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

Configuration of a chip: a compact pill with a label and optional leading, check and close icons. More...

#include <headers/guillaume/components/chip.hpp>

Inheritance diagram for guillaume::components::Chip:
Collaboration diagram for guillaume::components::Chip:

Public Types

enum class  Variant { Assist , Filter , Input , Suggestion }
 Kind of chip. More...
enum class  Mode { Flat , Outlined }
 Container style: Flat is filled with the secondary container color; Outlined is transparent with an outline until selected, where it is filled too. More...
using Handler = std::function<void(void)>
 Callback run when the chip, or its close icon, is activated.

Public Member Functions

 Chip (void)=default
 Create the configuration of a flat Assist chip with no label.
 ~Chip (void)=default
 Default destructor.
Variant getVariant (void) const noexcept
 Get the kind of chip.
Chip & setVariant (Variant variant)
 Choose the kind of chip.
Mode getMode (void) const noexcept
 Get the container style.
Chip & setMode (Mode mode)
 Choose the container style.
const std::string & getLabel (void) const noexcept
 Get the label text.
Chip & setLabel (const std::string &label)
 Set the label text.
const std::string & getIconGlyph (void) const noexcept
 Get the name of the leading icon glyph.
Chip & setIconGlyph (const std::string &iconGlyph)
 Set the name of the leading icon glyph.
ecs::Entity::Identifier getLeadingIcon (void) const noexcept
 Get the child entity that draws the leading icon.
Chip & setLeadingIcon (ecs::Entity::Identifier identifier)
 Record which child entity draws the leading icon.
ecs::Entity::Identifier getTrailingIcon (void) const noexcept
 Get the child entity that draws the trailing close icon.
Chip & setTrailingIcon (ecs::Entity::Identifier identifier)
 Record which child entity draws the trailing close icon.
ecs::Entity::Identifier getLabelEntity (void) const noexcept
 Get the child entity that draws the label.
Chip & setLabelEntity (ecs::Entity::Identifier identifier)
 Record which child entity draws the label.
ecs::Entity::Identifier getCheckIcon (void) const noexcept
 Get the child entity that draws the selected check.
Chip & setCheckIcon (ecs::Entity::Identifier identifier)
 Record which child entity draws the selected check.
bool isCompact (void) const noexcept
 Check whether the chip uses the compact padding.
Chip & setCompact (bool compact)
 Choose between the regular and the compact padding.
bool isElevated (void) const noexcept
 Check whether the chip casts a shadow.
Chip & setElevated (bool elevated)
 Choose whether the chip casts a shadow.
bool isShowSelectedOverlay (void) const noexcept
 Check whether a selected chip is darkened by a state layer.
Chip & setShowSelectedOverlay (bool show)
 Choose whether a selected chip is darkened by a state layer.
bool isShowSelectedCheck (void) const noexcept
 Check whether a selected chip shows its check.
Chip & setShowSelectedCheck (bool show)
 Choose whether a selected chip shows its check.
const Handler & getOnPress (void) const noexcept
 Get the callback run when the chip is pressed.
Chip & setOnPress (Handler handler)
 Set the callback run when the chip is pressed.
const Handler & getOnClose (void) const noexcept
 Get the callback run when the close icon is pressed.
Chip & setOnClose (Handler handler)
 Set the callback run when the close icon is pressed.
Public Member Functions inherited from guillaume::ecs::Component
bool hasChanged (void) const
 Tell whether a value of the component changed since the flags were last reset (the end of the previous frame).
void setHasChanged (bool hasChanged)
 Raise or lower the changed flag.
 Component (void)=default
 Create a component that is not marked as changed.
virtual ~Component (void)=default
 Virtual destructor, so components can be destroyed through the base class.

Static Public Attributes

static constexpr const char * DefaultAssistGlyph = "event"
 Glyph of the leading icon of an Assist chip without one.
static constexpr const char * CheckGlyph = "check"
 Glyph of the selected check.
