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::Button Class Reference

An interactive button widget. More...

#include <button.h>

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

Public Member Functions

 Button ()
 Default constructor.
 
void on_focus_changed (Context &ctx, bool focused) override
 Called when focus state changes.
 
bool on_event (Context &ctx, const UIEvent &e) override
 Handle a UI event.
 
void draw (Context &ctx) override
 Draw the button.
 
- Public Member Functions inherited from asw::ui::Widget
 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.
 
template<class T , class... Args>
T & add_child (Args &&... args)
 Add a child widget.
 

Public Attributes

std::function< void()> on_click
 Callback invoked when the button is clicked.
 
asw::Font font
 The font to use for the button text.
 
std::string text
 The button text.
 
- Public Attributes inherited from asw::ui::Widget
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.
 

Private Attributes

bool hovered_ = false
 
bool pressed_ = false
 
bool focused_ = false
 

Detailed Description

An interactive button widget.

Definition at line 23 of file button.h.

Constructor & Destructor Documentation

◆ Button()

asw::ui::Button::Button ( )
inline

Default constructor.

Definition at line 27 of file button.h.

Member Function Documentation

◆ draw()

void asw::ui::Button::draw ( Context & ctx)
overridevirtual

Draw the button.

Parameters
ctxThe UI context.

Reimplemented from asw::ui::Widget.

Definition at line 67 of file button.cpp.

◆ on_event()

bool asw::ui::Button::on_event ( Context & ctx,
const UIEvent & e )
overridevirtual

Handle a UI event.

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

Reimplemented from asw::ui::Widget.

Definition at line 12 of file button.cpp.

◆ on_focus_changed()

void asw::ui::Button::on_focus_changed ( Context & ctx,
bool focused )
overridevirtual

Called when focus state changes.

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

Reimplemented from asw::ui::Widget.

Definition at line 6 of file button.cpp.

Member Data Documentation

◆ focused_

bool asw::ui::Button::focused_ = false
private

Definition at line 65 of file button.h.

◆ font

asw::Font asw::ui::Button::font

The font to use for the button text.

Definition at line 57 of file button.h.

◆ hovered_

bool asw::ui::Button::hovered_ = false
private

Definition at line 63 of file button.h.

◆ on_click

std::function<void()> asw::ui::Button::on_click

Callback invoked when the button is clicked.

Definition at line 33 of file button.h.

◆ pressed_

bool asw::ui::Button::pressed_ = false
private

Definition at line 64 of file button.h.

◆ text

std::string asw::ui::Button::text

The button text.

Definition at line 60 of file button.h.


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