libwtk-sdl2  0.0.1
Public Member Functions | Protected Attributes | List of all members
widget Struct Referenceabstract

#include <widget.hpp>

Inheritance diagram for widget:
Inheritance graph
[legend]
Collaboration diagram for widget:
Collaboration graph
[legend]

Public Member Functions

 widget (widget const &)=delete
 
widgetoperator= (widget const &)=delete
 
SDL_Rect const & get_box () const
 
context_info const & get_context_info () const
 
void set_context_info (context_info const &ci)
 
void set_parent (widget *parent)
 
virtual std::vector< widget * > get_children ()
 
virtual std::vector< widget const * > get_children () const
 
Drawing and Dirty-Checking
virtual void on_child_dirty (widget *child)
 
virtual std::vector< widget * > get_visible_children ()
 
virtual std::vector< widget const * > get_visible_children () const
 
void clear_dirty ()
 
void mark_dirty ()
 
void mark_child_dirty (widget *child)
 
void draw (draw_context &dc, selection_context const &sc) const
 
void draw_dirty (draw_context &dc, selection_context const &sc) const
 
virtual void on_draw (draw_context &dc, selection_context const &sc) const =0
 
Input Event Handlers
virtual void on_mouse_up_event (mouse_up_event const &e)
 
virtual void on_mouse_down_event (mouse_down_event const &e)
 
virtual void on_mouse_move_event (mouse_move_event const &e)
 
virtual void on_key_event (key_event const &e)
 
virtual void on_activate ()
 
Layout
void apply_layout (SDL_Rect box)
 
virtual void on_box_allocated ()
 
virtual size_hint get_size_hint (int width=-1, int height=-1) const =0
 
virtual bool can_use_intermediate_size () const
 
Selection Navigation
virtual widgetfind_selectable (navigation_type nt, point center)
 
virtual widgetnavigate_selectable (navigation_type nt, point center)
 
virtual widgetnavigate_selectable_from_children (navigation_type nt, widget *w, point center)
 
virtual void on_select ()
 
virtual void on_unselect ()
 

Protected Member Functions

Helpers for custom widget implementations
std::optional< swipe_infoget_swipe_info_with_context_info (mouse_up_event const &e)
 
widgetnavigate_selectable_parent (navigation_type nt, point center)
 

Protected Attributes

widget_parent
 

Detailed Description

Abstract base class for widgets. A derived class will have to implement at least on_draw() and min_size_hint(). There exist useful default implementation for all other methods. Note that there are also several other abstract classes that already implement certain features.

Widgets are usually created as widget_ptr to provide easy usage.

Member Function Documentation

◆ apply_layout()

void widget::apply_layout ( SDL_Rect  box)

In the simplest case this just sets the bounding box but may involve more complex calculations with containers.

◆ can_use_intermediate_size()

virtual bool widget::can_use_intermediate_size ( ) const
virtual

Whether a widget is able to use an intermediate value between minimal and natural size (e.g., assigning more width or height). This might change the aspect ratio of the widget.

Whenever a widget does not fit with natural but more than minimal, some widgets profit from using additional space. For example, an image in aspect ratio or a list view. A label in general can't profit from extra space and would only look awkward.

Reimplemented in embedded_widget< BaseWidget >.

◆ clear_dirty()

void widget::clear_dirty ( )

Sets all dirty flags to clean. Drawing in general will not reset the dirty state. This is because it won't have to when not using dirty-based drawing and most importantly if double buffering is used the widget has to be drawn two times.

◆ draw()

void widget::draw ( draw_context dc,
selection_context const &  sc 
) const

Recursively draws all widgets without dirty checking. There is also no need to call clear_dirty().

◆ draw_dirty()

void widget::draw_dirty ( draw_context dc,
selection_context const &  sc 
) const

Recursively draws all dirty widgets.

◆ find_selectable()

virtual widget* widget::find_selectable ( navigation_type  nt,
point  center 
)
virtual

Should return the first selectable widget according to the navigation type. If a widget is selectable it should return itself. Containers should return the first selectable child widget. Otherwise nullptr is returned.

The point may serve as a hint to provide a more accurate selection.

