TermOx
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
ox::layout::Stack< Child_t > Class Template Reference

A Layout enabling only a single Widget at a time. More...

#include <stack.hpp>

Inheritance diagram for ox::layout::Stack< Child_t >:
ox::layout::Layout< Widget > ox::Widget

Public Member Functions

void set_active_page (std::size_t index)
 Set child Widget to be enabled/visible via its index into child vector. More...
 
void give_focus_on_change (bool sets_focus=true)
 Set whether Focus is given to a child Widget when it becomes active. More...
 
template<typename Widget_t = Child_t, typename... Args>
auto make_page (Args &&... args) -> Widget_t &
 Construct and append a page to the Stack. More...
 
template<typename Widget_t >
auto append_page (std::unique_ptr< Widget_t > w_ptr) -> Widget_t &
 Add an existing Widget as a page to the end of the Stack. More...
 
template<typename Widget_t >
auto append_page (Widget_t &&w) -> Child_t &
 Add an existing Widget as a page to the end of the Stack. More...
 
auto insert_page (std::unique_ptr< Child_t > child, std::size_t index) -> Child_t &
 Insert an existing Widget child at index. More...
 
void delete_page (std::size_t index)
 Remove a page from the list, by index value, and delete it. More...
 
auto remove_page (std::size_t index) -> std::unique_ptr< Widget >
 Remove page at index from the list and return it. More...
 
void clear ()
 Remove and delete all pages.
 
auto size () const -> std::size_t
 Return number of pages in this Stack.
 
auto get_active_page () const -> Child_t *
 Return a pointer to the current active page, or nullptr if none.
 
auto active_page_index () const -> std::size_t
 Return the index of the current active page. More...
 
- Public Member Functions inherited from ox::layout::Layout< Widget >
 Layout (std::unique_ptr< Widgets >... children)
 
 Layout (Parameters parameters)
 
auto get_children ()
 Return a View of all children.
 
auto get_children () const
 Return a const View of all children.
 
auto insert_child (std::unique_ptr< Widget_t > w, std::size_t index) -> Widget_t &
 Inserts w at index, sending child added event to *this. More...
 
auto append_child (std::unique_ptr< Widget_t > w) -> Widget_t &
 Move w to the end of the child container. Forwards to insert_child() More...
 
auto make_child (Args &&... args) -> Widget_t &
 Create a Widget and append it to the child container. More...
 
auto make_child (typename Widget_t::Parameters p) -> Widget_t &
 Helper so Parameters type does not have to be specified at call site.
 
auto remove_child (Child_t const *child) -> std::unique_ptr< Widget >
 Removes and returns the child pointed to by child. More...
 
auto remove_child_if (UnaryPredicate &&predicate) -> std::unique_ptr< Widget >
 Removes and returns the first child where predicate(child) returns true. More...
 
auto remove_child_at (std::size_t index) -> std::unique_ptr< Widget >
 Removes and returns the child at index in the child container. More...
 
auto remove_and_delete_child (Child_t const *child) -> bool
 Removes the child with given pointer and sends a Delete_event to it. More...
 
auto remove_and_delete_child_if (UnaryPredicate &&predicate) -> bool
 Erase first element that satisfies pred. More...
 
auto remove_and_delete_child_at (std::size_t index) -> bool
 Removes the child at index and sends a Delete_event to it. More...
 
void delete_all_children ()
 Removes all children and sends Delete_events to each.
 
void swap_children (std::size_t index_a, std::size_t index_b)
 Swap two child widgets, no index range check.
 
auto find_child_if (UnaryPredicate &&predicate) const -> Child_t const *
 Find first child satisfying predicate. More...
 
auto find_child_if (UnaryPredicate &&predicate) -> Child_t *
 Find first child satisfying predicate. More...
 
auto find_child_by_name (std::string const &name) -> Child_t *
 Find a child widget by name, returns nullptr if not found.
 
auto find_child_by_name (std::string const &name) const -> Child_t const *
 Find a child widget by name, returns nullptr if not found.
 
auto find_child_position (Widget const *w) const -> std::size_t
 Finds the index of the given child pointer in the child container. More...
 
auto contains_child (Widget const *w) const -> bool
 Returns true if w is a child of *this.
 
auto contains_descendant (Widget const *descendant) const -> bool
 Returns true if descendant is a child or some other child's child etc. More...
 
void update () final override
 Post a paint event to this Widget.
 
