23#include "guillaume/entities/chip.hpp"
28#include "guillaume/entities/content_helpers.hpp"
29#include "guillaume/entities/builder_base.hpp"
32#include "guillaume/systems/chip.hpp"
33#include "guillaume/theme.hpp"
47 _variant, _label, _iconGlyph, _selected);
54 _variant = Variant::Assist;
61 _config.mainAxisAlignment =
63 _config.crossAxisAlignment =
65 _config.spacing = 8.0f;
66 _config.padding = 12.0f;
67 _config.setFixedHeight(32.0f);
90 _iconGlyph = iconGlyph;
100 std::shared_ptr<Chip>
102 Variant variant,
const std::string &label,
103 const std::string &iconGlyph,
bool selected)
108 .withSelected(selected)
109 .registerEntity(parent);
113 Variant variant,
const std::string &label,
114 const std::string &iconGlyph,
bool selected)
122 .setIconGlyph(iconGlyph);
260 void Chip::build(
void)
264 const auto contentColor =
265 schemeColor(SchemeColorRole::OnSecondaryContainer);
266 std::vector<std::shared_ptr<ecs::Entity>> children;
270 const auto leadingIcon =
271 buildIcon(registry, *
this, shared_from_this(),
274 if (leadingIcon !=
nullptr) {
275 chip.setLeadingIcon(leadingIcon->getIdentifier());
276 children.push_back(leadingIcon);
280 const auto checkIcon =
281 buildIcon(registry, *
this, shared_from_this(),
284 if (checkIcon !=
nullptr) {
285 chip.setCheckIcon(checkIcon->getIdentifier());
286 children.push_back(checkIcon);
291 buildText(registry, *
this, shared_from_this(), chip.getLabel(),
293 if (label !=
nullptr) {
294 chip.setLabelEntity(label->getIdentifier());
295 children.push_back(label);
299 const auto closeIcon =
300 buildIcon(registry, *
this, shared_from_this(),
303 if (closeIcon !=
nullptr) {
304 chip.setTrailingIcon(closeIcon->getIdentifier());
305 children.push_back(closeIcon);
312 if (!children.empty()) {
Configuration of a chip: a compact pill with a label and optional leading, check and close icons.
static constexpr float IconSize
Font size of the icons, in dp.
static constexpr const char * CloseGlyph
Glyph of the trailing close icon.
static constexpr const char * CheckGlyph
Glyph of the selected check.
@ Center
Packed in the middle.
@ Horizontal
Row: children placed left to right.
Selected/unselected flag of an entity, with a callback run when it changes.
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
ComponentType & getComponent(const Entity::Identifier &entityIdentifier)
Get a component of an entity, to read or modify it.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
ComponentRegistry & getComponentRegistry(void)
Configures, creates and registers Chip widgets.
Builder & withLabel(const std::string &label)
Set the label text.
Builder & withIcon(const std::string &iconGlyph)
Set the leading icon.
Builder & withVariant(Variant variant)
Set the variant, which decides the children built and whether a press toggles the selection.
std::shared_ptr< Chip > makeChip(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::string &label, const std::string &iconGlyph, bool selected)
Build a chip, register it under parent and reset the builder.
Builder & withSelected(bool selected)
Choose whether the chip starts selected.
void reset(void) override
Restore the default configuration.
Builder & withPose(const utility::graphic::PoseF &pose)
Set the position and orientation of the chip.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
std::shared_ptr< Chip > buildEntity(void) override
Build a Chip, with its icon and label children, from the current configuration, without registering i...
Chip & setSelected(bool selected)
Select or deselect the chip, whatever its variant. Restyles at once.
bool isSelected(void) const
Check whether the chip is selected.
Mode getMode(void) const
Get the mode.
Chip & setOnClose(std::function< void(void)> onClose)
Set the handler called when the user presses the trailing close icon (Paper onClose).
Variant getVariant(void) const
Get the variant.
Chip & setMode(Mode mode)
Set the mode. Restyles at once.
Chip & setShowSelectedCheck(bool show)
Show the check icon while the chip is selected (Paper showSelectedCheck). Restyles at once.
Chip & setCompact(bool compact)
Use the compact padding (Paper compact). Restyles at once.
~Chip(void) override
Destructor.
Chip & setShowSelectedOverlay(bool show)
Darken the chip with a pressed state layer while it is selected (Paper showSelectedOverlay)....
bool isDisabled(void) const
Check whether the chip is disabled.
Chip & setVariant(Variant variant)
Set the variant. Restyles at once.
Chip & setElevated(bool elevated)
Paint a level 1 shadow under the chip (Paper elevated). Restyles at once.
Chip & setOnPress(std::function< void(void)> onPress)
Set the handler called when the user presses the chip (Paper onPress).
ecs::Entity::Identifier getCloseIconIdentifier(void) const
Get the identifier of the trailing close icon child.
Chip & setLabel(const std::string &label)
Set the label text. Restyles at once.
components::Chip::Variant Variant
Chip & setDisabled(bool disabled)
Enable or disable the chip. Restyles at once.
static std::shared_ptr< Chip > create(Arguments &&...arguments)
Create a chip and its icon and label children, without registering it in an entity registry.
components::Chip::Mode Mode
Paper chip mode: Flat (tonal fill, the default) or Outlined.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
static void setDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool disabled)
Enable or disable the chip and show it at once.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Draw one chip from its components and arrange its children.
static bool needsCheckIcon(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the widget class should build a selected check child for this chip.
static bool needsCloseIcon(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the widget class should build a trailing close icon child for this chip.
static std::string leadingGlyph(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Get the name of the glyph the leading icon of the chip should show.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make an entity behave as a chip.
static bool isDisabled(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the chip ignores input and is drawn disabled.
static void installCloseIcon(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make the trailing icon of a chip a close button.
static bool isSelected(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the chip is selected.
static void setSelected(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool selected)
Select or deselect the chip from code and show it at once.
Makes the interaction helpers callable from guillaume::entities without qualification.
Makes the color helpers callable from guillaume::entities without qualification.
State. Every class here is plain data attached to an entity.
Widgets: the classes used to create entities with the right components and children.
std::shared_ptr< Text > buildText(ecs::ComponentRegistry ®istry, ecs::EntityRegistry &entityRegistry, std::shared_ptr< ecs::Entity > parent, const std::string &content, float fontSize, const utility::graphic::Color32Bit &color)
Create a Text of a given font size as a child of a widget, or nothing when there is no content.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
std::shared_ptr< Icon > buildIcon(ecs::ComponentRegistry ®istry, ecs::EntityRegistry &entityRegistry, std::shared_ptr< ecs::Entity > parent, const std::string &glyphName, float fontSize, const utility::graphic::Color32Bit &color, components::Glyph::Style style=components::Glyph::Style::Outlined)
Create an Icon as a child of a widget, or nothing when there is no glyph to show.
@ LabelLarge
14 / 20, medium weight.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...