static constexpr const char * CloseGlyph = "close"
 Glyph of the trailing close icon.
static constexpr float IconSize = 18.0f
 Font size of the icons, in dp.
static constexpr float Padding = 12.0f
 Padding around the content, in dp.
static constexpr float CompactPadding = 8.0f
 Padding around the content of a compact chip, in dp.

Detailed Description

Configuration of a chip: a compact pill with a label and optional leading, check and close icons.

It holds the variant, the mode, the label, the icon glyph, the look options, the callbacks and the identifiers of the chip's children. Two pieces of state live in other components of the same entity: whether the chip is selected (components::Selectable) and whether it is enabled (components::StyleState).

Role in the frame:

  • entities::Chip writes the configuration, creates the children the variant needs and records their identifiers here.
  • systems::Chip (Layout phase) reads it and writes the chip's Color, Borders, Elevation, Layout padding and Accessibility, colors the children, copies the label to the label child and hands the Layout system the children to arrange in a row (the check takes the place of the leading icon while it is shown).

To select or disable a chip from code call systems::Chip::setSelected() or systems::Chip::setDisabled(). Every setter here except setOnPress() and setOnClose() compares before writing and marks the component changed only when the value differs.

See also
systems::Chip, components::Selectable, components::StyleState

Definition at line 59 of file chip.hpp.

Member Typedef Documentation

◆ Handler

using guillaume::components::Chip::Handler = std::function<void(void)>

Callback run when the chip, or its close icon, is activated.

Definition at line 80 of file chip.hpp.

Member Enumeration Documentation

◆ Mode

Container style: Flat is filled with the secondary container color; Outlined is transparent with an outline until selected, where it is filled too.

Definition at line 77 of file chip.hpp.

◆ Variant

Kind of chip.

Assist: an action; it shows DefaultAssistGlyph when it has no icon glyph. Filter: a press toggles its selection, and it has a check icon. Input: a piece of entered information; it has a close icon. Suggestion: a plain proposal.

Definition at line 70 of file chip.hpp.

Member Function Documentation

◆ getCheckIcon()

ecs::Entity::Identifier guillaume::components::Chip::getCheckIcon ( void ) const
noexcept

Get the child entity that draws the selected check.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the chip has none.

Definition at line 127 of file chip.cpp.

◆ getIconGlyph()

const std::string & guillaume::components::Chip::getIconGlyph ( void ) const
noexcept

Get the name of the leading icon glyph.

Returns
The glyph name as set, empty when none was given. Use systems::Chip::leadingGlyph() for the glyph really shown.

Definition at line 71 of file chip.cpp.

Here is the caller graph for this function:

◆ getLabel()

const std::string & guillaume::components::Chip::getLabel ( void ) const
noexcept

Get the label text.

Returns
The text.

Definition at line 57 of file chip.cpp.

◆ getLabelEntity()

ecs::Entity::Identifier guillaume::components::Chip::getLabelEntity ( void ) const
noexcept

Get the child entity that draws the label.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the chip has none.

Definition at line 113 of file chip.cpp.

◆ getLeadingIcon()

ecs::Entity::Identifier guillaume::components::Chip::getLeadingIcon ( void ) const
noexcept

Get the child entity that draws the leading icon.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the chip has none.

Definition at line 85 of file chip.cpp.

◆ getMode()

Chip::Mode guillaume::components::Chip::getMode ( void ) const
noexcept

Get the container style.

Returns
Flat (the default) or Outlined.

Definition at line 43 of file chip.cpp.

◆ getOnClose()

const Chip::Handler & guillaume::components::Chip::getOnClose ( void ) const
noexcept

Get the callback run when the close icon is pressed.

Returns
The callback, empty when none is set.

Definition at line 208 of file chip.cpp.

◆ getOnPress()

const Chip::Handler & guillaume::components::Chip::getOnPress ( void ) const
noexcept

Get the callback run when the chip is pressed.

Returns
The callback, empty when none is set.

Definition at line 197 of file chip.cpp.

