1.1-rc1
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Widget Class Referenceabstract

Base Widget class. More...

Inheritance diagram for Widget:
Inheritance graph
[legend]

Public Types

enum  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)
}
 Common flags used for various widget properties. More...
 
using Flags = egt::Flags< Widget::Flag >
 Widget flags. More...
 
using WalkCallback = std::function< bool(Widget *widget, int level)>
 Callback definition used by walk(). More...
 
using WidgetId = uint64_t
 Type used to identify a unique Widget ID. More...
 
- Public Types inherited from Object
using EventCallback = std::function< void(Event &event)>
 Event handler callback function. More...
 
using FilterFlags = FlagsBase< EventId >
 Event handler EventId filter. More...
 
using RegisterHandle = uint64_t
 Handle type. More...
 

Public Member Functions

 Widget (const Rect &rect={}, const Widget::Flags &flags={}) noexcept
 
 Widget (Frame &parent, const Rect &rect={}, const Widget::Flags &flags={}) noexcept
 
 Widget (const Widget &)=delete
 
 Widget (Widget &&) noexcept=default
 
 ~Widget () noexcept override
 
EGT_NODISCARD bool active () const
 Get the active state. More...
 
void active (bool value)
 Set the active state. More...
 
void align (const AlignFlags &a)
 Align the widget. More...
 
EGT_NODISCARD const AlignFlagsalign () const
 Get the alignment. More...
 
AlignFlagsalign ()
 Get the alignment. More...
 
EGT_NODISCARD float alpha () const
 Get the alpha property. More...
 
void alpha (float alpha)
 Set the alpha property. More...
 
void autoresize (bool value)
 Set the autoresize state. More...
 
EGT_NODISCARD bool autoresize () const
 Return the autoresize state of the widget. More...
 
void border (DefaultDim border)
 Set the border width. More...
 
EGT_NODISCARD DefaultDim border () const
 Get the border width. More...
 
void border_flags (const Theme::BorderFlags &flags)
 Set the border flags. More...
 
EGT_NODISCARD Theme::BorderFlags border_flags () const
 Get the border flags. More...
 
void border_radius (float radius)
 Set the border radius. More...
 
EGT_NODISCARD float border_radius () const
 Get the border radius. More...
 
EGT_NODISCARD const Rectbox () const
 Bounding box for the Widget. More...
 
void box (const Rect &rect)
 Change the bounding box of the widget. More...
 
bool can_handle_event () const
 Returns true if the widget is capable of handling an event. More...
 
EGT_NODISCARD Point center () const
 Get the center point of the widget's box(). More...
 
EGT_NODISCARD bool checked () const
 Get the boolean checked state of the a widget. More...
 
virtual void checked (bool value)
 Set the checked state of the widget. More...
 
EGT_NODISCARD bool clip () const
 Return the clip state of the widget. More...
 
EGT_NODISCARD const Patterncolor (Palette::ColorId id) const
 Get a Widget color. More...
 
EGT_NODISCARD const Patterncolor (Palette::ColorId id, Palette::GroupId group) const
 Get a Widget color. More...
 
void color (Palette::ColorId id, const Pattern &color, Palette::GroupId group=Palette::GroupId::normal)
 Add a color to the widget's instance palette. More...
 
virtual EGT_NODISCARD Rect content_area () const
 Return the area that content is allowed to be positioned into. More...
 
virtual void damage ()
 Damage the box() of the widget and cause a redraw. More...
 
virtual void damage (const Rect &rect)
 Mark the specified rect as a damaged area of the widget. More...
 
virtual void deserialize (const std::string &name, const std::string &value, const Serializer::Attributes &attrs)
 Deserialize widget properties. More...
 
void detach ()
 Detach this widget from its parent. More...
 
void disable ()
 Set the disabled state to true. More...
 
void disable_toggle ()
 Toggle the disabled state. More...
 
EGT_NODISCARD bool disabled () const
 Return the disabled state of the widget. More...
 
void disabled (bool value)
 Set the disabled state. More...
 
DisplayPoint display_origin ()
 Get the display origin of the Widget. More...
 
virtual Point display_to_local (const DisplayPoint &p)
 Convert a display point to a local point. More...
 
virtual void draw (Painter &painter, const Rect &rect)=0
 Draw the widget. More...
 
void draw_box (Painter &painter, Palette::ColorId bg, Palette::ColorId border) const
 Helper function to draw this widget's box using the appropriate theme. More...
 
void draw_circle (Painter &painter, Palette::ColorId bg, Palette::ColorId border) const
 Helper function to draw this widget's circle using the appropriate theme. More...
 
void enable ()
 Set the disabled state to false. More...
 
void fill_flags (const Theme::FillFlags &flags)
 Set the fill flags. More...
 
EGT_NODISCARD const Theme::FillFlagsfill_flags () const
 Get the fill flags. More...
 
