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

A row of joined toggle buttons (segments) from which the user picks one option, or several. More...

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

Inheritance diagram for guillaume::entities::SegmentedButton:
Collaboration diagram for guillaume::entities::SegmentedButton:

Classes

class  Builder
 Configures, creates and registers SegmentedButton widgets. More...

Public Types

using SelectionMode = components::SegmentedButton::SelectionMode
using Segment = components::SegmentedButton::Segment
Public Types inherited from guillaume::ecs::Entity
using Identifier = std::size_t
 The key under which an entity's components are stored. Systems and components refer to entities by this value.
using Signature = std::bitset<128>
 A set of component types, one bit per type (bit position given by ComponentTypeId, MaxComponentTypes bits).

Public Member Functions

SegmentedButton & setSegmentDisabled (std::size_t index, bool disabled)
 Enable or disable one segment. Restyles at once.
 ~SegmentedButton (void)
 Destructor.
SegmentedButton & select (std::size_t index)
 Select a segment. Restyles at once.
SegmentedButton & deselect (std::size_t index)
 Deselect a segment. Restyles at once.
bool isSelected (std::size_t index) const
 Get whether a segment is selected.
std::vector< std::size_t > getSelectedIndices (void) const
 Get the indices of all selected segments.
std::size_t getSegmentCount (void) const
 Get the number of segments.
ecs::Entity::Identifier getSegmentIdentifier (std::size_t index) const
 Get the identifier of the Button child of one segment.
Public Member Functions inherited from guillaume::ecs::ParentEntityFiller< components::Transform, components::Bound, components::Layout, components::SegmentedButton >
 ParentEntityFiller (ComponentRegistry &componentRegistry)
 Create the entity, its listed components and its components::Hierarchy. It owns no child yet.
virtual ~ParentEntityFiller (void)=default
 Destroy the entity object and release the children it owns; components stay in the registry (see EntityRegistry::removeEntity).
Public Member Functions inherited from guillaume::ecs::Entity
 Entity (void)
 Create an entity with a fresh identifier, an empty signature, no parent and no component.
virtual ~Entity (void)=default
 Destroy the entity object.
Entity::Identifier getIdentifier (void) const noexcept
 Get the identifier of the entity.
Entity::Signature getSignature (void) const noexcept
 Get the set of component types the entity declares.
void setSignature (const Signature &signature)
 Replace the signature of the entity.
std::int32_t getLayer (void) const noexcept
 Get the depth of the entity in the tree.
Entity & setParent (std::shared_ptr< Entity > parent)
 Attach the entity under another one, or detach it.
std::vector< Identifier > releaseComponents (void)
 Drop the entity's place in the tree and all its components.
std::shared_ptr< Entity > getParent (void) const noexcept
 Get the parent entity.
Public Member Functions inherited from guillaume::ecs::EntityRegistry
 EntityRegistry (void)=default
 Create a registry.
virtual ~EntityRegistry (void)=default
 Virtual destructor.
void addEntity (std::shared_ptr< Entity > entity)
 Make this registry own an entity, so that it stays alive and systems visit it.
bool removeEntity (Entity::Identifier identifier)
 Remove an entity, with its children and all their components.
void clearEntities (void)
 Remove every entity owned by this registry, with everything they own and all their components.
const std::vector< std::shared_ptr< Entity > > & getEntities (void) const
 Get the entities this registry owns directly.
std::vector< std::shared_ptr< Entity > > getEntitiesBreadthFirst (void)
 List every entity of this registry and of the registries nested in it, level by level.
std::vector< std::shared_ptr< Entity > > getEntitiesBreadthFirst (void) const
 List every entity of this registry and of the registries nested in it, level by level (const overload).
template<InheritFromEntity EntityType>
std::shared_ptr< EntityType > getEntity (Entity::Identifier identifier)
 Find an entity owned directly by this registry, by identifier.