Here is the caller graph for this function:

◆ getTrailingIcon()

ecs::Entity::Identifier guillaume::components::Chip::getTrailingIcon ( void ) const
noexcept

Get the child entity that draws the trailing close icon.

Returns
Its identifier, or ecs::Entity::InvalidIdentifier when the chip has none.

Definition at line 99 of file chip.cpp.

◆ getVariant()

Chip::Variant guillaume::components::Chip::getVariant ( void ) const
noexcept

Get the kind of chip.

Returns
The variant (Assist by default).

Definition at line 29 of file chip.cpp.

Here is the caller graph for this function:

◆ isCompact()

bool guillaume::components::Chip::isCompact ( void ) const
noexcept

Check whether the chip uses the compact padding.

Returns
True when the padding is CompactPadding instead of Padding.

Definition at line 141 of file chip.cpp.

◆ isElevated()

bool guillaume::components::Chip::isElevated ( void ) const
noexcept

Check whether the chip casts a shadow.

Returns
True when an enabled chip is drawn at elevation level 1.

Definition at line 155 of file chip.cpp.

◆ isShowSelectedCheck()

bool guillaume::components::Chip::isShowSelectedCheck ( void ) const
noexcept

Check whether a selected chip shows its check.

Returns
True when the check is shown while selected (the default).

Definition at line 183 of file chip.cpp.

◆ isShowSelectedOverlay()

bool guillaume::components::Chip::isShowSelectedOverlay ( void ) const
noexcept

Check whether a selected chip is darkened by a state layer.

Returns
True when the layer is drawn while selected.

Definition at line 169 of file chip.cpp.

◆ setCheckIcon()

Chip & guillaume::components::Chip::setCheckIcon ( ecs::Entity::Identifier identifier)

Record which child entity draws the selected check.

Parameters
identifierThe check child, or ecs::Entity::InvalidIdentifier for none.
Returns
This component, for chaining.

Definition at line 132 of file chip.cpp.

Here is the call graph for this function:

◆ setCompact()

Chip & guillaume::components::Chip::setCompact ( bool compact)

Choose between the regular and the compact padding.

Parameters
compactTrue for CompactPadding (8 dp), false for Padding (12 dp).
Returns
This component, for chaining.

Definition at line 146 of file chip.cpp.

Here is the call graph for this function:

◆ setElevated()

Chip & guillaume::components::Chip::setElevated ( bool elevated)

Choose whether the chip casts a shadow.

Parameters
elevatedTrue for elevation level 1 while enabled, false for no shadow.
Returns
This component, for chaining.

Definition at line 160 of file chip.cpp.

Here is the call graph for this function:

◆ setIconGlyph()

Chip & guillaume::components::Chip::setIconGlyph ( const std::string & iconGlyph)

Set the name of the leading icon glyph.

Parameters
iconGlyphThe glyph name in the icon font, or an empty string for none (an Assist chip then shows DefaultAssistGlyph).
Returns
This component, for chaining.

Definition at line 76 of file chip.cpp.

Here is the call graph for this function:

◆ setLabel()

Chip & guillaume::components::Chip::setLabel ( const std::string & label)

Set the label text.

The system copies it to the label child's Text and to the chip's Accessibility label.

Parameters
labelThe label text.
Returns
This component, for chaining.

Definition at line 62 of file chip.cpp.

Here is the call graph for this function:

◆ setLabelEntity()

Chip & guillaume::components::Chip::setLabelEntity ( ecs::Entity::Identifier identifier)

Record which child entity draws the label.

Parameters
identifierThe label child, or ecs::Entity::InvalidIdentifier for none.
Returns
This component, for chaining.

Definition at line 118 of file chip.cpp.

Here is the call graph for this function:

◆ setLeadingIcon()

Chip & guillaume::components::Chip::setLeadingIcon ( ecs::Entity::Identifier identifier)

Record which child entity draws the leading icon.