Theme::FillFlagsfill_flags ()
 Get a modifiable fill flags reference. More...
 
EGT_NODISCARD bool focus () const
 Get the current focus state. More...
 
EGT_NODISCARD const Fontfont () const
 Get the widget Font. More...
 
void font (const Font &font)
 Set the widget Font. More...
 
EGT_NODISCARD bool frame () const
 Return the frame state of the widget. More...
 
void grab_mouse (bool value)
 Set the grab_mouse state. More...
 
EGT_NODISCARD bool grab_mouse () const
 Return the grab_mouse state of the widget. More...
 
virtual void handle (Event &event)
 Handle an event. More...
 
void height (DefaultDim h)
 Change the height. More...
 
EGT_NODISCARD DefaultDim height () const
 Height of the widget's box(). More...
 
virtual void hide ()
 Hide the Widget. More...
 
void horizontal_ratio (DefaultDim horizontal)
 Set the horizontal ratio relative to parent. More...
 
EGT_NODISCARD DefaultDim horizontal_ratio () const
 Get the horizontal ratio relative to parent. More...
 
EGT_NODISCARD bool in_layout () const
 Indicate if the Widget is computing the layout or not. More...
 
virtual void layout ()
 Perform layout of the Widget. More...
 
DisplayPoint local_to_display (const Point &p)
 Convert a local point to a display point. More...
 
void margin (DefaultDim margin)
 Set the margin width. More...
 
EGT_NODISCARD DefaultDim margin () const
 Get the margin width. More...
 
virtual EGT_NODISCARD Size min_size_hint () const
 Get a minimum size hint for the Widget. More...
 
void min_size_hint (const Size &size)
 Set the minimum size hint for the Widget. More...
 
EGT_NODISCARD size_t moat () const
 Get the sum of the margin(), padding(), and border() around the content of the widget. More...
 
virtual void move (const Point &point)
 Move the Widget to a new position. More...
 
void move_to_center (const Point &point)
 Move the widget to the specified center point. More...
 
void move_to_center ()
 Move the widget to the center of its parent. More...
 
void no_layout (bool value)
 Set the no_layout state. More...
 
EGT_NODISCARD bool no_layout () const
 Return the no_layout state of the widget. More...
 
Widgetoperator= (const Widget &)=delete
 
Widgetoperator= (Widget &&) noexcept=default
 
void padding (DefaultDim padding)
 Set the padding width. More...
 
EGT_NODISCARD DefaultDim padding () const
 Return the padding width. More...
 
virtual void paint (Painter &painter)
 Paint the Widget using a Painter. More...
 
virtual void paint_to_file (const std::string &filename={})
 Draw the widget to a file. More...
 
void palette (const Palette &palette)
 Set the widget instance Palette. More...
 
Frameparent ()
 Get a pointer to the parent Frame, or nullptr if none exists. More...
 
EGT_NODISCARD const Frameparent () const
 Get a pointer to the parent Frame, or nullptr if none exists. More...
 
EGT_NODISCARD bool plane_window () const
 Return the plane_window state of the widget. More...
 
EGT_NODISCARD const Pointpoint () const
 Get the origin of the widget's box(). More...
 
void ratio (DefaultDim ratio)
 Set the size ratio relative to parent. More...
 
void ratio (DefaultDim horizontal, DefaultDim vertical)
 Set the size ratio relative to parent. More...
 
EGT_NODISCARD bool readonly () const
 Get the readonly state of the widget. More...
 
void readonly (bool value)
 Set the readonly state of the widget. More...
 
void readonly_toggle ()
 Toggle the readonly state. More...
 
void reset_palette ()
 Clear the widget instance palette. More...
 
void reset_theme ()
 Reset the Widget's Theme to the default Theme. More...
 
virtual void resize (const Size &size)
 Resize the widget. More...
 
void resize_by_ratio (DefaultDim hratio, DefaultDim vratio)
 Scale the current size of the Widget given the ratio. More...
 
void resize_by_ratio (DefaultDim ratio)
 Scale the current size of the Widget given the ratio. More...
 
virtual void scale (float hscale, float vscale)
 Set the scale of the widget. More...
 
void scale (float scale)
 Set the scale of the widget. More...
 
virtual EGT_NODISCARD Screenscreen () const
 Get a pointer to the Screen instance, using using a parent as necessary. More...
 
virtual void serialize (Serializer &serializer) const
 Serialize the widget to the specified serializer. More...
 
virtual void show ()
 Show the Widget. More...
 
EGT_NODISCARD const Sizesize () const
 Get the size of the widget's box(). More...
 
EGT_NODISCARD const Themetheme () const
 Get the Widget Theme. More...
 
void theme (const Theme &theme)
 Set the Widget's theme to a new theme. More...
 
EGT_NODISCARD Point to_parent (const Point &r) const
 Convert a point with a local origin to a parent origin. More...
 