Reimplemented in box, embedded_widget< BaseWidget >, notebook, table, container, bin, and selectable.

◆ get_box()

SDL_Rect const& widget::get_box ( ) const

Get the widget's assigned bounding box.

◆ get_children()

virtual std::vector<widget *> widget::get_children ( )
virtual

Return child widgets in Z-order. Should be implemented by containers.

Reimplemented in box, embedded_widget< BaseWidget >, notebook, bin, table, and container.

◆ get_context_info()

context_info const& widget::get_context_info ( ) const

Get the context_info associated with the widgets context. This is meant for font settings or available area to help with widget layout and drawing.

◆ get_size_hint()

virtual size_hint widget::get_size_hint ( int  width = -1,
int  height = -1 
) const
pure virtual

Computes the widgets preferred minimal and natural size. When given a specific width or height the widget might use that to give a more accurate size.

Implemented in box, embedded_widget< BaseWidget >, label, slider, texture_view, notebook, table, bin, list_view, swipe_area, button, padding, color_widget, and empty.

◆ get_swipe_info_with_context_info()

std::optional<swipe_info> widget::get_swipe_info_with_context_info ( mouse_up_event const &  e)
protected

Helper to implement widgets that support swipes. Uses the default values of the context to generate a possible direction from a mouse up event.

◆ get_visible_children()

virtual std::vector<widget *> widget::get_visible_children ( )
virtual

Return the visible children in Z-order. The default implementation assumes that all children are visible. Once an invisible widget gets visible again the parent is responsible to mark itself at least as dirty_type::CHILD_DIRTY and to propagate the change with notify_parent_child_dirty().

Reimplemented in notebook.

◆ navigate_selectable()

virtual widget* widget::navigate_selectable ( navigation_type  nt,
point  center 
)
virtual

Perform a navigation request from this widget as source.

A widget that is not selectable doesn't have to implement this. Containers on the other hand should implement this to enable navigation of their children.

The point may serve as a hint to provide a more accurate selection.

Reimplemented in embedded_widget< BaseWidget >, notebook, and selectable.

◆ navigate_selectable_from_children()

virtual widget* widget::navigate_selectable_from_children ( navigation_type  nt,
widget w,
point  center 
)
virtual

When a child widget has exhausted its selectable widgets it may ask its parent for the next widget according to the navigation. The coordinates of the widget are provided to get a more accurate result for some navigation types (i.e. 2-dimensional). The widget passed has to be the direct child, otherwise the parent is not able to find it.

Only containers should implement this.

Reimplemented in box, embedded_widget< BaseWidget >, notebook, table, and bin.

◆ navigate_selectable_parent()

widget* widget::navigate_selectable_parent ( navigation_type  nt,
point  center 
)
protected

Helper to continue a navigation in a parent once the current widget is exhausted.

◆ on_activate()

virtual void widget::on_activate ( )
virtual

A widget may get activated by other means (e.g., infrared remote or return key).

Reimplemented in embedded_widget< BaseWidget >, list_view, button, and color_widget.

◆ on_box_allocated()

virtual void widget::on_box_allocated ( )
virtual

Refresh layout with existing box. This should not be called if the widget does not have a box already. Otherwise no space is allocated.

Reimplemented in embedded_widget< BaseWidget >, box, slider, texture_view, notebook, list_view, table, container, bin, and padding.

◆ on_child_dirty()

virtual void widget::on_child_dirty ( widget child)
virtual

This is called when a child is marked as dirty. The widget may then decide what to do.

You might use mark_dirty() to mark this widget dirty or mark_child_dirty(widget * child) to only propagate the change upwards (this is the default implementation).

Reimplemented in notebook.

◆ on_draw()

virtual void widget::on_draw ( draw_context dc,
selection_context const &  sc 
) const
pure virtual

Draw the widget. No children should be drawn here.

Implemented in label, texture_view, slider, embedded_widget< BaseWidget >, notebook, list_view, container, swipe_area, bin, button, empty, and color_widget.

◆ set_context_info()

void widget::set_context_info ( context_info const &  ci)

Should not be set manually if you do not know what you're doing.

◆ set_parent()

void widget::set_parent ( widget parent)

Should not be set manually. Containers are responsible for linking their children to them.


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