|
libwtk-sdl2
0.0.1
|
#include <widget.hpp>


Public Member Functions | |
| widget (widget const &)=delete | |
| widget & | operator= (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 widget * | find_selectable (navigation_type nt, point center) |
| virtual widget * | navigate_selectable (navigation_type nt, point center) |
| virtual widget * | navigate_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_info > | get_swipe_info_with_context_info (mouse_up_event const &e) |
| widget * | navigate_selectable_parent (navigation_type nt, point center) |
Protected Attributes | |
| widget * | _parent |
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.
| 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.
|
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 >.
| 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.
| 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().
| void widget::draw_dirty | ( | draw_context & | dc, |
| selection_context const & | sc | ||
| ) | const |
Recursively draws all dirty widgets.
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.
| SDL_Rect const& widget::get_box | ( | ) | const |
Get the widget's assigned bounding box.
|
virtual |
| 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.
|
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.
|
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.
|
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.
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.
|
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.
Helper to continue a navigation in a parent once the current widget is exhausted.
|
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.
|
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.
|
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.
|
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.
| void widget::set_context_info | ( | context_info const & | ci | ) |
Should not be set manually if you do not know what you're doing.
| void widget::set_parent | ( | widget * | parent | ) |
Should not be set manually. Containers are responsible for linking their children to them.
1.8.14