EGT_NODISCARD Rect to_parent (const Rect &r) const
 Convert a point in a rect a local origin to a parent origin. More...
 
virtual EGT_NODISCARD std::string type () const
 Returns a string representation of the type of this widget. More...
 
EGT_NODISCARD const Rectuser_requested_box () const
 Get the box corresponding to the user requested one, not the actual one. More...
 
void vertical_ratio (DefaultDim vertical)
 Set the vertical ratio relative to parent. More...
 
EGT_NODISCARD DefaultDim vertical_ratio () const
 Get the vertical ratio relative to parent. More...
 
EGT_NODISCARD bool visible () const
 Get the visible state of the widget. More...
 
void visible (bool value)
 Set the visible state. More...
 
void visible_toggle ()
 Toggle the visibility state. More...
 
virtual void walk (const WalkCallback &callback, int level=0)
 Walk the Widget tree and call callback with each Widget. More...
 
EGT_NODISCARD WidgetId widgetid () const
 Get the unique id of the widget. More...
 
void width (DefaultDim w)
 Change the width. More...
 
EGT_NODISCARD DefaultDim width () const
 Width of the widget's box(). More...
 
void x (DefaultDim x)
 Set the X coordinate of the box. More...
 
EGT_NODISCARD DefaultDim x () const
 X coordinate of the widget's box(). More...
 
void xratio (DefaultDim xratio)
 Set the X position ratio relative to parent. More...
 
EGT_NODISCARD DefaultDim xratio () const
 Get the X position ratio relative to parent. More...
 
void y (DefaultDim y)
 Set the Y coordinate of the box. More...
 
EGT_NODISCARD DefaultDim y () const
 Y coordinate of the widget's box(). More...
 
void yratio (DefaultDim yratio)
 Set the Y position ratio relative to parent. More...
 
EGT_NODISCARD DefaultDim yratio () const
 Get the Y position ratio relative to parent. More...
 
virtual EGT_NODISCARD size_t zorder () const
 Get the zorder of the widget. More...
 
virtual void zorder_bottom ()
 Move the widget to the bottom. More...
 
virtual void zorder_down ()
 Move this widgets zorder down relative to other widgets with the same parent. More...
 
virtual void zorder_top ()
 Move the widget to the top. More...
 
virtual void zorder_up ()
 Move this widgets zorder up relative to other widgets with the same parent. More...
 
- 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. More...
 
void invoke_handlers (Event &event)
 Invoke all handlers with the specified event. More...
 
void invoke_handlers (EventId event)
 Invoke all handlers with the specified EventId. More...
 
EGT_NODISCARD const std::string & name () const
 Get the name of the Object. More...
 
void name (const std::string &name)
 Set the name of the Object. More...
 
RegisterHandle on_event (const EventCallback &handler, const FilterFlags &mask={})
 Add an event handler to be called when the widget generates an event. More...
 
Objectoperator= (const Object &)=delete
 
Objectoperator= (Object &&)=default
 
void remove_handler (RegisterHandle handle)
 Remove an event handler. More...
 

Public Attributes

Signal on_checked_changed
 Event signal. More...
 
Signal on_gain_focus
 Invoked when the widget gains focus. More...
 
Signal on_lost_focus
 Invoked when the widget loses focus. More...
 
Signal on_show
 Invoked when a widget is shown. More...
 
Signal on_hide
 Invoked when a widget is hidden. More...
 

Protected Member Functions

EGT_NODISCARD const Palettedefault_palette () const
 Get a reference to the default palette. More...
 
EGT_NODISCARD const Widget::Flagsflags () const
 Get a const ref of the flags. More...
 
Widget::Flagsflags ()
 Get a modifiable ref of the flags. More...
 
EGT_NODISCARD Rect local_box () const
 Get the local box which is the same size as box(), but with the origin zeroed. More...
 
EGT_NODISCARD bool parent_in_layout ()
 Indicate if our parent is computing the layout. More...
 
void parent_layout ()
 Call our parent to do a layout. More...
 
virtual void set_parent (Frame *parent)
 Set this widget's parent. More...
 
virtual EGT_NODISCARD bool top_level () const
 Is this widget a top level widget? More...
 

Protected Attributes

Rect m_box
 Bounding box. More...
 
bool m_in_layout {false}
 Status for whether this widget is currently performing layout. More...
 
Size m_min_size
 Minimum size of the widget when not an empty value. More...
 
Framem_parent {nullptr}
 Pointer to this widget's parent. More...
 
Rect m_user_requested_box
 Keep track of the box requested by the user. More...
 
WidgetId m_widgetid {0}
 Unique ID of this widget. More...
 
- Protected Attributes inherited from Object
detail::CopyOnWriteAllocate< CallbackArraym_callbacks
 Array of callbacks. More...
 
RegisterHandle m_handle_counter {0}
 Counter used to generate unique handles for each callback registration. More...
 
std::string m_name
 A user defined name for the Object. More...
 