template<InheritFromEntity EntityType>
std::shared_ptr< const EntityType > getEntity (Entity::Identifier identifier) const
 Find an entity owned directly by this registry, by identifier (const overload).
std::vector< Entity::Identifier > getEntityWithSignature (Entity::Signature systemSignature) const
 List the entities that have every component type of a signature, from the root down.
std::vector< Entity::Identifier > getEntityWithSignature (Entity::Signature systemSignature, const EntityTreeTraveler &traveler) const
 List the entities that have every component type of a signature, in the order chosen by a traveler.

Static Public Member Functions

template<typename... Arguments>
static std::shared_ptr< SegmentedButton > create (Arguments &&...arguments)
 Create a segmented button and one button per segment, without registering it in an entity registry.
Static Public Member Functions inherited from guillaume::ecs::Entity
template<InheritFromComponent... ComponentTypes>
static Signature getSignatureFromTypes (void)
 Build the signature that has exactly the bits of the given component types.

Static Public Attributes

static constexpr float MinSegmentWidth
 Minimum width of a segment, in dp (Paper SegmentedButtons: 76 dp).
Static Public Attributes inherited from guillaume::ecs::Entity
static constexpr Identifier InvalidIdentifier
 "No entity": never the identifier of a real entity

Additional Inherited Members

Protected Member Functions inherited from guillaume::ecs::ParentEntityFiller< components::Transform, components::Bound, components::Layout, components::SegmentedButton >
ComponentRegistry & getComponentRegistry (void)
 Get the registry that stores this entity's components.
Protected Member Functions inherited from guillaume::ecs::ParentEntity
std::vector< std::shared_ptr< Entity > > & accessDirectEntities (void) override
 Give access to the list of entities this entity owns directly.
const std::vector< std::shared_ptr< Entity > > & accessDirectEntities (void) const override
 Give read access to the list of entities this entity owns directly.
Protected Member Functions inherited from guillaume::ecs::Entity
void attachHierarchy (ComponentRegistry &componentRegistry)
 Give the entity a components::Hierarchy in a registry and add that component to its signature.
template<InheritFromComponent... ComponentTypes>
void setSignature (void)
 Replace the signature by the one made of the given component types.

Detailed Description

A row of joined toggle buttons (segments) from which the user picks one option, or several.

Its state lives in components::SegmentedButton (segment options, selection mode, callback, child identifiers). Each segment is a Button child, and whether a segment is selected is the selection of that button. systems::SegmentedButton gives a selected segment a check icon, gives every segment the same width, fills the row and joins the corners each frame, in the Layout phase. The class itself holds no field: its methods call the system.

getEntityRegistry());
auto view = builder.makeSegmentedButton(parent,
{ "Day", "Week", "Month" }, SegmentedButton::SelectionMode::Single,
[](std::size_t index) {
// called when the user presses the segment at index
});
view->select(0);
Configures, creates and registers SegmentedButton widgets.

SegmentedButton::create(registry, labels, selectionMode, onChange), or the same call with a std::vector<Segment> in place of the labels, builds the same widget without registering it in an entity registry.

The segmented button owns its segment buttons: it is the entity registry they are registered in. The segments are fixed at creation and none is selected at first. select() and deselect() do not call the change handler; only a user press does. The click handler, the minimum width and the corners of the segment buttons, and the Layout configuration of the row, are set by the system; do not replace them.

See also
components::SegmentedButton, systems::SegmentedButton, Button

Definition at line 85 of file segmented_button.hpp.

Member Typedef Documentation

◆ Segment

Options of one segment: label, icon, disabled flag and accessibility label (Paper buttons[] entry).

Definition at line 98 of file segmented_button.hpp.

◆ SelectionMode

Constructor & Destructor Documentation

◆ ~SegmentedButton()

guillaume::entities::SegmentedButton::~SegmentedButton ( void )

Destructor.

Definition at line 156 of file segmented_button.cpp.

