ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
asw::ui::Widget Class Reference

Base class for all UI widgets. More...

#include <widget.h>

Inheritance diagram for asw::ui::Widget:
[legend]
Collaboration diagram for asw::ui::Widget:
[legend]

Public Member Functions

 Widget ()
 Default constructor for Widget.
 
virtual ~Widget ()=default
 Default virtual destructor.
 
 Widget (Widget &&)=default
 Move constructor.
 
Widgetoperator= (Widget &&)=default
 Move assignment operator.
 
 Widget (const Widget &)=delete
 
Widgetoperator= (const Widget &)=delete
 
WidgetId id () const
 Get the unique identifier for this widget.
 
virtual void layout (Context &ctx)
 Lay out this widget and its children.
 
virtual bool on_event (Context &ctx, const UIEvent &e)
 Handle a UI event.
 
virtual void on_focus_changed (Context &ctx, bool focused)
 Called when focus state changes.
 
virtual void draw (Context &ctx)
 Draw this widget and its children.
 
template<class T , class... Args>
T & add_child (Args &&... args)
 Add a child widget.
 

Public Attributes

bool visible = true
 Whether the widget is visible.
 
bool enabled = true
 Whether the widget is enabled.
 
bool focusable = false
 Whether the widget can receive focus.
 
Widgetparent = nullptr
 Pointer to the parent widget.
 
std::vector< std::unique_ptr< Widget > > children
 Child widgets.
 
asw::Quad< float > transform
 The transform (position and size) of the widget.
 

Static Private Member Functions

static int generate_id ()
 

Private Attributes

WidgetId id_
 

Static Private Attributes

static int id_counter_ { 1 }
 

Detailed Description

Base class for all UI widgets.

Definition at line 28 of file widget.h.

Constructor & Destructor Documentation

◆ Widget() [1/3]

asw::ui::Widget::Widget ( )
inline

Default constructor for Widget.

Definition at line 32 of file widget.h.

◆ ~Widget()

virtual asw::ui::Widget::~Widget ( )
virtualdefault

Default virtual destructor.

◆ Widget() [2/3]

asw::ui::Widget::Widget ( Widget && )
default

Move constructor.

◆ Widget() [3/3]

asw::ui::Widget::Widget ( const Widget & )
delete

Member Function Documentation

◆ add_child()

template<class T , class... Args>
T & asw::ui::Widget::add_child ( Args &&... args)
inline

Add a child widget.

Template Parameters
TThe type of widget to add. Must derive from Widget.
ArgsConstructor argument types.
Parameters
argsConstructor arguments forwarded to T.
Returns
A reference to the newly added child widget.

Definition at line 108 of file widget.h.

◆ draw()

void asw::ui::Widget::draw ( Context & ctx)
virtual

Draw this widget and its children.

Parameters
ctxThe UI context.

Reimplemented in asw::ui::Button, asw::ui::InputBox, asw::ui::Label, and asw::ui::Panel.

Definition at line 26 of file widget.cpp.

◆ generate_id()

static int asw::ui::Widget::generate_id ( )
inlinestaticprivate

Definition at line 124 of file widget.h.

◆ id()

WidgetId asw::ui::Widget::id ( ) const
inline

Get the unique identifier for this widget.

Returns
The widget's unique identifier.

Definition at line 54 of file widget.h.

◆ layout()

void asw::ui::Widget::layout ( Context & ctx)
virtual

Lay out this widget and its children.

Parameters
ctxThe UI context.

Reimplemented in asw::ui::VBox.

Definition at line 5 of file widget.cpp.

◆ on_event()

bool asw::ui::Widget::on_event ( Context & ctx,
const UIEvent & e )
virtual

Handle a UI event.

Parameters
ctxThe UI context.
eThe event to handle.
Returns
True if the event was handled.

Reimplemented in asw::ui::Button, and asw::ui::InputBox.

Definition at line 13 of file widget.cpp.

◆ on_focus_changed()

void asw::ui::Widget::on_focus_changed ( Context & ctx,
bool focused )
virtual

Called when focus state changes.

Parameters
ctxThe UI context.
focusedWhether the widget is now focused.

Reimplemented in asw::ui::Button, and asw::ui::InputBox.

Definition at line 20 of file widget.cpp.

◆ operator=() [1/2]

Widget & asw::ui::Widget::operator= ( const Widget & )
delete

◆ operator=() [2/2]

Widget & asw::ui::Widget::operator= ( Widget && )
default

Move assignment operator.

Member Data Documentation

◆ children

std::vector<std::unique_ptr<Widget> > asw::ui::Widget::children

Child widgets.

Definition at line 72 of file widget.h.

◆ enabled

bool asw::ui::Widget::enabled = true

Whether the widget is enabled.

Definition at line 63 of file widget.h.

◆ focusable

bool asw::ui::Widget::focusable = false

Whether the widget can receive focus.

Definition at line 66 of file widget.h.

◆ id_

WidgetId asw::ui::Widget::id_
private

Definition at line 129 of file widget.h.

◆ id_counter_

int asw::ui::Widget::id_counter_ { 1 }
inlinestaticprivate

Definition at line 122 of file widget.h.

◆ parent

Widget* asw::ui::Widget::parent = nullptr

Pointer to the parent widget.

Definition at line 69 of file widget.h.

◆ transform

asw::Quad<float> asw::ui::Widget::transform

The transform (position and size) of the widget.

Definition at line 119 of file widget.h.

◆ visible

bool asw::ui::Widget::visible = true

Whether the widget is visible.

Definition at line 60 of file widget.h.


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