Friends

class Frame
 

Additional Inherited Members

- Protected Types inherited from Object
using CallbackArray = std::vector< CallbackMeta >
 Helper type for an array of callbacks. More...
 

Detailed Description

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.

Member Typedef Documentation

◆ Flags

using Flags = egt::Flags<Widget::Flag>

Widget flags.

◆ WalkCallback

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.

◆ WidgetId

using WidgetId = uint64_t

Type used to identify a unique Widget ID.

Member Enumeration Documentation

◆ Flag

enum Flag : uint32_t
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.

Constructor & Destructor Documentation

◆ Widget() [1/4]

Widget ( const Rect rect = {},
const Widget::Flags flags = {} 
)
explicitnoexcept
Parameters
[in]rectInitial rectangle of the Widget.
[in]flagsWidget flags.

◆ Widget() [2/4]

Widget ( Frame parent,
const Rect rect = {},
const Widget::Flags flags = {} 
)
explicitnoexcept
Parameters
[in]parentParent Frame of the Widget.
[in]rectInitial rectangle of the Widget.
[in]flagsWidget flags.

◆ Widget() [3/4]

Widget ( const Widget )
delete

◆ Widget() [4/4]

Widget ( Widget &&  )
defaultnoexcept

◆ ~Widget()

~Widget ( )
overridenoexcept

Member Function Documentation

◆ active() [1/2]

EGT_NODISCARD bool active ( ) const

Get the active state.

The meaning of active is largely up to the derived implementation.

◆ active() [2/2]

void active ( bool  value)

Set the active state.

The meaning of active is largely up to the derived implementation.

◆ align() [1/3]

void align ( const AlignFlags a)

Align the widget.

This will align the widget relative to the box of its parent frame.

Parameters
[in]aThe AlignFlags.

◆ align() [2/3]

EGT_NODISCARD const AlignFlags& align ( ) const
inline

Get the alignment.

◆ align() [3/3]

AlignFlags& align ( )
inline

Get the alignment.

◆ alpha() [1/2]

EGT_NODISCARD float alpha ( ) const
inline

Get the alpha property.

Returns
Alpha property in the range 0.0 to 1.0.

◆ alpha() [2/2]

void alpha ( float  alpha)

Set the alpha property.

This controls the alpha property of the entire widget and all of its children.

Parameters
[in]alphaWidget alpha component in range 0.0 - 1.0.

◆ autoresize() [1/2]

void autoresize ( bool  value)

Set the autoresize state.

Parameters
[in]valueWhen true, the widget can be automatically resized.

By default, this state is true;

◆ autoresize() [2/2]

EGT_NODISCARD bool autoresize ( ) const

Return the autoresize state of the widget.

◆ border() [1/2]

void border ( DefaultDim  border)
inline

Set the border width.

See also
The Widget Box Model

◆ border() [2/2]

EGT_NODISCARD DefaultDim border ( ) const
inline

Get the border width.

See also
The Widget Box Model

◆ border_flags() [1/2]

void border_flags ( const Theme::BorderFlags flags)
inline

Set the border flags.

See also
Theme::BorderFlag

◆ border_flags() [2/2]

EGT_NODISCARD Theme::BorderFlags border_flags ( ) const
inline

Get the border flags.

See also
Theme::BorderFlag

◆ border_radius() [1/2]

void border_radius ( float  radius)
inline

Set the border radius.

◆ border_radius() [2/2]

EGT_NODISCARD float border_radius ( ) const
inline

Get the border radius.

◆ box() [1/2]

EGT_NODISCARD const Rect& box ( ) const
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.

See also
The Widget Box Model

◆ box() [2/2]

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.

See also
The Widget Box Model

◆ can_handle_event()

bool can_handle_event ( ) const
inline

Returns true if the widget is capable of handling an event.

◆ center()

EGT_NODISCARD Point center ( ) const
inline

Get the center point of the widget's box().

◆ checked() [1/2]

EGT_NODISCARD bool checked ( ) const
inline

Get the boolean checked state of the a widget.

Returns
true if checked.

◆ checked() [2/2]

virtual void checked ( bool  value)
virtual

Set the checked state of the widget.

Reimplemented in Button.

◆ clip()

EGT_NODISCARD bool clip ( ) const

Return the clip state of the widget.

◆ color() [1/3]

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.

Parameters
idPalette::ColorId to get.

◆ color() [2/3]

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.

Parameters
idPalette::ColorId to get.
groupPalette::GroupId to get.

◆ color() [3/3]

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.

Parameters
idPalette::ColorId to set.
colorColor to set.
groupPalette::GroupId to set.

◆ content_area()

virtual EGT_NODISCARD Rect content_area ( ) const
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.

See also
The Widget Box Model

◆ damage() [1/2]

virtual void damage ( )
virtual

Damage the box() of the widget and cause a redraw.

This is the same as calling damage(box()) in most cases.