- Public Member Functions inherited from ox::Widget
 Widget (std::string name="", Focus_policy focus_policy_=Focus_policy::None, Size_policy width_policy_=Size_policy{}, Size_policy height_policy_=Size_policy{}, Brush brush_=Brush{}, Glyph wallpaper=U' ', bool brush_paints_wallpaper=true, Cursor cursor=Cursor{})
 Create an empty Widget.
 
 Widget (Parameters p)
 Create an empty Widget.
 
 Widget (Widget const &)=delete
 
 Widget (Widget &&)=delete
 
Widgetoperator= (Widget const &)=delete
 
Widgetoperator= (Widget &&)=delete
 
void set_name (std::string name)
 Set the identifying name of the Widget.
 
auto name () const -> std::string const &
 Return the name of the Widget.
 
auto unique_id () const -> std::uint16_t
 Return the ID number unique to this Widget.
 
void set_wallpaper (Glyph g)
 Used to fill in empty space that is not filled in by paint_event().
 
auto get_wallpaper () const -> Glyph
 Return the currently in use wallpaper or std::nullopt if none.
 
void enable (bool enable=true)
 Enable this Widget and send an Enable_event to itself. More...
 
void disable (bool disable=true)
 Disable this Widget and send a Disable_event to itself. More...
 
auto is_enabled () const -> bool
 Check whether the Widget is enabled.
 
auto parent () const -> Widget *
 Return the Widget's parent pointer. More...
 
auto top_left () const -> Point
 Return the global top left corner of this widget.
 
auto area () const -> Area
 Return the area the widget occupies.
 
void install_event_filter (Widget &filter)
 Install another Widget as an Event filter. More...
 
void remove_event_filter (Widget &filter)
 Remove a Widget from the Event filter list. More...
 
auto get_event_filters () const -> std::set< Widget * > const &
 Return the list of Event filter Widgets.
 
void enable_animation (std::chrono::milliseconds interval)
 Enable animation on this Widget. More...
 
void enable_animation (FPS fps)
 Enable animation with a frames-per-second value.
 
void disable_animation ()
 Turn off animation, no more Timer_events will be sent to this Widget. More...
 
auto is_animated () const -> bool
 Return true if this Widget has animation enabled.
 
auto get_children ()
 Get a range containing Widget& to each child.
 
auto get_children () const
 Get a const range containing Widget& to each child.
 
auto get_descendants () const -> std::vector< Widget * >
 Return container of all descendants of self_.
 
void paint_wallpaper_with_brush (bool paints=true)
 Set if the brush is applied to the wallpaper Glyph.
 
auto paints_wallpaper_with_brush () const -> bool
 If true, the brush will apply to the wallpaper Glyph.
 
auto generate_wallpaper () const -> Glyph
 Return the wallpaper Glyph. More...
 
auto get_child_offset () const -> std::size_t
 Return the index of the first child displayed by this Widget.
 
auto child_count () const -> std::size_t
 Return the number of children held by this Widget.
 
virtual auto child_added_event (Widget &child) -> bool
 Handles Child_added_event objects.
 
virtual auto child_removed_event (Widget &child) -> bool
 Handles Child_removed_event objects.
 
virtual auto child_polished_event (Widget &child) -> bool
 Handles Child_polished_event objects.
 
virtual auto mouse_press_event (Mouse const &m) -> bool
 Handles Mouse_press_event objects.
 
virtual auto mouse_release_event (Mouse const &m) -> bool
 Handles Mouse_release_event objects.
 
virtual auto mouse_wheel_event (Mouse const &m) -> bool
 Handles Mouse_wheel_event objects.
 
virtual auto mouse_move_event (Mouse const &m) -> bool
 Handles Mouse_move_event objects.
 
virtual auto key_press_event (Key k) -> bool
 Handles Key_press_event objects.
 
virtual auto key_release_event (Key k) -> bool
 Handles Key_release_event objects. More...
 
virtual auto focus_out_event () -> bool
 Handles Focus_out_event objects.
 
virtual auto delete_event () -> bool
 Handles Delete_event objects.
 
virtual auto paint_event (Painter &p) -> bool
 Handles Paint_event objects.
 
virtual auto timer_event () -> bool
 Handles Timer_event objects.
 
virtual auto enable_event_filter (Widget &receiver) -> bool
 Handles Enable_event objects filtered from other Widgets.
 
virtual auto disable_event_filter (Widget &receiver) -> bool
 Handles Disable_event objects filtered from other Widgets.
 
virtual auto child_added_event_filter (Widget &receiver, Widget &child) -> bool
 Handles Child_added_event objects filtered from other Widgets.
 
