guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
guillaume::entities::Button::Builder Class Reference

Configures, creates and registers Button widgets. More...

#include <headers/guillaume/entities/button.hpp>

Inheritance diagram for guillaume::entities::Button::Builder:
Collaboration diagram for guillaume::entities::Button::Builder:

Public Member Functions

 Builder (ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
 Construct a builder with the default configuration (see reset()).
std::shared_ptr< Button > buildEntity (void) override
 Build a Button, with its icon and label children, from the current configuration, without registering it.
void reset (void) override
 Restore the default configuration.
Builder & withIcon (const std::string &iconGlyphName)
 Set the icon shown next to the label.
Builder & withIconStyle (const components::Glyph::Style &iconStyle)
 Set the glyph style of the icon.
Builder & withLabel (const std::string &labelContent)
 Set the label text.
Builder & withOnClick (std::function< void(void)> onClick)
 Set the click handler.
Builder & withToggle (const bool &isToggle)
 Make the button a toggle: each click flips its selected state.
Builder & withColorStyle (const Color &colorStyle)
 Set the color style.
Builder & withShape (const Shape &shape)
 Set the corner shape.
Builder & withSize (const Size &size)
 Set the size.
Builder & withMorph (const bool &isMorph)
 Choose whether a selected toggle button swaps its shape (Round becomes Square and Square becomes Round).
Builder & withDisabled (const bool &isDisabled)
 Choose whether the button starts disabled.
Builder & withTrailingIcon (const bool &isTrailingIcon)
 Choose the side of the icon.
Builder & withAccessibilityLabel (const std::string &accessibilityLabel)
 Set the label read by assistive technology.
std::shared_ptr< Button > makeButton (std::shared_ptr< Entity > parent, const std::string &labelContent, std::function< void(void)> onClick, Color colorStyle, Shape shape, Size size, bool isMorph)
 Build a button with a label and no icon, register it under parent and reset the builder.
std::shared_ptr< Button > makeIconButton (std::shared_ptr< Entity > parent, const std::string &labelContent, const std::string &iconGlyphName, const components::Glyph::Style &iconStyle, std::function< void(void)> onClick, Color colorStyle, Shape shape, Size size, bool isMorph)
 Build a button with an icon and a label, register it under parent and reset the builder.
Public Member Functions inherited from guillaume::entities::EntityBuilderBase< Button >
 EntityBuilderBase (ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
 Construct a builder bound to two registries.
 ~EntityBuilderBase (void) override=default
 Default destructor.
std::shared_ptr< Button > registerEntity (std::shared_ptr< ecs::Entity > parent)
 Build the widget, attach it to its parent, hand it to the entity registry, then reset the builder to its defaults.
Public Member Functions inherited from guillaume::ecs::EntityBuilder
 EntityBuilder (ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
 Create a builder working on a pair of registries, normally those of one scene.
virtual ~EntityBuilder (void)=default
 Virtual destructor.

Additional Inherited Members

Protected Member Functions inherited from guillaume::ecs::EntityBuilder
ComponentRegistry & getComponentRegistry (void)
 Get the registry in which the builder creates components.
EntityRegistry & getEntityRegistry (void)
 Get the registry in which the builder registers the entities it creates.

Detailed Description

Configures, creates and registers Button widgets.

Set options with the with... methods then call registerEntity(), or use makeButton() / makeIconButton() to do both in one call.

Definition at line 96 of file button.hpp.

Constructor & Destructor Documentation

◆ Builder()

guillaume::entities::Button::Builder::Builder ( ecs::ComponentRegistry & componentRegistry,
ecs::EntityRegistry & entityRegistry )

Construct a builder with the default configuration (see reset()).

Parameters
componentRegistryThe registry that stores the components of the buttons to build.
entityRegistryThe registry the built buttons are added to (usually the scene's).

Definition at line 37 of file button.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ buildEntity()

std::shared_ptr< Button > guillaume::entities::Button::Builder::buildEntity ( void )
overridevirtual

Build a Button, with its icon and label children, from the current configuration, without registering it.

registerEntity() calls it, then sets the parent, registers the button and resets the builder.

Returns
The new button.

Implements guillaume::entities::EntityBuilderBase< Button >.

Definition at line 44 of file button.cpp.

Here is the call graph for this function:

◆ makeButton()

std::shared_ptr< Button > guillaume::entities::Button::Builder::makeButton ( std::shared_ptr< Entity > parent,
const std::string & labelContent,
std::function< void(void)> onClick,
Color colorStyle,
Shape shape,
Size size,
bool isMorph )

Build a button with a label and no icon, register it under parent and reset the builder.

Options set before the call with the other with... methods (toggle, disabled, ...) also apply.

Parameters
parentThe entity the button becomes a child of.
labelContentThe text shown in the button.
onClickThe function called when the user clicks the button (may be empty).
colorStyleThe color style.
shapeThe corner shape.
sizeThe size.
isMorphTrue for a toggle button that swaps its shape while selected.
Returns
The new button, registered in the entity registry.

Definition at line 145 of file button.cpp.

Here is the call graph for this function:

◆ makeIconButton()

std::shared_ptr< Button > guillaume::entities::Button::Builder::makeIconButton ( std::shared_ptr< Entity > parent,
const std::string & labelContent,
const std::string & iconGlyphName,
const components::Glyph::Style & iconStyle,
std::function< void(void)> onClick,
Color colorStyle,
Shape shape,
Size size,
bool isMorph )

Build a button with an icon and a label, register it under parent and reset the builder.

Options set before the call with the other with... methods (toggle, trailing icon, ...) also apply. For a button that shows an icon only, see IconButton.

Parameters
parentThe entity the button becomes a child of.
labelContentThe text shown in the button.
iconGlyphNameThe glyph name of the icon.
iconStyleThe glyph style of the icon.
onClickThe function called when the user clicks the button (may be empty).
colorStyleThe color style.
shapeThe corner shape.
sizeThe size.
isMorphTrue for a toggle button that swaps its shape while selected.
Returns
The new button, registered in the entity registry.

Definition at line 159 of file button.cpp.

Here is the call graph for this function:

◆ reset()

void guillaume::entities::Button::Builder::reset ( void )
overridevirtual

Restore the default configuration.

Defaults: no icon, Glyph::Style::Outlined, empty label, no click handler, not a toggle, Color::Text, Shape::Round, Size::Small, no morph, enabled, leading icon, empty accessibility label.

Implements guillaume::ecs::EntityBuilder.

Definition at line 53 of file button.cpp.

Here is the caller graph for this function:

◆ withAccessibilityLabel()

Button::Builder & guillaume::entities::Button::Builder::withAccessibilityLabel ( const std::string & accessibilityLabel)

Set the label read by assistive technology.

Parameters
accessibilityLabelThe accessibility label. Default: empty, in which case the label text is used.
Returns
Reference to the builder for chaining.

Definition at line 138 of file button.cpp.

◆ withColorStyle()

Button::Builder & guillaume::entities::Button::Builder::withColorStyle ( const Color & colorStyle)

Set the color style.

Parameters
colorStyleThe color style. Default: Color::Text.
Returns
Reference to the builder for chaining.

Definition at line 101 of file button.cpp.

◆ withDisabled()

Button::Builder & guillaume::entities::Button::Builder::withDisabled ( const bool & isDisabled)

Choose whether the button starts disabled.

Parameters
isDisabledTrue for a button that ignores input. Default: false.
Returns
Reference to the builder for chaining.

Definition at line 125 of file button.cpp.

Here is the call graph for this function:

◆ withIcon()

Button::Builder & guillaume::entities::Button::Builder::withIcon ( const std::string & iconGlyphName)

Set the icon shown next to the label.

Parameters
iconGlyphNameThe glyph name of the icon (for example "add"). Default: empty, no icon.
Returns
Reference to the builder for chaining.

Definition at line 69 of file button.cpp.

Here is the caller graph for this function:

◆ withIconStyle()

Button::Builder & guillaume::entities::Button::Builder::withIconStyle ( const components::Glyph::Style & iconStyle)

Set the glyph style of the icon.

Parameters
iconStyleThe glyph style. Default: Glyph::Style::Outlined.
Returns
Reference to the builder for chaining.

Definition at line 75 of file button.cpp.

◆ withLabel()

Button::Builder & guillaume::entities::Button::Builder::withLabel ( const std::string & labelContent)

Set the label text.

Parameters
labelContentThe text shown in the button. Default: empty. It is also the accessibility label when none is set.
Returns
Reference to the builder for chaining.

Definition at line 82 of file button.cpp.

Here is the caller graph for this function:

◆ withMorph()

Button::Builder & guillaume::entities::Button::Builder::withMorph ( const bool & isMorph)

Choose whether a selected toggle button swaps its shape (Round becomes Square and Square becomes Round).

Parameters
isMorphTrue to swap the shape while selected. Default: false. It has no effect on a button that is not a toggle.
Returns
Reference to the builder for chaining.

Definition at line 119 of file button.cpp.

◆ withOnClick()

Button::Builder & guillaume::entities::Button::Builder::withOnClick ( std::function< void(void)> onClick)

Set the click handler.

Parameters
onClickThe function called when the user clicks the button. Default: empty, nothing is called.
Returns
Reference to the builder for chaining.

Definition at line 89 of file button.cpp.

◆ withShape()

Button::Builder & guillaume::entities::Button::Builder::withShape ( const Shape & shape)

Set the corner shape.

Parameters
shapeThe corner shape. Default: Shape::Round.
Returns
Reference to the builder for chaining.

Definition at line 107 of file button.cpp.

◆ withSize()

Button::Builder & guillaume::entities::Button::Builder::withSize ( const Size & size)

Set the size.

Parameters
sizeThe size. Default: Size::Small.
Returns
Reference to the builder for chaining.

Definition at line 113 of file button.cpp.

◆ withToggle()

Button::Builder & guillaume::entities::Button::Builder::withToggle ( const bool & isToggle)

Make the button a toggle: each click flips its selected state.

Parameters
isToggleTrue for a toggle button. Default: false.
Returns
Reference to the builder for chaining.

Definition at line 95 of file button.cpp.

◆ withTrailingIcon()

Button::Builder & guillaume::entities::Button::Builder::withTrailingIcon ( const bool & isTrailingIcon)

Choose the side of the icon.

Parameters
isTrailingIconTrue to place the icon after the label, false to place it before. Default: false.
Returns
Reference to the builder for chaining.

Definition at line 132 of file button.cpp.


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