1.10 |
#include <widget.h>
Public Types | |
enum class | Flag : uint32_t { plane_window = detail::bit(0) , window = detail::bit(1) , frame = detail::bit(2) , disabled = detail::bit(3) , readonly = detail::bit(4) , active = detail::bit(5) , invisible = detail::bit(6) , grab_mouse = detail::bit(7) , no_clip = detail::bit(8) , no_layout = detail::bit(9) , no_autoresize = detail::bit(10) , checked = detail::bit(11) , component = detail::bit(12) , user_drag = detail::bit(13) , user_track_drag = detail::bit(14) } |
Common flags used for various widget properties. More... | |
using | Flags = egt::Flags< Widget::Flag > |
Widget flags. | |
using | WalkCallback = std::function< bool(Widget *widget, int level)> |
Callback definition used by walk(). | |
using | WidgetId = uint64_t |
Type used to identify a unique Widget ID. | |
Public Types inherited from Object | |
using | EventCallback = std::function< void(Event &event)> |
Event handler callback function. | |
using | FilterFlags = FlagsBase< EventId > |
Event handler EventId filter. | |
using | RegisterHandle = uint64_t |
Handle type. | |
Public Member Functions | |
Widget (const Rect &rect={}, const Widget::Flags &flags={}) noexcept | |
Widget (const Widget &)=delete | |
Widget (Frame &parent, const Rect &rect={}, const Widget::Flags &flags={}) noexcept | |
Widget (Serializer::Properties &props) noexcept | |
Widget (Widget &&) noexcept=default | |
~Widget () noexcept override | |
EGT_NODISCARD bool | active () const |
Get the active state. | |
void | active (bool value) |
Set the active state. | |
AlignFlags & | align () |
Get the alignment. | |
EGT_NODISCARD const AlignFlags & | align () const |
Get the alignment. | |
void | align (const AlignFlags &a) |
Align the widget. | |
EGT_NODISCARD float | alpha () const |
Get the alpha property. | |
void | alpha (float alpha) |
Set the alpha property. | |
EGT_NODISCARD bool | autoresize () const |
Return the autoresize state of the widget. | |
void | autoresize (bool value) |
Set the autoresize state. | |
EGT_NODISCARD Image * | background (bool allow_fallback=false) const |
Get the background image, if any, for the current group. | |
void | background (const Image &image, Palette::GroupId group=Palette::GroupId::normal) |
Add an image background to the widget's box. | |
EGT_NODISCARD Image * | background (Palette::GroupId group, bool allow_fallback=false) const |
Get the background image, if any, for the given group. | |
EGT_NODISCARD DefaultDim | border () const |
Get the border width. | |
void | border (DefaultDim border) |
Set the border width. | |
EGT_NODISCARD Theme::BorderFlags | border_flags () const |
Get the border flags. | |
void | border_flags (const Theme::BorderFlags &flags) |
Set the border flags. | |
EGT_NODISCARD float | border_radius () const |
Get the border radius. | |
void | border_radius (float radius) |
Set the border radius. | |
EGT_NODISCARD const Rect & | box () const |
Bounding box for the Widget. | |
void | box (const Rect &rect) |
Change the bounding box of the widget. | |
bool | can_handle_event () const |
Returns true if the widget is capable of handling an event. | |
EGT_NODISCARD Point | center () const |
Get the center point of the widget's box(). | |
EGT_NODISCARD bool | checked () const |
Get the boolean checked state of the a widget. | |
virtual void | checked (bool value) |
Set the checked state of the widget. | |
EGT_NODISCARD bool | clip () const |
Return the clip state of the widget. | |
EGT_NODISCARD const Pattern & | color (Palette::ColorId id) const |
Get a Widget color. | |
void | color (Palette::ColorId id, const Pattern &color, Palette::GroupId group=Palette::GroupId::normal) |
Add a color to the widget's instance palette. | |
EGT_NODISCARD const Pattern & | color (Palette::ColorId id, Palette::GroupId group) const |
Get a Widget color. | |
virtual EGT_NODISCARD Rect | content_area () const |
Return the area that content is allowed to be positioned into. | |
void | continue_drag (Event &event) |
Handle 'pointer_drag' and 'pointer_drag_stop' events. | |
virtual void | damage () |
Damage the box() of the widget and cause a redraw. | |
virtual void | damage (const Rect &rect) |
Mark the specified rect as a damaged area of the widget. | |
virtual void | deserialize_children (const Deserializer &deserializer) |
Deserialize the children of this widget. | |
void | detach () |
Detach this widget from its parent. | |
void | disable () |
Set the disabled state to true. | |
void | disable_toggle () |
Toggle the disabled state. | |
EGT_NODISCARD bool | disabled () const |
Return the disabled state of the widget. | |
void | disabled (bool value) |
Set the disabled state. | |
DisplayPoint | display_origin () |
Get the display origin of the Widget. | |
virtual Point | display_to_local (const DisplayPoint &p) const |
Convert a display point to a local point. | |
virtual void | draw (Painter &painter, const Rect &rect) |
Draw the widget. | |
void | draw_box (Painter &painter, Palette::ColorId bg, Palette::ColorId border) const |
Helper function to draw this widget's box using the appropriate theme. | |
void | draw_circle (Painter &painter, Palette::ColorId bg, Palette::ColorId border) const |
Helper function to draw this widget's circle using the appropriate theme. | |
void | enable () |
Set the disabled state to false. | |
Theme::FillFlags & | fill_flags () |
Get a modifiable fill flags reference. | |
EGT_NODISCARD const Theme::FillFlags & | fill_flags () const |
Get the fill flags. | |
void | fill_flags (const Theme::FillFlags &flags) |
Set the fill flags. | |
EGT_NODISCARD bool | focus () const |
Get the current focus state. | |
void | focus (bool value) |
Set the focus state. | |
EGT_NODISCARD const Font & | font () const |
Get the widget Font. | |
void | font (const Font &font) |
Set the widget Font. | |
EGT_NODISCARD bool | frame () const |
Return the frame state of the widget. | |
EGT_NODISCARD bool | grab_mouse () const |
Return the grab_mouse state of the widget. | |
void | grab_mouse (bool value) |
Set the grab_mouse state. | |
EGT_NODISCARD Palette::GroupId | group () const |
Get the current Palette::GroupId depending on the widget's state. | |
virtual void | handle (Event &event) |
Handle an event. | |
bool | has_font () const |
Check whether the widget has a custom Font. | |
EGT_NODISCARD bool | has_palette () const |
Check whether the widget has a custom palette. | |
virtual EGT_NODISCARD bool | has_screen () const |
Does this Widget have a screen? | |
EGT_NODISCARD DefaultDim | height () const |
Height of the widget's box(). | |
void | height (DefaultDim h) |
Change the height. | |
virtual void | hide () |
Hide the Widget. | |
EGT_NODISCARD bool | hit (const DisplayPoint &point) const |
Returns true if the DisplayPoint is within the widget box. | |
EGT_NODISCARD DefaultDim | horizontal_ratio () const |
Get the horizontal ratio relative to parent. | |
void | horizontal_ratio (DefaultDim horizontal) |
Set the horizontal ratio relative to parent. | |
EGT_NODISCARD bool | in_layout () const |
Indicate if the Widget is computing the layout or not. | |
virtual void | layout () |
Perform layout of the Widget. | |
DisplayPoint | local_to_display (const Point &p) const |
Convert a local point to a display point. | |
EGT_NODISCARD DefaultDim | margin () const |
Get the margin width. | |
void | margin (DefaultDim margin) |
Set the margin width. | |
virtual EGT_NODISCARD Size | min_size_hint () const |
Get a minimum size hint for the Widget. | |
void | min_size_hint (const Size &size) |
Set the minimum size hint for the Widget. | |
EGT_NODISCARD size_t | moat () const |
Get the sum of the margin(), padding(), and border() around the content of the widget. | |
virtual void | move (const Point &point) |
Move the Widget to a new position. | |
void | move_to_center () |
Move the widget to the center of its parent. | |
void | move_to_center (const Point &point) |
Move the widget to the specified center point. | |
EGT_NODISCARD bool | no_layout () const |
Return the no_layout state of the widget. | |
void | no_layout (bool value) |
Set the no_layout state. | |
virtual void | on_screen_resized () |
Called from ComposerScreen::resize(). | |
Widget & | operator= (const Widget &)=delete |
Widget & | operator= (Widget &&) noexcept=default |
EGT_NODISCARD DefaultDim | padding () const |
Return the padding width. | |
void | padding (DefaultDim padding) |
Set the padding width. | |
virtual void | paint (Painter &painter) |
Paint the Widget using a Painter. | |
virtual void | paint_to_file (const std::string &filename={}) |
Draw the widget to a file. | |
EGT_NODISCARD const Palette & | palette () const |
Get the widget palette. | |
void | palette (const Palette &palette) |
Set the widget instance Palette. | |
Widget * | parent () |
Get a pointer to the parent Widget, or nullptr if none exists. | |
EGT_NODISCARD const Widget * | parent () const |
Get a pointer to the parent Widget, or nullptr if none exists. | |
EGT_NODISCARD bool | plane_window () const |
Return the plane_window state of the widget. | |
EGT_NODISCARD const Point & | point () const |
Get the origin of the widget's box(). | |
virtual void | post_deserialize (Serializer::Properties &props) |
Resume deserializing of the widget after its children have been deserialized. | |
void | ratio (DefaultDim horizontal, DefaultDim vertical) |
Set the size ratio relative to parent. | |
void | ratio (DefaultDim ratio) |
Set the size ratio relative to parent. | |
EGT_NODISCARD bool | readonly () const |
Get the readonly state of the widget. | |
void | readonly (bool value) |
Set the readonly state of the widget. | |
void | readonly_toggle () |
Toggle the readonly state. | |
void | reset_background (Palette::GroupId group=Palette::GroupId::normal) |
Remove an image background from the widget's box. | |
void | reset_font () |
Reset the widget's Font. | |
void | reset_palette () |
Clear the widget instance palette. | |
virtual void | resize (const Size &size) |
Resize the widget. | |
void | resize_by_ratio (DefaultDim hratio, DefaultDim vratio) |
Scale the current size of the Widget given the ratio. | |
void | resize_by_ratio (DefaultDim ratio) |
Scale the current size of the Widget given the ratio. | |
virtual void | scale (float hscale, float vscale) |
Set the scale of the widget. | |
void | scale (float scale) |
Set the scale of the widget. | |
virtual EGT_NODISCARD Screen * | screen () const |
Get a pointer to the Screen instance, using using a parent as necessary. | |
virtual void | serialize (Serializer &serializer) const |
Serialize the widget to the specified serializer. | |
virtual void | serialize_children (Serializer &serializer) const |
Serialize the widget's children to the specified serializer. | |
virtual void | show () |
Show the Widget. | |
EGT_NODISCARD const Size & | size () const |
Get the size of the widget's box(). | |
EGT_NODISCARD const Theme & | theme () const |
Get the Widget Theme. | |
EGT_NODISCARD Point | to_parent (const Point &r) const |
Convert a point with a local origin to a parent origin. | |
EGT_NODISCARD Rect | to_parent (const Rect &r) const |
Convert a point in a rect a local origin to a parent origin. | |
virtual EGT_NODISCARD std::string | type () const |
Returns a string representation of the type of this widget. | |
EGT_NODISCARD bool | user_drag () const |
void | user_drag (bool value) |
EGT_NODISCARD const Rect & | user_requested_box () const |
Get the box corresponding to the user requested one, not the actual one. | |
EGT_NODISCARD bool | user_track_drag () const |
void | user_track_drag (bool value) |
EGT_NODISCARD DefaultDim | vertical_ratio () const |
Get the vertical ratio relative to parent. | |
void | vertical_ratio (DefaultDim vertical) |
Set the vertical ratio relative to parent. | |
EGT_NODISCARD bool | visible () const |
Get the visible state of the widget. | |
void | visible (bool value) |
Set the visible state. | |
void | visible_toggle () |
Toggle the visibility state. | |
virtual void | walk (const WalkCallback &callback, int level=0) |
Walk the Widget tree and call callback with each Widget. | |
EGT_NODISCARD WidgetId | widgetid () const |
Get the unique id of the widget. | |
EGT_NODISCARD DefaultDim | width () const |
Width of the widget's box(). | |
void | width (DefaultDim w) |
Change the width. | |
EGT_NODISCARD DefaultDim | x () const |
X coordinate of the widget's box(). | |
void | x (DefaultDim x) |
Set the X coordinate of the box. | |
EGT_NODISCARD DefaultDim | xratio () const |
Get the X position ratio relative to parent. | |
void | xratio (DefaultDim xratio) |
Set the X position ratio relative to parent. | |
EGT_NODISCARD DefaultDim | y () const |
Y coordinate of the widget's box(). | |
void | y (DefaultDim y) |
Set the Y coordinate of the box. | |
EGT_NODISCARD DefaultDim | yratio () const |
Get the Y position ratio relative to parent. | |
void | yratio (DefaultDim yratio) |
Set the Y position ratio relative to parent. | |
virtual EGT_NODISCARD size_t | zorder () const |
Get the zorder of the widget. | |
virtual void | zorder (size_t rank) |
Set the zorder of the widget. | |
virtual void | zorder_bottom () |
Move the widget to the bottom. | |
virtual void | zorder_down () |
Move this widgets zorder down relative to other widgets with the same parent. | |
virtual void | zorder_top () |
Move the widget to the top. | |
virtual void | zorder_up () |
Move this widgets zorder up relative to other widgets with the same parent. | |
Public Member Functions inherited from Object | |
Object () noexcept=default | |
Object (const Object &)=delete | |
Object (Object &&)=default | |
virtual | ~Object () noexcept=default |
void | clear_handlers () |
Clear all registered event handlers. | |
void | invoke_handlers (Event &event) |
Invoke all handlers with the specified event. | |
void | invoke_handlers (EventId event) |
Invoke all handlers with the specified EventId. | |
EGT_NODISCARD const std::string & | name () const |
Get the name of the Object. | |
void | name (const std::string &name) |
Set the name of the Object. | |
RegisterHandle | on_event (const EventCallback &handler, const FilterFlags &mask={}) |
Add an event handler to be called when the widget generates an event. | |
Object & | operator= (const Object &)=delete |
Object & | operator= (Object &&)=default |
void | remove_handler (RegisterHandle handle) |
Remove an event handler. | |
Public Attributes | |
Signal | on_checked_changed |
Event signal. | |
Signal | on_gain_focus |
Invoked when the widget gains focus. | |
Signal | on_lost_focus |
Invoked when the widget loses focus. | |
Signal | on_show |
Invoked when a widget is shown. | |
Signal | on_hide |
Invoked when a widget is hidden. | |
Protected Types | |
using | ChildDrawCallback = std::function< void(Painter &painter, Widget *widget)> |
Helper type that defines the special draw child callback. | |
using | SubordinatesArray = std::list< std::shared_ptr< Widget > > |
Helper type for an array of subordinate widgets. | |
Protected Types inherited from Object | |
using | CallbackArray = std::vector< CallbackMeta > |
Helper type for an array of callbacks. | |
Protected Member Functions | |
Widget (Serializer::Properties &props, bool is_derived) noexcept | |
bool | accept_drag () const |
Tell the start_drag() method whether the widget accepts 'pointer_drag*' events. | |
void | add_component (Widget &widget) |
Add a component. | |
void | add_damage (const Rect &rect) |
Add damage to the damage array. | |
virtual void | begin_draw () |
Cause the widget to draw itself and all of its children. | |
void | begin_draw (Widget *parent) |
Call the begin_draw() method of the parent. | |
EGT_NODISCARD detail::Range< SubordinatesArray > & | children () |
Return the array of child widgets. | |
EGT_NODISCARD const detail::Range< SubordinatesArray > & | children () const |
Return the array of child widgets. | |
EGT_NODISCARD bool | component () const |
Get the component status. | |
void | component (bool value) |
Set the component flag. | |
EGT_NODISCARD detail::Range< SubordinatesArray > & | components () |
Return the array of components widgets. | |
EGT_NODISCARD const detail::Range< SubordinatesArray > & | components () const |
Return the array of components widgets. | |
virtual void | damage_from_subordinate (const Rect &rect) |
Special variation of damage() that is to be called explicitly by subordinate widgets. | |
void | deserialize_leaf (Serializer::Properties &props) |
Deserialize widget properties that require to call overridden methods. | |
Widget * | find_screen () |
Starting from this Widget, find the Widget that has a Screen. | |
EGT_NODISCARD const Widget * | find_screen () const |
Starting from this Widget, find the Widget that has a Screen. | |
Widget::Flags & | flags () |
Get a modifiable ref of the flags. | |
EGT_NODISCARD const Widget::Flags & | flags () const |
Get a const ref of the flags. | |
virtual bool | internal_drag () const |
virtual bool | internal_track_drag () const |
EGT_NODISCARD Rect | local_box () const |
Get the local box which is the same size as box(), but with the origin zeroed. | |
EGT_NODISCARD bool | parent_in_layout () |
Indicate if our parent is computing the layout. | |
void | parent_layout () |
Call our parent to do a layout. | |
virtual Point | point_from_subordinate (const Widget &subordinate) const |
EGT_NODISCARD detail::Range< SubordinatesArray > & | range_from_widget (const Widget &widget) |
Return either components() or children() depending on widget.component() | |
EGT_NODISCARD const detail::Range< SubordinatesArray > & | range_from_widget (const Widget &widget) const |
Return either components() or children() depending on widget.component() | |
void | remove_component (Widget *widget) |
Remove a component. | |
virtual void | set_parent (Widget *parent) |
Set this widget's parent. | |
void | special_child_draw (Painter &painter, Widget *widget) |
Special draw function that can be invoked when drawing each child. | |
EGT_NODISCARD ChildDrawCallback | special_child_draw_callback () const |
Get the special child draw callback. | |
void | special_child_draw_callback (ChildDrawCallback func) |
Set the special child draw callback. | |
EGT_NODISCARD ChildDrawCallback | special_child_draw_callback (Widget *parent) const |
Get the child draw callback of the parent. | |
void | start_drag (Event &event) |
Handle 'pointer_drag_start' events and decide whether they are caught by this widget. | |
virtual Point | to_panel (const Point &p) |
Convert a local point to the coordinate system of the current panel. | |
virtual EGT_NODISCARD Point | to_subordinate (const Point &p) const |
Convert a point with an origin of the current widget to subordinate origin. | |
EGT_NODISCARD Rect | to_subordinate (Rect rect) const |
virtual EGT_NODISCARD bool | top_level () const |
Is this widget a top level widget? | |
bool | track_drag () const |
Tell the continue_drag() method whether the widget tracks 'pointer_drag*' events once they have crossed out the widget boundaries. | |
void | update_subordinates_ranges () |
Update the 'm_children' and 'm_components' members. | |
size_t | zorder (const Widget *widget) const |
Get the zorder of the widget. | |
void | zorder (const Widget *widget, size_t rank) |
Set the zorder of the widget. | |
void | zorder_bottom (const Widget *widget) |
Move the specified widget zorder to the bottom of the current list of widgets with the same parent. | |
void | zorder_down (const Widget *widget) |
Move the specified widget zorder down relative to other widgets with the same parent. | |
void | zorder_top (const Widget *widget) |
Move the specified widget zorder to the top of the current list of widgets with the same parent. | |
void | zorder_up (const Widget *widget) |
Move the specified widget zorder up relative to other widgets with the same parent. | |
Protected Attributes | |
Rect | m_box |
Bounding box. | |
detail::Range< SubordinatesArray > | m_children |
Array of child widgets in the order they were added. | |
detail::Range< SubordinatesArray > | m_components |
Array of component widgets in the order they were added. | |
SubordinatesArray::iterator | m_components_begin |
Iterator for the beginning of components which are positionned after children in the subordinates array. | |
Screen::DamageArray | m_damage |
The damage array for this widget. | |
bool | m_in_draw {false} |
Status for whether this widget is currently drawing. | |
bool | m_in_layout {false} |
Status for whether this widget is currently performing layout. | |
Size | m_min_size |
Minimum size of the widget when not an empty value. | |
Widget * | m_parent {nullptr} |
Pointer to this widget's parent. | |
ChildDrawCallback | m_special_child_draw_callback |
Used internally for calling the special child draw function. | |
SubordinatesArray | m_subordinates |
Array of subordinates widgets split in child widgets and component widgets. | |
Rect | m_user_requested_box |
Keep track of the box requested by the user. | |
WidgetId | m_widgetid {0} |
Unique ID of this widget. | |
Protected Attributes inherited from Object | |
detail::CopyOnWriteAllocate< CallbackArray > | m_callbacks |
Array of callbacks. | |
RegisterHandle | m_handle_counter {0} |
Counter used to generate unique handles for each callback registration. | |
std::string | m_name |
A user defined name for the Object. | |
Friends | |
class | Frame |
Base Widget class.
This is the base class for all widgets. A Widget is a thing, a UI component, with a basic set of properties. In this case, it has a bounding rectangle, some flags, and some states - and these properties can be manipulated. A Widget can handle events, draw itself, and more. However, the specifics of what it means to handle an event or draw the Widget is implemented in classes that are derived from this one, like a Button or a Label.
|
protected |
Helper type that defines the special draw child callback.
using Flags = egt::Flags<Widget::Flag> |
Widget flags.
|
protected |
Helper type for an array of subordinate widgets.
using WalkCallback = std::function<bool(Widget* widget, int level)> |
Callback definition used by walk().
In the callback, return true to continue or false to stop.
|
strong |
Common flags used for various widget properties.
Enumerator | |
---|---|
plane_window | This is an overlay plane window. |
window | This is a window widget. |
frame | This is a frame. |
disabled | When set, the widget is disabled. Typically, when a widget is disabled it will not accept input. This may change how the widget behaves or is drawn. |
readonly | When set, the widget will not receive input events. |
active | When true, the widget is active. The active state of a widget is usually a momentary state, unlike focus, which exists until focus is changed. For example, when a button is currently being held down, it its implementation may consider this the active state and choose to draw the button differently. This may change how the widget behaves or is draw. |
invisible | When set, the widget is not visible. |
grab_mouse | Grab related mouse events. For example, if a button receives the EventId::raw_pointer_down event, make sure the button also gets subsequent mouse events, including the EventId::raw_pointer_up event. |
no_clip | Don't clip the child to drawing only in its box. Use this with caution, it's probably not what you want. |
no_layout | Tell any parent not to perform layout on this widget. |
no_autoresize | Do not automatically resize a widget to meet the minimal size hint. |
checked | Is the widget in a checked state. |
component | Is the widget a component. |
user_drag | Has the user enabled 'pointer_drag*' events (if not internally enabled by the widget itself). |
user_track_drag | has the user enabled 'pointer_drag*' events to be tracked when they cross the widget boundaries. |
|
explicitnoexcept |
|
explicitnoexcept |
|
inlineexplicitnoexcept |
[in] | props | list of widget argument and its properties. |
|
explicitprotectednoexcept |
|
overridenoexcept |
|
inlineprotected |
Tell the start_drag() method whether the widget accepts 'pointer_drag*' events.
EGT_NODISCARD bool active | ( | ) | const |
Get the active state.
The meaning of active is largely up to the derived implementation.
void active | ( | bool | value | ) |
Set the active state.
The meaning of active is largely up to the derived implementation.
|
protected |
Add a component.
|
protected |
Add damage to the damage array.
Damage rects added here must have origin at point() of this widget. This is done for several reasons, including if this widget is moved, all of the damage rects are still valid.
|
inline |
Get the alignment.
|
inline |
Get the alignment.
void align | ( | const AlignFlags & | a | ) |
Align the widget.
This will align the widget relative to the box of its parent widget.
[in] | a | The AlignFlags. |
|
inline |
Get the alpha property.
void alpha | ( | float | alpha | ) |
Set the alpha property.
This controls the alpha property of the entire widget and all of its children.
[in] | alpha | Widget alpha component in range 0.0 - 1.0. |
EGT_NODISCARD bool autoresize | ( | ) | const |
Return the autoresize state of the widget.
void autoresize | ( | bool | value | ) |
Set the autoresize state.
[in] | value | When true, the widget can be automatically resized. |
By default, this state is true;
EGT_NODISCARD Image * background | ( | bool | allow_fallback = false | ) | const |
Get the background image, if any, for the current group.
allow_fallback | If true, return the 'normal' image if no image is set for the current Palette::GroupId. |
void background | ( | const Image & | image, |
Palette::GroupId | group = Palette::GroupId::normal |
||
) |
Add an image background to the widget's box.
image | Image to set. |
group | Palette::GroupId to set. |
EGT_NODISCARD Image * background | ( | Palette::GroupId | group, |
bool | allow_fallback = false |
||
) | const |
Get the background image, if any, for the given group.
group | Palette::GroupId to get. |
allow_fallback | If true, return the 'normal' image if no image is set for the requested group. |
|
inlineprotectedvirtual |
Cause the widget to draw itself and all of its children.
Reimplemented in Window.
|
inlineprotected |
Call the begin_draw() method of the parent.
As begin_draw() is protected, a subclass of widget is not allowed to call m_parent->begin_draw(), so use this method.
|
inline |
Get the border width.
|
inline |
Set the border width.
|
inline |
Get the border flags.
|
inline |
Set the border flags.
|
inline |
Get the border radius.
|
inline |
Set the border radius.
|
inline |
Bounding box for the Widget.
This is the rectangle that defines where this widget is positioned relative to its parent and also the size of the widget.
void box | ( | const Rect & | rect | ) |
Change the bounding box of the widget.
This is the same as calling move() and resize() at the same time.
|
inline |
Returns true if the widget is capable of handling an event.
|
inline |
Get the boolean checked state of the a widget.
|
virtual |
|
inlineprotected |
Return the array of child widgets.
|
inlineprotected |
Return the array of child widgets.
EGT_NODISCARD bool clip | ( | ) | const |
Return the clip state of the widget.
EGT_NODISCARD const Pattern & color | ( | Palette::ColorId | id | ) | const |
Get a Widget color.
This will return a color for the Palette::GroupId reflecting the current state of the Widget when the call is made. To get a specific Palette::GroupId color, use the overloaded function.
If the id and group exist in the widget instance palette, that will be used. Otherwise, the default_palette() will be used.
id | Palette::ColorId to get. |
void color | ( | Palette::ColorId | id, |
const Pattern & | color, | ||
Palette::GroupId | group = Palette::GroupId::normal |
||
) |
Add a color to the widget's instance palette.
This will add the specified id, color, and group to the widget's instance palette.
id | Palette::ColorId to set. |
color | Color to set. |
group | Palette::GroupId to set. |
EGT_NODISCARD const Pattern & color | ( | Palette::ColorId | id, |
Palette::GroupId | group | ||
) | const |
Get a Widget color.
If the id and group exist in the widget instance palette, that will be used. Otherwise, the default_palette() will be used.
id | Palette::ColorId to get. |
group | Palette::GroupId to get. |
|
protected |
Get the component status.
|
protected |
Set the component flag.
|
inlineprotected |
Return the array of components widgets.
|
inlineprotected |
Return the array of components widgets.
|
virtual |
Return the area that content is allowed to be positioned into.
In most cases, the normal box() area needs to be shrunk by the margin + padding + border. However, some widgets reserve more for themselves, and only allow their children to be positioned in the rest.
void continue_drag | ( | Event & | event | ) |
Handle 'pointer_drag' and 'pointer_drag_stop' events.
Called from Input::dispatch().
event | The drag event that occured. |
|
virtual |
Damage the box() of the widget and cause a redraw.
This is the same as calling damage(box()) in most cases.
|
virtual |
Mark the specified rect as a damaged area of the widget.
rect | The rectangle to save for damage. This will merge the damaged area with any already existing damaged area that it overlaps with into a super rectangle. Then, the whole array has to be checked again to make sure the new rectangle doesn't conflict with another existing rectangle. |
Reimplemented in Window.
|
inlineprotectedvirtual |
Special variation of damage() that is to be called explicitly by subordinate widgets.
Reimplemented in ScrolledView.
|
inlinevirtual |
Deserialize the children of this widget.
Reimplemented in Frame, and StaticGrid.
|
protected |
Deserialize widget properties that require to call overridden methods.
Should be called at the end of all T::T(Serializer::Properties& props, bool is_derived) constructors, if and only if 'is_derived' is 'false'.
Indeed, we wait for an object to be entirely constructed so the expected virtual/overridden methods are executed.
void detach | ( | ) |
Detach this widget from its parent.
void disable | ( | ) |
Set the disabled state to true.
|
inline |
Return the disabled state of the widget.
When a widget is disabled, it does not receive events. Depending on the widget, the color scheme may change.
|
inline |
DisplayPoint display_origin | ( | ) |
Get the display origin of the Widget.
|
virtual |
Convert a display point to a local point.
A display point has origin in the top left of the display. A local point has its origin at the top left of the position of this widget.
Draw the widget.
To change how a widget is drawn, this function can be overloaded and changed in a derived class, or it can be changed dynamically with the Theme.
To optimize drawing, a Widget may use the Rect parameter to limit what needs to be redrawn, which may be smaller than the widget's box(), but will never be outside the widget's box().
Painter will always be supplied in a default state to this function, so there is no need to do any cleanup or state saving inside this draw() function.
Reimplemented in CircleWidget, LineWidget, Button, Switch, CameraWindow, ChartBase, PieChart, CheckBox, ToggleBox, ComboBox, GaugeLayer, NeedleLayer, SelectableGrid, ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, Label, ProgressBarType< T >, ProgressBarType< float >, ProgressBarType< float >, ProgressBarType< int >, ProgressBarType< int >, SpinProgressType< T >, SpinProgressType< float >, SpinProgressType< float >, SpinProgressType< int >, SpinProgressType< int >, LevelMeterType< T >, LevelMeterType< float >, LevelMeterType< float >, LevelMeterType< int >, LevelMeterType< int >, AnalogMeterType< T >, AnalogMeterType< float >, AnalogMeterType< float >, AnalogMeterType< int >, AnalogMeterType< int >, RadialType< T >, RadioBox, RectangleWidget, SliderType< T >, SliderType< float >, SliderType< float >, SliderType< int >, SliderType< int >, Sprite, TextBox, VideoWindow, and ScrolledView.
void draw_box | ( | Painter & | painter, |
Palette::ColorId | bg, | ||
Palette::ColorId | border | ||
) | const |
Helper function to draw this widget's box using the appropriate theme.
void draw_circle | ( | Painter & | painter, |
Palette::ColorId | bg, | ||
Palette::ColorId | border | ||
) | const |
Helper function to draw this widget's circle using the appropriate theme.
void enable | ( | ) |
Set the disabled state to false.
|
inline |
Get a modifiable fill flags reference.
|
inline |
Get the fill flags.
|
inline |
Set the fill flags.
The fill flags of a widget are used to set predefined draw operators for a widget. This provides a level of customization that is primarily for performance optimizations.
Setting a fill type of empty means that no background will be drawn no matter what the background color of the widget is.
|
inlineprotected |
|
inlineprotected |
|
inlineprotected |
Get a modifiable ref of the flags.
|
inlineprotected |
Get a const ref of the flags.
|
inline |
Get the current focus state.
void focus | ( | bool | value | ) |
Set the focus state.
value | State of the focus. |
EGT_NODISCARD const Font & font | ( | ) | const |
|
inline |
EGT_NODISCARD bool frame | ( | ) | const |
Return the frame state of the widget.
EGT_NODISCARD bool grab_mouse | ( | ) | const |
Return the grab_mouse state of the widget.
void grab_mouse | ( | bool | value | ) |
Set the grab_mouse state.
[in] | value | When true, grab mouse events. |
By default, this state is false.
EGT_NODISCARD Palette::GroupId group | ( | ) | const |
Get the current Palette::GroupId depending on the widget's state.
|
virtual |
Handle an event.
This handles global events that usually do not originate at the widget. For example, a pointer event. All events are defined by egt::EventId.
The default implementation in the Widget class, will dispatch the event to any third party handlers that have been registered with on_event(). What this means is if you expect other handlers to receive the events then this must be called from derived classes. Or, manually call invoke_handlers().
Override this function in a derived class to handle events.
event | The Event that occurred. |
Reimplemented in Button, CheckButton, Switch, ComboBox, SelectableGrid, ListBox, RadialType< T >, SideBoard, SliderType< T >, SliderType< float >, SliderType< float >, SliderType< int >, SliderType< int >, TextBox, and ScrolledView.
|
inline |
Check whether the widget has a custom Font.
|
inline |
Check whether the widget has a custom palette.
|
inlinevirtual |
|
inline |
Height of the widget's box().
|
inline |
Change the height.
[in] | h | The new height of the Widget. |
|
virtual |
|
inline |
Returns true if the DisplayPoint is within the widget box.
|
inline |
Get the horizontal ratio relative to parent.
|
inline |
Set the horizontal ratio relative to parent.
[in] | horizontal | Horizontal ratio of parent width, with 100 being 100%. |
|
inline |
Indicate if the Widget is computing the layout or not.
|
inlineprotectedvirtual |
Reimplemented in RadialType< T >, SliderType< T >, SliderType< float >, SliderType< float >, SliderType< int >, SliderType< int >, TextBox, and ScrolledView.
|
inlineprotectedvirtual |
Reimplemented in SliderType< T >, SliderType< float >, SliderType< float >, SliderType< int >, and SliderType< int >.
|
virtual |
Perform layout of the Widget.
This will cause the widget to layout itself and any of its children. This can mean, for example, the widget will resize() itself to respect its min_size_hint().
Reimplemented in StaticGrid, BoxSizer, and ScrolledView.
|
inlineprotected |
Get the local box which is the same size as box(), but with the origin zeroed.
DisplayPoint local_to_display | ( | const Point & | p | ) | const |
Convert a local point to a display point.
A display point has origin in the top left of the display. A local point has its origin at the top left of the position of this widget.
|
inline |
Get the margin width.
|
inline |
Set the margin width.
|
virtual |
Get a minimum size hint for the Widget.
This is used by sizers to pick minimum and default dimensions when no other force is used.
Reimplemented in ComboBox, Button, Switch, Switch, ToggleBox, ComboBox, ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, Label, ProgressBarType< T >, ProgressBarType< float >, ProgressBarType< float >, ProgressBarType< int >, ProgressBarType< int >, SpinProgressType< T >, SpinProgressType< float >, SpinProgressType< float >, SpinProgressType< int >, SpinProgressType< int >, LevelMeterType< T >, LevelMeterType< float >, LevelMeterType< float >, LevelMeterType< int >, LevelMeterType< int >, AnalogMeterType< T >, AnalogMeterType< float >, AnalogMeterType< float >, AnalogMeterType< int >, AnalogMeterType< int >, SliderType< T >, SliderType< float >, SliderType< float >, SliderType< int >, SliderType< int >, StringItem, and TextBox.
|
inline |
Set the minimum size hint for the Widget.
This is used by sizers to pick minimum and default dimensions when no other force is used. When this is set to a non-zero value, this will override any computation done by min_size_hint().
size | The minimum size. |
EGT_NODISCARD size_t moat | ( | ) | const |
|
virtual |
void move_to_center | ( | ) |
Move the widget to the center of its parent.
Changes the X and Y position of the widget relative to the center point of its parent.
void move_to_center | ( | const Point & | point | ) |
Move the widget to the specified center point.
Changes the X and Y position of the widget relative to the center point.
EGT_NODISCARD bool no_layout | ( | ) | const |
Return the no_layout state of the widget.
void no_layout | ( | bool | value | ) |
Set the no_layout state.
[in] | value | When true, parent won't perform layout for the widget. |
By default, this state is false.
|
virtual |
Called from ComposerScreen::resize().
This would have required too many changes to accurately handle all widget life cycles, so instead we call this virtual method on the main window from ComposerScreen::resize() to recursively scan and progress the whole widget tree.
Reimplemented in Frame.
|
inline |
Return the padding width.
|
inline |
Set the padding width.
|
virtual |
|
virtual |
Draw the widget to a file.
[in] | filename | Optional filename to save to. |
Reimplemented in Frame.
EGT_NODISCARD const Palette & palette | ( | ) | const |
Get the widget palette.
This will return any palette set on the widget instance, or default to the global palette.
void palette | ( | const Palette & | palette | ) |
Set the widget instance Palette.
This will replace any Palette instance currently owned by the Widget. This does not have to be a complete Palette, in which case the widget will default to the Theme palette if a Color is not found in this palette.
palette | The new palette to assign to the widget. |
EGT_NODISCARD const Widget * parent | ( | ) | const |
Get a pointer to the parent Widget, or nullptr if none exists.
|
protected |
Indicate if our parent is computing the layout.
|
protected |
Call our parent to do a layout.
EGT_NODISCARD bool plane_window | ( | ) | const |
Return the plane_window state of the widget.
Reimplemented in ScrolledView.
|
inlinevirtual |
Resume deserializing of the widget after its children have been deserialized.
Reimplemented in Notebook, and ScrolledView.
|
inlineprotected |
Return either components() or children() depending on widget.component()
|
inlineprotected |
Return either components() or children() depending on widget.component()
|
inline |
Set the size ratio relative to parent.
[in] | horizontal | Horizontal ratio of parent width, with 100 being 100%. |
[in] | vertical | Vertical ratio of parent height, with 100 being 100%. |
|
inline |
Set the size ratio relative to parent.
[in] | ratio | Horizontal and vertical ratio parent size, with 100 being 100%. |
|
inline |
Get the readonly state of the widget.
void readonly | ( | bool | value | ) |
Set the readonly state of the widget.
When a widget is readonly, it typically works as normal, except it does not accept any user input. Depending on the widget, the color scheme may change.
value | Readonly when true. |
|
inline |
Toggle the readonly state.
|
protected |
Remove a component.
void reset_background | ( | Palette::GroupId | group = Palette::GroupId::normal | ) |
Remove an image background from the widget's box.
group | Palette::GroupId to set. |
|
inline |
void reset_palette | ( | ) |
Clear the widget instance palette.
This will clear the widget instance's palette. Meaning, for all colors the widget will now use default_palette().
|
virtual |
Resize the widget.
Changes the width and height of the Widget.
[in] | size | The new size of the Widget. |
Reimplemented in ComboBox, ListBox, VideoWindow, VirtualKeyboard, ChartBase, PieChart, CircleWidget, TextBox, VideoWindow, ScrolledView, and Window.
void resize_by_ratio | ( | DefaultDim | hratio, |
DefaultDim | vratio | ||
) |
Scale the current size of the Widget given the ratio.
There is no automatic undo for this operation. Each call to this function uses the current size of the Widget.
[in] | hratio | Horizontal ratio of width(), with 100 being 100%. |
[in] | vratio | Vertical ratio of height(), with 100 being 100%. |
|
inline |
|
inlinevirtual |
Set the scale of the widget.
[in] | hscale | Horizontal scale, with 1.0 being 100%. |
[in] | vscale | Vertical scale, with 1.0 being 100%. |
Reimplemented in CameraWindow, CameraWindow, VideoWindow, VideoWindow, and Window.
|
inline |
Set the scale of the widget.
[in] | scale | Vertical and horizontal scale, with 1.0 being 100%. |
|
virtual |
|
virtual |
Serialize the widget to the specified serializer.
Reimplemented in ChartBase, Switch, CameraWindow, LineChart, PointChart, BarChart, PieChart, ToggleBox, ComboBox, Frame, StaticGrid, SelectableGrid, ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, ListBox, Notebook, ProgressBarType< T >, ProgressBarType< float >, ProgressBarType< float >, ProgressBarType< int >, ProgressBarType< int >, SpinProgressType< T >, SpinProgressType< float >, SpinProgressType< float >, SpinProgressType< int >, SpinProgressType< int >, LevelMeterType< T >, LevelMeterType< float >, LevelMeterType< float >, LevelMeterType< int >, LevelMeterType< int >, Scrollwheel, CircleWidget, LineWidget, SideBoard, BoxSizer, SliderType< T >, SliderType< float >, SliderType< float >, SliderType< int >, SliderType< int >, TextBox, TextWidget, ValueRangeWidget< T >, ValueRangeWidget< float >, ValueRangeWidget< float >, ValueRangeWidget< int >, ValueRangeWidget< int >, VideoWindow, ScrolledView, and Window.
|
inlinevirtual |
Serialize the widget's children to the specified serializer.
Reimplemented in Frame, and StaticGrid.
|
protectedvirtual |
|
virtual |
Special draw function that can be invoked when drawing each child.
This is useful, for example, to draw a custom bounding box around children or to modify how a child draws by overwriting it.
painter | An instance of the Painter to use. |
widget | The widget. |
|
inlineprotected |
Get the special child draw callback.
|
inlineprotected |
Set the special child draw callback.
|
inlineprotected |
Get the child draw callback of the parent.
As special_child_draw_callback() is protected, a subclass of widget is not allowed to call m_parent->special_child_draw_callback(), so use this method.
|
protected |
Handle 'pointer_drag_start' events and decide whether they are caught by this widget.
Called from handle().
event | The drag event that occured. |
EGT_NODISCARD const Theme & theme | ( | ) | const |
Convert a local point to the coordinate system of the current panel.
In other words, work towards a parent that has the panel so we can get this point relative to the origin of the panel we are drawing to.
Convert a point with a local origin to a parent origin.
Convert a point in a rect a local origin to a parent origin.
Convert a point with an origin of the current widget to subordinate origin.
|
inlineprotectedvirtual |
Is this widget a top level widget?
Reimplemented in Frame.
|
inlineprotected |
Tell the continue_drag() method whether the widget tracks 'pointer_drag*' events once they have crossed out the widget boundaries.
If not, a 'pointer_drag_stop' event is inserted wihtin the widget boundaries.
|
virtual |
Returns a string representation of the type of this widget.
Should this need to be changed, override this function.
Reimplemented in ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Button, Palette::ColorId::button_bg, Palette::ColorId::border, Palette::ColorId::button_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, ImageHolder< Label, Palette::ColorId::label_bg, Palette::ColorId::border, Palette::ColorId::label_text >, ProgressBar, ProgressBarF, SpinProgress, SpinProgressF, LevelMeter, LevelMeterF, AnalogMeter, AnalogMeterF, Slider, and SliderF.
|
inlineprotected |
Update the 'm_children' and 'm_components' members.
|
inline |
|
inline |
|
inline |
Get the box corresponding to the user requested one, not the actual one.
|
inline |
|
inline |
|
inline |
Get the vertical ratio relative to parent.
|
inline |
Set the vertical ratio relative to parent.
[in] | vertical | Vertical ratio of parent height, with 100 being 100%. |
|
inline |
Get the visible state of the widget.
void visible | ( | bool | value | ) |
Set the visible state.
|
virtual |
|
inline |
Get the unique id of the widget.
Every widget allocated is given a unique id. This is used internally to create a default name() of the widget, but can also be used to uniquely identify widgets for other purposes.
|
inline |
Width of the widget's box().
|
inline |
Change the width.
[in] | w | The new width of the Widget. |
|
inline |
X coordinate of the widget's box().
|
inline |
Set the X coordinate of the box.
[in] | x | The new origin X value for the widget relative to its parent. |
|
inline |
Get the X position ratio relative to parent.
|
inline |
Set the X position ratio relative to parent.
[in] | xratio | X ratio of parent width, with 100 being 100%. |
|
inline |
Y coordinate of the widget's box().
|
inline |
Set the Y coordinate of the box.
[in] | y | The new origin Y value for the widget relative to its parent. |
|
inline |
Get the Y position ratio relative to parent.
|
inline |
Set the Y position ratio relative to parent.
[in] | yratio | Y ratio of parent height, with 100 being 100%. |
|
virtual |
|
protected |
Get the zorder of the widget.
widget | The widget. |
|
protected |
Set the zorder of the widget.
widget | The widget. |
rank | The rank in the zorder. |
|
virtual |
|
virtual |
|
protected |
Move the specified widget zorder to the bottom of the current list of widgets with the same parent.
widget | The widget. |
|
virtual |
|
protected |
Move the specified widget zorder down relative to other widgets with the same parent.
widget | The widget. |
|
virtual |
|
protected |
Move the specified widget zorder to the top of the current list of widgets with the same parent.
widget | The widget. |
|
virtual |
|
protected |
Move the specified widget zorder up relative to other widgets with the same parent.
widget | The widget. |
|
friend |
|
protected |
Bounding box.
|
protected |
Array of child widgets in the order they were added.
|
protected |
Array of component widgets in the order they were added.
|
protected |
Iterator for the beginning of components which are positionned after children in the subordinates array.
Components are child widget as well, but not added through the Frame interface. Components are composition widgets and users must not be able to add extra ones or to remove them.
|
protected |
The damage array for this widget.
|
protected |
Status for whether this widget is currently drawing.
|
protected |
Status for whether this widget is currently performing layout.
|
protected |
Minimum size of the widget when not an empty value.
|
protected |
|
protected |
Used internally for calling the special child draw function.
|
protected |
Array of subordinates widgets split in child widgets and component widgets.
|
protected |
Keep track of the box requested by the user.
|
protected |
Unique ID of this widget.
Signal on_gain_focus |
Invoked when the widget gains focus.
Signal on_hide |
Invoked when a widget is hidden.
Signal on_lost_focus |
Invoked when the widget loses focus.
Signal on_show |
Invoked when a widget is shown.