22#include "guillaume/systems/checkbox.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/hand_hover_interaction.hpp"
29#include "guillaume/components/layout.hpp"
30#include "guillaume/components/line.hpp"
31#include "guillaume/components/mouse_hover_interaction.hpp"
32#include "guillaume/components/selection.hpp"
36#include "guillaume/systems/layout.hpp"
37#include "guillaume/theme.hpp"
55 void colorChild(ecs::ComponentRegistry ®istry,
57 const utility::graphic::Color32Bit &color)
59 if (registry.hasComponent<components::Color>(child)) {
60 registry.getComponent<components::Color>(child).setColor(color);
70 void placeLabel(ecs::ComponentRegistry ®istry,
74 if (!registry.hasComponent<components::Bound>(label)) {
80 registry.getComponent<components::Bound>(identifier);
81 const auto &labelBound =
82 registry.getComponent<components::Bound>(label);
89 const float y = (box.getHeight() - labelBound.getHeight()) / 2.0f;
91 utility::graphic::PositionF(x, y, 0.0f),
94 x + labelBound.getWidth()
111 componentRegistry, identifier,
113 [registry, identifier]() {
114 toggle(*registry, identifier);
116 [registry, identifier]() {
117 apply(*registry, identifier);
124 const auto margin =
static_cast<unsigned int>(
128 .setAccessibilityMargin(utility::graphic::SizeUI(margin, margin));
131 .setAccessibilityMargin(utility::graphic::SizeUI(margin, margin));
134 .setOnSelectionChangedHandler([registry,
135 identifier](
bool selected) {
138 if (checkbox.getState() != State::Indeterminate) {
139 checkbox.setState(selected ? State::Checked
142 apply(*registry, identifier);
149 return componentRegistry
163 .setSelected(state != State::Unchecked);
164 apply(componentRegistry, entityIdentifier);
170 if (
isDisabled(componentRegistry, entityIdentifier)) {
174 const auto &checkbox =
177 setState(componentRegistry, entityIdentifier,
178 checkbox.getState() == State::Checked ? State::Unchecked
181 const auto onValueChange = checkbox.getOnValueChange();
183 onValueChange(checkbox.getState());
190 const auto &checkbox =
193 const State state = checkbox.
getState();
194 const Variant variant = checkbox.getVariant();
203 variant != Variant::Disabled);
205 const bool disabled =
isDisabled(componentRegistry, entityIdentifier);
206 const bool errored = (variant == Variant::Error);
210 .setLabel(checkbox.getLabel())
213 : (state == State::Indeterminate
217 line.setThickness(state == State::Indeterminate ? 2.0f : 0.0f);
219 const auto onColorRole =
220 errored ? SchemeColorRole::OnError : SchemeColorRole::OnPrimary;
224 const auto containerRole =
225 errored ? SchemeColorRole::Error : SchemeColorRole::Primary;
229 case State::Indeterminate: {
234 componentRegistry, entityIdentifier,
236 : checkbox.getCheckedColor().value_or(
243 case State::Unchecked:
245 const auto outline = errored
247 : checkbox.getUncheckedColor().value_or(
249 color.setColor(disabled
252 componentRegistry, entityIdentifier,
254 borders.setWidth(2.0f);
260 colorChild(componentRegistry, checkbox.getCheckIcon(),
263 colorChild(componentRegistry, checkbox.getLabelEntity(),
267 : SchemeColorRole::OnSurface));
269 placeLabel(componentRegistry, entityIdentifier,
270 checkbox.getLabelEntity());
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setChecked(std::optional< CheckedState > checked)
Set whether the entity is ticked.
Corner radii and outline stroke of a rectangular entity.
Borders & setColor(const utility::graphic::Color32Bit &color)
Set the color of the stroke.
State of a checkbox: checked state, variant, label, color overrides and the identifiers of its check ...
static constexpr float LabelGap
Gap between the touch target and the label, in dp.
static constexpr float TouchTarget
Edge of the square touch target centered on the box, in dp.
State getState(void) const noexcept
Get the checked state.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Color & setColor(const utility::graphic::Color32Bit &color)
Set the color.
Whether an XR hand (controller) aims at an entity, what to call when the aim enters or leaves,...
How a container arranges its children: in a row or a column, with which alignment,...
A straight stroke across the width of the entity: a divider, an indicator, the underline of a text fi...
Whether the mouse pointer is over an entity, what to call when it enters or leaves,...
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.
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...
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Draw one checkbox from its component: colors, accessibility and label position.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make an entity behave as a checkbox.
Checkbox(void)
Create the system for the Layout phase, matching entities that have a components::Checkbox.
static void setState(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, components::Checkbox::State state)
Set the state of a checkbox from code and show it at once.
static bool isDisabled(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the checkbox ignores input and is drawn disabled.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Frame entry point: call apply on one checkbox.
static void toggle(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Toggle the checkbox as a click does.
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.
State. Every class here is plain data attached to an entity.
@ Checkbox
Two- or three-state checkbox.
@ Mixed
Indeterminate: neither checked nor unchecked.
The entity-component-system core, independent of any widget.
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.
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 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.
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.
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.