Warning
damage() cannot be called while in or below a Widget::draw() method.

Reimplemented in Frame.

◆ damage() [2/2]

virtual void damage ( const Rect rect)
virtual

Mark the specified rect as a damaged area of the widget.

Note
This call will propagate to a top level parent frame that owns a Screen.
Warning
damage() cannot be called while in or below a Widget::draw() method.
Parameters
rectThe rectangle to save for damage.

Reimplemented in Frame, Window, and ScrolledView.

◆ default_palette()

EGT_NODISCARD const Palette& default_palette ( ) const
protected

Get a reference to the default palette.

This returns the palette of the theme assigned to the widget.

This is the same as calling theme().palette().

◆ deserialize()

virtual void deserialize ( const std::string &  name,
const std::string &  value,
const Serializer::Attributes attrs 
)
virtual

◆ detach()

void detach ( )

Detach this widget from its parent.

Warning
This can result in immediately deleting the instance of the widget if its lifetime is managed by a smart pointer and there are no more references.

◆ disable()

void disable ( )

Set the disabled state to true.

◆ disable_toggle()

void disable_toggle ( )
inline

Toggle the disabled state.

See also
disable() and enable()

◆ disabled() [1/2]

EGT_NODISCARD bool disabled ( ) const
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.

◆ disabled() [2/2]

void disabled ( bool  value)
inline

Set the disabled state.

Parameters
[in]valueWhen true, the Widget is disabled.
See also
enable() and disable()

◆ display_origin()

DisplayPoint display_origin ( )

Get the display origin of the Widget.

◆ display_to_local()

virtual Point display_to_local ( const DisplayPoint p)
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.

See also
Coordinate System

◆ draw()

virtual void draw ( Painter painter,
const Rect rect 
)
pure virtual

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.

Warning
Normally this should not be called directly and instead the EventLoop will call this function with an already established Painter when the Widget needs to be drawn.
See also
Color, Palette, and Theme and Drawing
Parameters
[in]painterInstance of the Painter for the Screen.
[in]rectThe rectangle to draw.

Implemented in AnalogMeterType< T >, AnalogMeterType< float >, AnalogMeterType< int >, PieChart, LevelMeterType< T >, LevelMeterType< float >, LevelMeterType< int >, BarChart, SelectableGrid, SpinProgressType< T >, SpinProgressType< float >, SpinProgressType< int >, Frame, ImageButton, PointChart, RadialType< T >, SliderType< T >, SliderType< float >, SliderType< int >, ImageLabel, RectangleWidget, NeedleLayer, TextBox, Button, CameraWindow, VideoWindow, LineChart, ToggleBox, LineWidget, ComboBox, Sprite, Label, ScrolledView, ProgressBarType< T >, ProgressBarType< float >, ProgressBarType< int >, CheckBox, CircleWidget, GaugeLayer, and RadioBox.

◆ draw_box()

void draw_box ( Painter painter,
Palette::ColorId  bg,
Palette::ColorId  border 
) const

Helper function to draw this widget's box using the appropriate theme.

◆ draw_circle()

void draw_circle ( Painter painter,
Palette::ColorId  bg,
Palette::ColorId  border 
) const

Helper function to draw this widget's circle using the appropriate theme.

◆ enable()

void enable ( )

Set the disabled state to false.

◆ fill_flags() [1/3]

