23#include "guillaume/systems/chip.hpp"
27#include "guillaume/components/accessibility.hpp"
28#include "guillaume/components/borders.hpp"
29#include "guillaume/components/color.hpp"
30#include "guillaume/components/elevation.hpp"
31#include "guillaume/components/layout.hpp"
32#include "guillaume/components/selection.hpp"
33#include "guillaume/components/text.hpp"
36#include "guillaume/systems/layout.hpp"
37#include "guillaume/theme.hpp"
56 void colorChild(ecs::ComponentRegistry ®istry,
58 const utility::graphic::Color32Bit &color)
60 if (registry.hasComponent<components::Color>(child)) {
61 registry.getComponent<components::Color>(child).setColor(color);
72 void attachChildren(ecs::ComponentRegistry ®istry,
76 registry.getComponent<components::Chip>(identifier);
78 const auto leading = chip.getLeadingIcon();
79 const auto check = chip.getCheckIcon();
80 const auto label = chip.getLabelEntity();
81 const auto trailing = chip.getTrailingIcon();
85 if (leading == invalid && check == invalid && label == invalid
86 && trailing == invalid) {
90 std::vector<ecs::Entity::Identifier> children;
91 if (check != invalid && showCheck) {
92 children.push_back(check);
93 }
else if (leading != invalid) {
94 children.push_back(leading);
96 if (label != invalid) {
97 children.push_back(label);
99 if (trailing != invalid) {
100 children.push_back(trailing);
102 registry.getComponent<components::Layout>(identifier)
103 .setChildren(children);
119 componentRegistry, identifier,
121 [registry, identifier]() {
122 press(*registry, identifier);
124 [registry, identifier]() {
125 apply(*registry, identifier);
129 .setOnSelectionChangedHandler([registry, identifier](
bool) {
130 apply(*registry, identifier);
149 [registry, identifier]() {
150 close(*registry, identifier);
159 return componentRegistry
177 if (chip.getVariant() == Variant::Assist
178 && chip.getIconGlyph().empty()) {
187 return componentRegistry
200 ||
static_cast<bool>(chip.getOnClose());
209 apply(componentRegistry, entityIdentifier);
217 apply(componentRegistry, entityIdentifier);
223 if (
isDisabled(componentRegistry, entityIdentifier)) {
229 if (chip.getVariant() == Variant::Filter) {
231 !
isSelected(componentRegistry, entityIdentifier));
243 if (
isDisabled(componentRegistry, entityIdentifier)) {
266 const bool selected =
isSelected(componentRegistry, entityIdentifier);
267 const bool disabled =
isDisabled(componentRegistry, entityIdentifier);
268 const bool outlined = (chip.getMode() == Mode::Outlined);
269 const bool showCheck = selected && chip.isShowSelectedCheck();
273 .setLabel(chip.getLabel())
279 if (!outlined || selected) {
280 container =
schemeColor(SchemeColorRole::SecondaryContainer);
282 auto content = (outlined && !selected)
284 :
schemeColor(SchemeColorRole::OnSecondaryContainer);
285 auto iconColor = selected
286 ?
schemeColor(SchemeColorRole::OnSecondaryContainer)
295 if (selected && chip.isShowSelectedOverlay()) {
300 componentRegistry, entityIdentifier, container, content);
304 .setColor(container);
306 if (outlined && !selected) {
316 .setElevationLevel((chip.isElevated() && !disabled)
323 colorChild(componentRegistry, chip.getLeadingIcon(), iconColor);
324 colorChild(componentRegistry, chip.getCheckIcon(),
326 colorChild(componentRegistry, chip.getTrailingIcon(), content);
327 colorChild(componentRegistry, chip.getLabelEntity(), content);
329 chip.getLabelEntity())) {
335 attachChildren(componentRegistry, entityIdentifier, showCheck);
336 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setSelected(bool selected)
Set whether the entity is the selected one of its group.
Corner radii and outline stroke of a rectangular entity.
Configuration of a chip: a compact pill with a label and optional leading, check and close icons.
static constexpr float Padding
Padding around the content, in dp.
static constexpr const char * DefaultAssistGlyph
Glyph of the leading icon of an Assist chip without one.
Variant getVariant(void) const noexcept
Get the kind of chip.
const std::string & getIconGlyph(void) const noexcept
Get the name of the leading icon glyph.
Mode
Container style: Flat is filled with the secondary container color; Outlined is transparent with an o...
const Handler & getOnPress(void) const noexcept
Get the callback run when the chip is pressed.
static constexpr float CompactPadding
Padding around the content of a compact chip, in dp.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Soft shadow drawn around an elevated surface.
How a container arranges its children: in a row or a column, with which alignment,...
Selected/unselected flag of an entity, with a callback run when it changes.
A run of text: its content, its font metrics and the position of the editing cursor.
Text & setContent(const std::string &content)
Replace the text.
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.
bool hasComponent(const Entity::Identifier &entityIdentifier) const
Tell whether an entity has a component of a given type.
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
SystemFiller(Phase phase)
ecs::ComponentRegistry & getComponentRegistry(void)
Get the component registry of the scene being processed.
bool requireComponent(const ecs::Entity::Identifier &entityIdentifier)
Tell whether an entity has a component, and log a warning naming the entity and the component when it...
void update(const ecs::Entity::Identifier &entityIdentifier) override
Frame entry point: call apply on one chip.
static void setDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool disabled)
Enable or disable the chip and show it at once.
Chip(void)
Create the system for the Layout phase, matching entities that have a components::Chip.
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 void press(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Press the chip as a click does.
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 close(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Press the close icon of the chip as a click does.
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.
Arranges the children of a container in a row or a column and sizes the container around them.
static void apply(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const std::vector< ecs::Entity::Identifier > &childIdentifiers, std::uint32_t layer=0)
Arrange children inside a container and size the container.
static std::uint32_t layerOf(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &identifier)
Get the layer of an entity: its depth in the entity tree.
State. Every class here is plain data attached to an entity.
@ Button
Pressable button.
The entity-component-system core, independent of any widget.
utility::graphic::Color32Bit disabledContainerColor(void)
Fill color of the container of a disabled widget.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit stateLayer(const utility::graphic::Color32Bit &base, const utility::graphic::Color32Bit &overlay, std::uint8_t alpha)
Blend a translucent tint over a base color.
utility::graphic::Color32Bit disabledContentColor(void)
Color of the icon, label or outline of a disabled widget.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
Rules. Every class here runs each frame on the entities that have the components it declares.
utility::graphic::Color32Bit disabledContainerColor(void)
Fill color of the container of a disabled widget.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit disabledContentColor(void)
Color of the icon, label or outline of a disabled widget.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ Level1
Lowest raised level.
@ Level0
Flat: no shadow, no tint.
@ Pressed
0.12 overlay of the content color.
Helpers of the namespace systems::interaction: what "pressable" means for a widget,...
bool isEnabled(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier)
Whether an entity accepts input.
void makeInteractive(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier, components::AccessibilityRole role, std::function< void(void)> onPress, std::function< void(void)> onStateChange={})
Make an entity hoverable, pressable and focusable.
void setEnabled(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier, bool enabled)
Enable or disable an entity.
utility::graphic::Color32Bit stateLayerColor(const ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &entityIdentifier, const utility::graphic::Color32Bit &base, const utility::graphic::Color32Bit &content)
Container color of a widget in its current input state.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.