virtual auto child_removed_event_filter (Widget &receiver, Widget &child) -> bool
 Handles Child_removed_event objects filtered from other Widgets.
 
virtual auto child_polished_event_filter (Widget &receiver, Widget &child) -> bool
 Handles Child_polished_event objects filtered from other Widgets.
 
virtual auto move_event_filter (Widget &receiver, Point new_position, Point old_position) -> bool
 Handles Move_event objects filtered from other Widgets.
 
virtual auto resize_event_filter (Widget &receiver, Area new_size, Area old_size) -> bool
 Handles Resize_event objects filtered from other Widgets.
 
virtual auto mouse_press_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_press_event objects filtered from other Widgets.
 
virtual auto mouse_release_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_release_event objects filtered from other Widgets.
 
virtual auto mouse_wheel_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_wheel_event objects filtered from other Widgets.
 
virtual auto mouse_move_event_filter (Widget &receiver, Mouse const &m) -> bool
 Handles Mouse_move_event objects filtered from other Widgets.
 
virtual auto key_press_event_filter (Widget &receiver, Key k) -> bool
 Handles Key_press_event objects filtered from other Widgets.
 
virtual auto key_release_event_filter (Widget &receiver, Key k) -> bool
 Handles Key_release_event objects filtered from other Widgets.
 
virtual auto focus_in_event_filter (Widget &receiver) -> bool
 Handles Focus_in_event objects filtered from other Widgets.
 
virtual auto focus_out_event_filter (Widget &receiver) -> bool
 Handles Focus_out_event objects filtered from other Widgets.
 
virtual auto delete_event_filter (Widget &receiver) -> bool
 Handles Delete_event objects filtered from other Widgets.
 
virtual auto paint_event_filter (Widget &receiver, Painter &p) -> bool
 Handles Paint_event objects filtered from other Widgets.
 
virtual auto timer_event_filter (Widget &receiver) -> bool
 Handles Timer_event objects filtered from other Widgets.
 
void set_top_left (Point p)
 Should only be used by Move_event send() function.
 
void set_area (Area a)
 Should only be used by Resize_event send() function.
 
void set_parent (Widget *parent)
 Should only be used by Layout.
 

Public Attributes

sl::Signal< void(std::size_t)> page_changed
 Emitted when the active page is changed, sends the new index along.
 
- Public Attributes inherited from ox::Widget
Signal< void()> enabled
 
Signal< void()> disabled
 
Signal< void(Widget &)> child_added
 
Signal< void(Widget &)> child_removed
 
Signal< void(Widget &)> child_polished
 
Signal< void(Point, Point)> moved
 
Signal< void(Area, Area)> resized
 
Signal< void(Mouse const &)> mouse_pressed
 
Signal< void(Mouse const &)> mouse_released
 
Signal< void(Mouse const &)> mouse_wheel_scrolled
 
Signal< void(Mouse const &)> mouse_moved
 
Signal< void(Key)> key_pressed
 
Signal< void(Key)> key_released
 
Signal< void()> focused_in
 
Signal< void()> focused_out
 
Signal< void()> deleted
 
Signal< void(Painter &)> painted
 
Signal< void()> timer
 
Signal< bool(Widget &)> enabled_filter
 
Signal< bool(Widget &)> disabled_filter
 
Signal< bool(Widget &, Widget &)> child_added_filter
 
Signal< bool(Widget &, Widget &)> child_removed_filter
 
Signal< bool(Widget &, Widget &)> child_polished_filter
 
Signal< bool(Widget &, Point, Point)> moved_filter
 
Signal< bool(Widget &, Area, Area)> resized_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_pressed_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_released_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_wheel_scrolled_filter
 
Signal< bool(Widget &, Mouse const &)> mouse_moved_filter
 
Signal< bool(Widget &, Key)> key_pressed_filter
 
Signal< bool(Widget &, Key)> key_released_filter
 
Signal< bool(Widget &)> focused_in_filter
 
Signal< bool(Widget &)> focused_out_filter
 
Signal< bool(Widget &)> deleted_filter
 
Signal< bool(Widget &, Painter &)> painted_filter
 
Signal< bool(Widget &)> timer_filter
 
Focus_policy focus_policy
 Describes how focus is given to this Widget.
 
Cursor cursor
 Provides information on where the cursor is and if it is enabled.
 
Size_policy width_policy
 Describes how the width of this Widget should be modified by a Layout.
 