void fill_flags ( const Theme::FillFlags 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.

See also
Theme::FillFlag

◆ fill_flags() [2/3]

EGT_NODISCARD const Theme::FillFlags& fill_flags ( ) const
inline

Get the fill flags.

See also
Theme::FillFlag

◆ fill_flags() [3/3]

Theme::FillFlags& fill_flags ( )
inline

Get a modifiable fill flags reference.

See also
Theme::FillFlag

◆ flags() [1/2]

EGT_NODISCARD const Widget::Flags& flags ( ) const
inlineprotected

Get a const ref of the flags.

◆ flags() [2/2]

Widget::Flags& flags ( )
inlineprotected

Get a modifiable ref of the flags.

Warning
Directly modifying flags may result in inconsistent state of the widget. Always use the appropriate member functions (i.e. readonly(), checked()).

◆ focus()

EGT_NODISCARD bool focus ( ) const
inline

Get the current focus state.

Returns
true if in focus.

◆ font() [1/2]

EGT_NODISCARD const Font& font ( ) const
inline

Get the widget Font.

This will return any font set on the widget instance, or default to the widget Theme font.

◆ font() [2/2]

void font ( const Font font)
inline

Set the widget Font.

Sets the widget font which means the widget instance will no longer use its Theme font.

◆ frame()

EGT_NODISCARD bool frame ( ) const

Return the frame state of the widget.

◆ grab_mouse() [1/2]

void grab_mouse ( bool  value)

Set the grab_mouse state.

Parameters
[in]valueWhen true, grab mouse events.

By default, this state is false.

◆ grab_mouse() [2/2]

EGT_NODISCARD bool grab_mouse ( ) const

Return the grab_mouse state of the widget.

◆ handle()

virtual void handle ( Event event)
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.

See also
Events
Parameters
eventThe Event that occurred.

Reimplemented in SelectableGrid, RadialType< T >, TextBox, SliderType< T >, SliderType< float >, SliderType< int >, CameraWindow, VideoWindow, Button, ListBox, ComboBox, ScrolledView, SideBoard, Frame, CheckBox, and RadioBox.

◆ height() [1/2]

void height ( DefaultDim  h)
inline

Change the height.

Parameters
[in]hThe new height of the Widget.

◆ height() [2/2]

EGT_NODISCARD DefaultDim height ( ) const
inline

Height of the widget's box().

◆ hide()

virtual void hide ( )
virtual

Hide the Widget.

A widget that is not visible will receive no draw() calls.

This changes the visible() state of the Widget.

Reimplemented in Window.

◆ horizontal_ratio() [1/2]

void horizontal_ratio ( DefaultDim  horizontal)
inline

Set the horizontal ratio relative to parent.

Parameters
[in]horizontalHorizontal ratio of parent width, with 100 being 100%.

◆ horizontal_ratio() [2/2]

EGT_NODISCARD DefaultDim horizontal_ratio ( ) const
inline

Get the horizontal ratio relative to parent.

◆ in_layout()

EGT_NODISCARD bool in_layout ( ) const
inline

Indicate if the Widget is computing the layout or not.

◆ layout()

virtual void layout ( )
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 Frame, StaticGrid, ScrolledView, and BoxSizer.

◆ local_box()

EGT_NODISCARD Rect local_box ( ) const
inlineprotected

Get the local box which is the same size as box(), but with the origin zeroed.

◆ local_to_display()

DisplayPoint local_to_display ( const Point p)

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.

See also
Coordinate System

◆ margin() [1/2]

void margin ( DefaultDim  margin)
inline

Set the margin width.

See also
The Widget Box Model

◆ margin() [2/2]

EGT_NODISCARD DefaultDim margin ( ) const
inline

Get the margin width.

See also
The Widget Box Model

◆ min_size_hint() [1/2]

virtual EGT_NODISCARD Size min_size_hint ( ) const
virtual

◆ min_size_hint() [2/2]

void min_size_hint ( const Size size)
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().

Parameters
sizeThe minimum size.

◆ moat()

EGT_NODISCARD size_t moat ( ) const

Get the sum of the margin(), padding(), and border() around the content of the widget.

◆ move()

virtual void move ( const Point point)
virtual

Move the Widget to a new position.

Changes the X and Y position of the Widget.

Parameters
[in]pointThe new origin point for the widget relative to its parent.
Note
This will cause a redraw of the Widget.

Reimplemented in Window, and ComboBox.

◆ move_to_center() [1/2]

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.

Note
This will cause a redraw of the widget.

◆ move_to_center() [2/2]

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.

Note
This will cause a redraw of the widget.

◆ no_layout() [1/2]

void no_layout ( bool  value)

Set the no_layout state.

Parameters
[in]valueWhen true, parent won't perform layout for the widget.

By default, this state is false.

◆ no_layout() [2/2]

EGT_NODISCARD bool no_layout ( ) const

Return the no_layout state of the widget.

◆ operator=() [1/2]

Widget& operator= ( const Widget )
delete

◆ operator=() [2/2]

Widget& operator= ( Widget &&  )
defaultnoexcept

◆ padding() [1/2]

void padding ( DefaultDim  padding)
inline

Set the padding width.

See also
The Widget Box Model

◆ padding() [2/2]

EGT_NODISCARD DefaultDim padding ( ) const
inline

Return the padding width.

See also
The Widget Box Model

◆ paint()

virtual void paint ( Painter painter)
virtual

Paint the Widget using a Painter.

paint() is not part of the normal draw path. This is a utility function to get the widget to draw its contents to another surface provided with a Painter.

Reimplemented in Window, and Sprite.

◆ paint_to_file()

virtual void paint_to_file ( const std::string &  filename = {})
virtual

Draw the widget to a file.

Parameters
[in]filenameOptional filename to save to.

Reimplemented in Frame.

◆ 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.

Parameters
paletteThe new palette to assign to the widget.
Note
This will overwrite the entire widget Palette.

◆ parent() [1/2]

Frame* parent ( )

Get a pointer to the parent Frame, or nullptr if none exists.

◆ parent() [2/2]

EGT_NODISCARD const Frame* parent ( ) const

Get a pointer to the parent Frame, or nullptr if none exists.

◆ parent_in_layout()

EGT_NODISCARD bool parent_in_layout ( )
protected

Indicate if our parent is computing the layout.

◆ parent_layout()

void parent_layout ( )
protected

Call our parent to do a layout.

◆ plane_window()

EGT_NODISCARD bool plane_window ( ) const

Return the plane_window state of the widget.

◆ point()

EGT_NODISCARD const Point& point ( ) const
inline

Get the origin of the widget's box().

◆ ratio() [1/2]

void ratio ( DefaultDim  ratio)
inline

Set the size ratio relative to parent.

Parameters
[in]ratioHorizontal and vertical ratio parent size, with 100 being 100%.
Note
This is the same as calling ratio(ratio, ratio).

◆ ratio() [2/2]

void ratio ( DefaultDim  horizontal,
DefaultDim  vertical 
)
inline

Set the size ratio relative to parent.

Parameters
[in]horizontalHorizontal ratio of parent width, with 100 being 100%.
[in]verticalVertical ratio of parent height, with 100 being 100%.

◆ readonly() [1/2]

EGT_NODISCARD bool readonly ( ) const
inline

Get the readonly state of the widget.

Returns
true if the widget is readonly.

◆ readonly() [2/2]

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.

Parameters
valueReadonly when true.

◆ readonly_toggle()

void readonly_toggle ( )
inline

Toggle the readonly state.

See also
readonly()

◆ reset_palette()

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().

◆ reset_theme()

void reset_theme ( )

Reset the Widget's Theme to the default Theme.

This is the inverse of setting a custom theme for this widget instance with theme().

See also
Theme

◆ resize()

virtual void resize ( const Size size)
virtual

Resize the widget.

Changes the width and height of the Widget.

Parameters
[in]sizeThe new size of the Widget.
Note
This will cause a redraw of the Widget.

Reimplemented in PieChart, BarChart, PointChart, Frame, VirtualKeyboard, LineChart, Window, VideoWindow, ListBox, ComboBox, and ScrolledView.

◆ resize_by_ratio() [1/2]

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.

Parameters
[in]hratioHorizontal ratio of width(), with 100 being 100%.
[in]vratioVertical ratio of height(), with 100 being 100%.
See also
resize()

◆ resize_by_ratio() [2/2]

void resize_by_ratio ( DefaultDim  ratio)
inline

Scale the current size of the Widget given the ratio.

Parameters
[in]ratioHorizontal and vertical ratio of size(), with 100 being 100%.
See also
resize()

◆ scale() [1/2]

virtual void scale ( float  hscale,
float  vscale 
)
inlinevirtual

Set the scale of the widget.

Parameters
[in]hscaleHorizontal scale, with 1.0 being 100%.
[in]vscaleVertical scale, with 1.0 being 100%.
Warning
This is experimental.

Reimplemented in VideoWindow, CameraWindow, and Window.

◆ scale() [2/2]

void scale ( float  scale)
inline

Set the scale of the widget.

Parameters
[in]scaleVertical and horizontal scale, with 1.0 being 100%.
Warning
This is experimental.

◆ screen()

virtual EGT_NODISCARD Screen* screen ( ) const
virtual

Get a pointer to the Screen instance, using using a parent as necessary.

Returns
An Screen if available, or nullptr.

Reimplemented in Window.

◆ serialize()

virtual void serialize ( Serializer serializer) const
virtual

◆ set_parent()

virtual void set_parent ( Frame parent)
protectedvirtual

Set this widget's parent.

Reimplemented in ComboBox, Button, and Label.

◆ show()

virtual void show ( )
virtual

Show the Widget.

This changes the visible() state of the Widget.

Reimplemented in Frame, and Window.

◆ size()

EGT_NODISCARD const Size& size ( ) const
inline

Get the size of the widget's box().

◆ theme() [1/2]

EGT_NODISCARD const Theme& theme ( ) const

Get the Widget Theme.

If a custom Theme was set for the instance, it will be returned. Otherwise, if this widget has a parent it will walk up the tree looking for a widget that has a Theme set. If no widget is found with a theme, the global_theme() will be returned.

What this means is themes are inherited from widget parents. For example, if you set a custom theme on a egt::TopWindow, all of its children will inherit and use the theme by default.

See also
Theme

◆ theme() [2/2]

void theme ( const Theme theme)

Set the Widget's theme to a new theme.

See also
Theme
Todo:
This does not call Theme::apply() which creates an inconsistency with global_theme().

◆ to_parent() [1/2]

EGT_NODISCARD Point to_parent ( const Point r) const

Convert a point with a local origin to a parent origin.

◆ to_parent() [2/2]

EGT_NODISCARD Rect to_parent ( const Rect r) const
inline

Convert a point in a rect a local origin to a parent origin.

See also
to_parent().

◆ top_level()

virtual EGT_NODISCARD bool top_level ( ) const
inlineprotectedvirtual

Is this widget a top level widget?

Reimplemented in Frame.

◆ type()

virtual EGT_NODISCARD std::string type ( ) const
virtual

Returns a string representation of the type of this widget.

Should this need to be changed, override this function.

Reimplemented in AnalogMeterF, AnalogMeter, LevelMeterF, LevelMeter, SpinProgressF, SliderF, SpinProgress, Slider, ProgressBarF, and ProgressBar.

◆ user_requested_box()

EGT_NODISCARD const Rect& user_requested_box ( ) const
inline

Get the box corresponding to the user requested one, not the actual one.

◆ vertical_ratio() [1/2]

void vertical_ratio ( DefaultDim  vertical)
inline

Set the vertical ratio relative to parent.

Parameters
[in]verticalVertical ratio of parent height, with 100 being 100%.

◆ vertical_ratio() [2/2]

EGT_NODISCARD DefaultDim vertical_ratio ( ) const
inline

Get the vertical ratio relative to parent.

◆ visible() [1/2]

EGT_NODISCARD bool visible ( ) const
inline

Get the visible state of the widget.

Returns
true if the widget is visible.

◆ visible() [2/2]

void visible ( bool  value)

Set the visible state.

◆ visible_toggle()

void visible_toggle ( )
inline

Toggle the visibility state.

See also
show() and hide() and visible()

◆ walk()

virtual void walk ( const WalkCallback callback,
int  level = 0 
)
virtual

Walk the Widget tree and call callback with each Widget.

Parameters
callbackFunction to call for each widget.
levelThe current level of the widget hierarchy starting with the level originally passed in.
widget->walk([](Widget* widget, int level) {
// do something
});

Reimplemented in Frame.

◆ widgetid()

EGT_NODISCARD WidgetId widgetid ( ) const
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.

◆ width() [1/2]

void width ( DefaultDim  w)
inline

Change the width.

Parameters
[in]wThe new width of the Widget.

◆ width() [2/2]

EGT_NODISCARD DefaultDim width ( ) const
inline

Width of the widget's box().

◆ x() [1/2]

void x ( DefaultDim  x)
inline

Set the X coordinate of the box.

Parameters
[in]xThe new origin X value for the widget relative to its parent.

◆ x() [2/2]

EGT_NODISCARD DefaultDim x ( ) const
inline

X coordinate of the widget's box().

◆ xratio() [1/2]

void xratio ( DefaultDim  xratio)
inline

Set the X position ratio relative to parent.

Parameters
[in]xratioX ratio of parent width, with 100 being 100%.

◆ xratio() [2/2]

EGT_NODISCARD DefaultDim xratio ( ) const
inline

Get the X position ratio relative to parent.

◆ y() [1/2]

void y ( DefaultDim  y)
inline

Set the Y coordinate of the box.

Parameters
[in]yThe new origin Y value for the widget relative to its parent.

◆ y() [2/2]

EGT_NODISCARD DefaultDim y ( ) const
inline

Y coordinate of the widget's box().

◆ yratio() [1/2]

void yratio ( DefaultDim  yratio)
inline

Set the Y position ratio relative to parent.

Parameters
[in]yratioY ratio of parent height, with 100 being 100%.

◆ yratio() [2/2]

EGT_NODISCARD DefaultDim yratio ( ) const
inline

Get the Y position ratio relative to parent.

◆ zorder()

virtual EGT_NODISCARD size_t zorder ( ) const
virtual

Get the zorder of the widget.

See also
Z-order

◆ zorder_bottom()

virtual void zorder_bottom ( )
virtual

Move the widget to the bottom.

See also
Z-order

◆ zorder_down()

virtual void zorder_down ( )
virtual

Move this widgets zorder down relative to other widgets with the same parent.

See also
Z-order

◆ zorder_top()

virtual void zorder_top ( )
virtual

Move the widget to the top.

See also
Z-order

◆ zorder_up()

virtual void zorder_up ( )
virtual

Move this widgets zorder up relative to other widgets with the same parent.

See also
Z-order

Friends And Related Function Documentation

◆ Frame

friend class Frame
friend

Member Data Documentation

◆ m_box

Rect m_box
protected

Bounding box.

◆ m_in_layout

bool m_in_layout {false}
protected

Status for whether this widget is currently performing layout.

◆ m_min_size

Size m_min_size
protected

Minimum size of the widget when not an empty value.

◆ m_parent

Frame* m_parent {nullptr}
protected

Pointer to this widget's parent.

The parent is a Frame, which is capable of managing children.

◆ m_user_requested_box

Rect m_user_requested_box
protected

Keep track of the box requested by the user.

◆ m_widgetid

WidgetId m_widgetid {0}
protected

Unique ID of this widget.

◆ on_checked_changed

Signal on_checked_changed

Event signal.

Invoked when the checked state of the widget changes.

◆ on_gain_focus

Signal on_gain_focus

Invoked when the widget gains focus.

◆ on_hide

Signal on_hide

Invoked when a widget is hidden.

◆ on_lost_focus

Signal on_lost_focus

Invoked when the widget loses focus.

◆ on_show

Signal on_show

Invoked when a widget is shown.