Member Function Documentation

◆ create()

template<typename... Arguments>
std::shared_ptr< SegmentedButton > guillaume::entities::SegmentedButton::create ( Arguments &&... arguments)
inlinestatic

Create a segmented button and one button per segment, without registering it in an entity registry.

The constructors are private because the segment buttons need a parent already held by a std::shared_ptr: create() constructs the segmented button then calls build(), which creates them.

Template Parameters
ArgumentsThe types of the constructor arguments.
Parameters
argumentsThe arguments forwarded to a constructor: (registry, labels, selectionMode, onChange) with labels a std::vector<std::string>, or (registry, segments, selectionMode, onChange) with segments a std::vector<Segment>.
Returns
The new segmented button, with no segment selected.

Definition at line 247 of file segmented_button.hpp.

Here is the caller graph for this function:

◆ deselect()

SegmentedButton & guillaume::entities::SegmentedButton::deselect ( std::size_t index)

Deselect a segment. Restyles at once.

The change handler is not called.

Parameters
indexThe index of the segment to deselect (0 is the first). Nothing happens when it is out of range.
Returns
Reference to this segmented button for chaining.

Definition at line 167 of file segmented_button.cpp.

Here is the call graph for this function:

◆ getSegmentCount()

std::size_t guillaume::entities::SegmentedButton::getSegmentCount ( void ) const

Get the number of segments.

Returns
The number of segment buttons.

Definition at line 186 of file segmented_button.cpp.

Here is the call graph for this function:

◆ getSegmentIdentifier()

ecs::Entity::Identifier guillaume::entities::SegmentedButton::getSegmentIdentifier ( std::size_t index) const

Get the identifier of the Button child of one segment.

Parameters
indexThe index of the segment (0 is the first).
Returns
The identifier of the segment button, or ecs::Entity::InvalidIdentifier when index is out of range.

Definition at line 195 of file segmented_button.cpp.

Here is the call graph for this function:

◆ getSelectedIndices()

std::vector< std::size_t > guillaume::entities::SegmentedButton::getSelectedIndices ( void ) const

Get the indices of all selected segments.

Returns
The indices in ascending order; empty when no segment is selected. At most one index in single selection mode.

Definition at line 180 of file segmented_button.cpp.

Here is the call graph for this function:

◆ isSelected()

bool guillaume::entities::SegmentedButton::isSelected ( std::size_t index) const

Get whether a segment is selected.

Parameters
indexThe index of the segment (0 is the first).
Returns
True when the segment is selected, false when it is not or when index is out of range.

Definition at line 174 of file segmented_button.cpp.

Here is the call graph for this function:

◆ select()

SegmentedButton & guillaume::entities::SegmentedButton::select ( std::size_t index)

Select a segment. Restyles at once.

In single selection mode the other segments are deselected. The change handler is not called.

Parameters
indexThe index of the segment to select (0 is the first). Nothing happens when it is out of range.
Returns
Reference to this segmented button for chaining.

Definition at line 160 of file segmented_button.cpp.

Here is the call graph for this function:

◆ setSegmentDisabled()

SegmentedButton & guillaume::entities::SegmentedButton::setSegmentDisabled ( std::size_t index,
bool disabled )

Enable or disable one segment. Restyles at once.

A disabled segment ignores input and keeps its selection.

Parameters
indexThe index of the segment (0 is the first). Nothing happens when it is out of range.
disabledTrue to disable the segment, false to enable it.
Returns
Reference to this segmented button for chaining.

Definition at line 148 of file segmented_button.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ MinSegmentWidth

float guillaume::entities::SegmentedButton::MinSegmentWidth
staticconstexpr
Initial value:
=
static constexpr float MinSegmentWidth
Minimum width of a segment, in dp.

Minimum width of a segment, in dp (Paper SegmentedButtons: 76 dp).

Definition at line 104 of file segmented_button.hpp.


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