Size_policy height_policy
 Describes how the height of this Widget should be modified by a Layout.
 
Brush brush
 A Brush that is applied to every Glyph painted by this Widget.
 
sl::Lifetime lifetime
 Slots can track this object's lifetime to disable Slot invocations.
 

Static Public Attributes

static constexpr auto invalid_index = static_cast<std::size_t>(-1)
 Used to indicate an error on return values of index type.
 

Protected Member Functions

auto enable_event () -> bool override
 Handles Enable_event objects.
 
auto disable_event () -> bool override
 Handles Disable_event objects.
 
auto move_event (Point new_position, Point old_position) -> bool override
 Handles Move_event objects.
 
auto resize_event (Area new_size, Area old_size) -> bool override
 Handles Resize_event objects.
 
auto focus_in_event () -> bool override
 Handles Focus_in_event objects.
 

Additional Inherited Members

- Public Types inherited from ox::layout::Layout< Widget >
using Child_t = Widget
 
- Protected Types inherited from ox::Widget
using Children_t = std::vector< std::unique_ptr< Widget > >
 
- Protected Attributes inherited from ox::Widget
Children_t children_
 
std::size_t child_offset_ = 0
 

Detailed Description

template<typename Child_t = Widget>
class ox::layout::Stack< Child_t >

A Layout enabling only a single Widget at a time.

A Stack is made up of pages, which are child Widgets that can be displayed one at a time within the Stack. The active page determines which child Widget is currently displayed.

Member Function Documentation

◆ active_page_index()

template<typename Child_t = Widget>
auto ox::layout::Stack< Child_t >::active_page_index ( ) const -> std::size_t
inline

Return the index of the current active page.

Returns Stack::invalid_index if active_page_ is nullptr.

◆ append_page() [1/2]

template<typename Child_t = Widget>
template<typename Widget_t >
auto ox::layout::Stack< Child_t >::append_page ( std::unique_ptr< Widget_t >  w_ptr) -> Widget_t&
inline

Add an existing Widget as a page to the end of the Stack.

Returns a reference to the appended Widget as Child_t&.

◆ append_page() [2/2]

template<typename Child_t = Widget>
template<typename Widget_t >
auto ox::layout::Stack< Child_t >::append_page ( Widget_t &&  w) -> Child_t&
inline

Add an existing Widget as a page to the end of the Stack.

Returns a reference to the appended Widget as Child_t&.

◆ delete_page()

template<typename Child_t = Widget>
void ox::layout::Stack< Child_t >::delete_page ( std::size_t  index)
inline

Remove a page from the list, by index value, and delete it.

Throws std::out_of_range if index is invalid. Sets active page to nullptr if the active page is being deleted.

◆ give_focus_on_change()

template<typename Child_t = Widget>
void ox::layout::Stack< Child_t >::give_focus_on_change ( bool  sets_focus = true)
inline

Set whether Focus is given to a child Widget when it becomes active.

Enabled by default.

◆ insert_page()

template<typename Child_t = Widget>
auto ox::layout::Stack< Child_t >::insert_page ( std::unique_ptr< Child_t child,
std::size_t  index 
) -> Child_t&
inline

Insert an existing Widget child at index.

Throws std::invalid_argument if child is nullptr. Throws std::out_of_range if index > number of children. Returns a reference to the inserted Child_t object.

◆ make_page()

template<typename Child_t = Widget>
template<typename Widget_t = Child_t, typename... Args>
auto ox::layout::Stack< Child_t >::make_page ( Args &&...  args) -> Widget_t&
inline

Construct and append a page to the Stack.

This will construct a child Widget of type T, using args passed to T's constructor, and then automatically disable it. Returns a reference to the created child Widget.

◆ remove_page()

template<typename Child_t = Widget>
auto ox::layout::Stack< Child_t >::remove_page ( std::size_t  index) -> std::unique_ptr<Widget>
inline

Remove page at index from the list and return it.

Useful if you need to move a page into another Widget. Use Stack::delete_page() if you want to remove a page and destroy it. Letting the returned Widget destroy itself will potentially leave dangling pointers in the event system. Throws std::out_of_range if index is invalid. Sets active page to nullptr if active page removed.

◆ set_active_page()

template<typename Child_t = Widget>
void ox::layout::Stack< Child_t >::set_active_page ( std::size_t  index)
inline

Set child Widget to be enabled/visible via its index into child vector.

The index is typically the same order as child Widgets were added. Throws std::out_of_range if index is invalid.


The documentation for this class was generated from the following file: