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

A text display widget. More...

#include <label.h>

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

Public Member Functions

 Label ()
 Default constructor.
 
void draw (Context &ctx) override
 Draw the label.
 
void set_text (const std::string &t, bool auto_size=false)
 Set the text, optionally sizing the label to fit it, so layouts such as VBox and Modal give it room.
 
void measure (Context &ctx) override
 Size to the text if set_text asked for it.
 
- Public Member Functions inherited from asw::ui::Widget
 Widget ()
 Default constructor for Widget.
 
virtual ~Widget ()=default
 Default virtual destructor.
 
 Widget (Widget &&other) noexcept
 Move constructor. The children move over and point to the new widget as their parent. The new widget gets its own id and no parent, since it is not in the old parent's children. Removed children stay with the old widget, which is where Root finds and frees them.
 
Widget & operator= (Widget &&other) noexcept
 Move assignment operator. The children move over and point to this widget as their parent. This widget keeps its place in the tree: its parent, id and state. Its old children are removed as by clear_children. Removed children of the other widget stay with it.
 
 Widget (const Widget &)=delete
 
Widget & operator= (const Widget &)=delete
 
WidgetId id () const
 Get the unique identifier for this widget.
 
const std::vector< std::unique_ptr< Widget > > & children () const
 Get the child widgets. Change them with add_child, remove_child and clear_children, which keep removed widgets alive until Root is done with them.
 
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 activate (Context &ctx)
 Called when the widget is clicked, or activated with the keyboard or a controller while focused. Does nothing by default.
 
template<class T , class... Args>
T & add_child (Args &&... args)
 Add a child widget.
 
bool remove_child (const Widget &child)
 Remove a child widget. It leaves the tree now and is destroyed at the next Root::update, so a callback can remove any widget, even the one it runs in.
 
void clear_children ()
 Remove every child widget, destroyed as for remove_child.
 
bool is_hovered () const
 Whether the pointer is currently over this widget.
 
bool is_pressed () const
 Whether this widget is currently being pressed.
 
bool is_focused () const
 Whether this widget currently holds focus.
 
bool is_captured () const
 Whether this widget was pressed and the pointer is still held, even if it has moved off the widget.
 
bool is_highlighted (const Context &ctx) const
 Whether to draw the hover look: hovered, pressed, or focused while focus is shown.
 

Public Attributes

asw::Font font
 The font. Uses the theme font when empty.
 
std::string text
 The text to display.
 
asw::TextJustify justify = asw::TextJustify::Left
 The text justification.
 
std::optional< asw::Color > color
 The text color. Uses the theme text color when empty.
 
- 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. Focusable widgets are also the ones the pointer can press.
 
Widget * nav_up = nullptr
 Widget to focus on up, instead of the nearest one. Optional.
 
Widget * nav_down = nullptr
 Widget to focus on down, instead of the nearest one. Optional.
 
Widget * nav_left = nullptr
 Widget to focus on left, instead of the nearest one. Optional.
 
Widget * nav_right = nullptr
 Widget to focus on right, instead of the nearest one. Optional.
 
bool focus_ring = true
 Draw the theme focus ring around this widget while it has visible focus. Turn off for widgets that show focus themselves.
 
Widget * parent = nullptr
 Pointer to the parent widget.
 
asw::Quad< float > transform
 The transform (position and size) of the widget.
 
Anchor anchor = Anchor::None
 Pin this widget to a point of its parent, e.g. BottomRight for a corner button. The parent places it on every layout, so it stays in place when the screen or its own size changes. Stack and Grid place their children themselves and ignore it.
 
asw::Vec2< float > anchor_margin { 0.0F, 0.0F }
 Space between an anchored widget and the parent's edges.
 

Private Attributes

bool _fit_text = false
 

Additional Inherited Members

- Protected Member Functions inherited from asw::ui::Widget
void place_anchored (Widget &child) const
 Place a child that has an anchor inside this widget.
 
- Protected Attributes inherited from asw::ui::Widget
bool _hovered = false
 
bool _pressed = false
 
bool _focused = false
 
bool _captured = false
 

Detailed Description

A text display widget.

Definition at line 23 of file label.h.

Constructor & Destructor Documentation

◆ Label()

asw::ui::Label::Label ( )
inline

Default constructor.

Definition at line 27 of file label.h.

Member Function Documentation

◆ draw()

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

Draw the label.

Parameters
ctxThe UI context.

Reimplemented from asw::ui::Widget.

Definition at line 21 of file label.cpp.

◆ measure()

void asw::ui::Label::measure ( Context & ctx)
overridevirtual

Size to the text if set_text asked for it.

Parameters
ctxThe UI context.

Reimplemented from asw::ui::Widget.

Definition at line 12 of file label.cpp.

◆ set_text()

void asw::ui::Label::set_text ( const std::string & t,
bool auto_size = false )

Set the text, optionally sizing the label to fit it, so layouts such as VBox and Modal give it room.

Parameters
tThe text to set.
auto_sizeIf true, the label is sized to its text when measured.

Definition at line 6 of file label.cpp.

Member Data Documentation

◆ _fit_text

bool asw::ui::Label::_fit_text = false
private

Definition at line 65 of file label.h.

◆ color

std::optional<asw::Color> asw::ui::Label::color

The text color. Uses the theme text color when empty.

Definition at line 62 of file label.h.

◆ font

asw::Font asw::ui::Label::font

The font. Uses the theme font when empty.

Definition at line 53 of file label.h.

◆ justify

asw::TextJustify asw::ui::Label::justify = asw::TextJustify::Left

The text justification.

Definition at line 59 of file label.h.

◆ text

std::string asw::ui::Label::text

The text to display.

Definition at line 56 of file label.h.


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