Parameters
identifierThe leading icon child, or ecs::Entity::InvalidIdentifier for none.
Returns
This component, for chaining.

Definition at line 90 of file chip.cpp.

Here is the call graph for this function:

◆ setMode()

Chip & guillaume::components::Chip::setMode ( Mode mode)

Choose the container style.

Parameters
modeFlat for a filled chip, Outlined for a transparent chip with an outline.
Returns
This component, for chaining.

Definition at line 48 of file chip.cpp.

Here is the call graph for this function:

◆ setOnClose()

Chip & guillaume::components::Chip::setOnClose ( Handler handler)

Set the callback run when the close icon is pressed.

A chip of any variant with a close callback needs a close icon (systems::Chip::needsCloseIcon()). The chip is not removed for you: do it in the callback. Does not mark the component changed.

Parameters
handlerThe callback, or an empty one to remove it.
Returns
This component, for chaining.

Definition at line 213 of file chip.cpp.

Here is the call graph for this function:

◆ setOnPress()

Chip & guillaume::components::Chip::setOnPress ( Handler handler)

Set the callback run when the chip is pressed.

It runs on every press of an enabled chip, after a Filter chip toggled its selection. Does not mark the component changed.

Parameters
handlerThe callback, or an empty one to remove it.
Returns
This component, for chaining.

Definition at line 202 of file chip.cpp.

Here is the call graph for this function:

◆ setShowSelectedCheck()

Chip & guillaume::components::Chip::setShowSelectedCheck ( bool show)

Choose whether a selected chip shows its check.

Parameters
showTrue so that, while selected, the check child takes the place of the leading icon; false to keep the leading icon.
Returns
This component, for chaining.

Definition at line 188 of file chip.cpp.

Here is the call graph for this function:

◆ setShowSelectedOverlay()

Chip & guillaume::components::Chip::setShowSelectedOverlay ( bool show)

Choose whether a selected chip is darkened by a state layer.

Parameters
showTrue to blend the pressed state layer over the container while the chip is selected and enabled.
Returns
This component, for chaining.

Definition at line 174 of file chip.cpp.

Here is the call graph for this function:

◆ setTrailingIcon()

Chip & guillaume::components::Chip::setTrailingIcon ( ecs::Entity::Identifier identifier)

Record which child entity draws the trailing close icon.

systems::Chip::installCloseIcon() then makes that child run the close callback when pressed.

Parameters
identifierThe close icon child, or ecs::Entity::InvalidIdentifier for none.
Returns
This component, for chaining.

Definition at line 104 of file chip.cpp.

Here is the call graph for this function:

◆ setVariant()

Chip & guillaume::components::Chip::setVariant ( Variant variant)

Choose the kind of chip.

Parameters
variantThe variant; it decides whether a press toggles the selection and which icons the chip needs.
Returns
This component, for chaining.

Definition at line 34 of file chip.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ CheckGlyph

const char* guillaume::components::Chip::CheckGlyph = "check"
staticconstexpr

Glyph of the selected check.

Definition at line 86 of file chip.hpp.

◆ CloseGlyph

const char* guillaume::components::Chip::CloseGlyph = "close"
staticconstexpr

Glyph of the trailing close icon.

Definition at line 89 of file chip.hpp.

◆ CompactPadding

float guillaume::components::Chip::CompactPadding = 8.0f
staticconstexpr

Padding around the content of a compact chip, in dp.

Definition at line 98 of file chip.hpp.

◆ DefaultAssistGlyph

const char* guillaume::components::Chip::DefaultAssistGlyph = "event"
staticconstexpr

Glyph of the leading icon of an Assist chip without one.

Definition at line 83 of file chip.hpp.

◆ IconSize

float guillaume::components::Chip::IconSize = 18.0f
staticconstexpr

Font size of the icons, in dp.

Definition at line 92 of file chip.hpp.

◆ Padding

float guillaume::components::Chip::Padding = 12.0f
staticconstexpr

Padding around the content, in dp.

Definition at line 95 of file chip.hpp.


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