22#include "guillaume/systems/switch.hpp"
24#include "guillaume/components/accessibility.hpp"
25#include "guillaume/components/borders.hpp"
26#include "guillaume/components/bound.hpp"
27#include "guillaume/components/color.hpp"
28#include "guillaume/components/value.hpp"
32#include "guillaume/systems/layout.hpp"
33#include "guillaume/theme.hpp"
51 void colorChild(ecs::ComponentRegistry ®istry,
53 const utility::graphic::Color32Bit &color)
55 if (registry.hasComponent<components::Color>(child)) {
56 registry.getComponent<components::Color>(child).setColor(color);
73 componentRegistry, identifier,
75 [registry, identifier]() {
76 toggle(*registry, identifier);
78 [registry, identifier]() {
79 apply(*registry, identifier);
86 apply(*registry, identifier);
93 return componentRegistry
103 return componentRegistry
114 .setValue(checked ? 1.0f : 0.0f);
120 if (
isDisabled(componentRegistry, entityIdentifier)) {
124 setChecked(componentRegistry, entityIdentifier,
125 !
isChecked(componentRegistry, entityIdentifier));
127 const auto onValueChange =
131 onValueChange(
isChecked(componentRegistry, entityIdentifier));
140 const bool on =
isChecked(componentRegistry, entityIdentifier);
141 const auto layer =
Layout::layerOf(componentRegistry, entityIdentifier);
142 const auto thumb = config.getThumb();
143 const auto label = config.getLabelEntity();
149 thumb, on ? 1.0f : 0.0f,
151 colorChild(componentRegistry, thumb,
152 config.getVariant() == Variant::Disabled
155 : SchemeColorRole::Outline));
163 const auto &labelBound =
166 componentRegistry, entityIdentifier, label,
167 utility::graphic::PositionF(
169 (track.getHeight() - labelBound.getHeight()) / 2.0f, 0.0f),
173 + labelBound.getWidth());
181 config.getVariant() != Variant::Disabled);
188 const bool disabled =
isDisabled(componentRegistry, entityIdentifier);
194 color.setColor(
schemeColor(on ? SchemeColorRole::Primary
195 : SchemeColorRole::SurfaceVariant));
201 colorChild(componentRegistry, config.getIcon(),
205 : SchemeColorRole::OnSurfaceVariant));
206 colorChild(componentRegistry, label,
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setLabel(const std::string &label)
Set the name announced for the entity, such as "Close".
Corner radii and outline stroke of a rectangular entity.
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Configuration of a switch: its variant, its thumb icon, its label and the identifiers of its thumb,...
static constexpr float ThumbInset
Inset of the thumb from the track ends, in dp.
static constexpr float LabelGap
Gap between the track and the label, in dp.
A number kept inside a range, with a callback run when it changes.
Value & setMin(float min)
Set the lower bound of the range.
Value & setOnChangedHandler(const Handler &handler)
Set the callback run when the value changes.
Value & setMax(float max)
Set the upper bound of the range.
Value & setStep(float step)
Set the snapping step.
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...
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...
Arranges the children of a container in a row or a column and sizes the container around them.
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.
Switch(void)
Create the system for the Layout phase, matching entities that have a components::Switch.
static void setChecked(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool checked)
Turn the switch on or off from code.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Frame entry point: call apply on one switch.
static bool isChecked(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the switch is on.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make an entity behave as a switch.
static bool isDisabled(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the switch ignores input and is drawn disabled.
static void toggle(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Flip the switch as a click does.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Draw one switch from its components: thumb position, colors and accessibility.
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
void centerChild(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const ecs::Entity::Identifier &childIdentifier, std::uint32_t parentLayer)
Center a child inside the bound of its parent, on both axes.
void placeChild(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const ecs::Entity::Identifier &childIdentifier, const utility::graphic::PositionF &offset, std::uint32_t parentLayer)
Place a child at an offset from the position of its parent.
void reserveTrailingWidth(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &identifier, float width)
Reserve layout room after an entity's Bound.
void placeNormalized(ecs::ComponentRegistry ®istry, const ecs::Entity::Identifier &parentIdentifier, const ecs::Entity::Identifier &childIdentifier, float normalized, float inset, std::uint32_t parentLayer)
Place a child along the width of its parent from a 0 to 1 value, vertically centered.
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.
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.
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.
Placement helpers for the children systems::Layout does not arrange.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.