23#include "guillaume/entities/checkbox.hpp"
28#include "guillaume/entities/content_helpers.hpp"
29#include "guillaume/entities/builder_base.hpp"
32#include "guillaume/components/hand_hover_interaction.hpp"
33#include "guillaume/components/mouse_hover_interaction.hpp"
35#include "guillaume/systems/checkbox.hpp"
36#include "guillaume/theme.hpp"
50 _state, _variant, _label);
57 _state = State::Unchecked;
58 _variant = Variant::Enabled;
61 _config.borderRadius = 2.0f;
63 _config.mainAxisAlignment =
65 _config.crossAxisAlignment =
67 _config.spacing = 8.0f;
68 _config.padding = 0.0f;
69 _config.setFixedWidth(18.0f);
70 _config.setFixedHeight(18.0f);
98 std::shared_ptr<Checkbox>
101 const std::string &label)
104 .withVariant(variant)
106 .registerEntity(parent);
111 Variant variant,
const std::string &label)
146 std::optional<utility::graphic::Color32Bit> color)
156 std::optional<utility::graphic::Color32Bit> color)
203 checkbox.getLabelEntity())) {
218 void Checkbox::build(
void)
226 const auto checkIcon =
227 buildIcon(registry, *
this, shared_from_this(),
"check", 14.0f,
229 std::vector<std::shared_ptr<ecs::Entity>> children;
230 if (checkIcon !=
nullptr) {
231 checkbox.setCheckIcon(checkIcon->getIdentifier());
232 children.push_back(checkIcon);
235 if (!checkbox.getLabel().empty()) {
237 buildText(registry, *
this, shared_from_this(),
240 if (label !=
nullptr) {
241 checkbox.setLabelEntity(label->getIdentifier());
State of a checkbox: checked state, variant, label, color overrides and the identifiers of its check ...
Checkbox & setLabel(const std::string &label)
Set the label text.
@ 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.
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.
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.
ComponentRegistry & getComponentRegistry(void)
Configures, creates and registers Checkbox widgets.
Builder & withState(State state)
Set the state the checkbox starts in.
void reset(void) override
Restore the default configuration.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Construct a builder with the default configuration (see reset()).
Builder & withVariant(Variant variant)
Set the visual variant.
Builder & withPose(const utility::graphic::PoseF &pose)
Set the position and orientation of the box.
Builder & withLabel(const std::string &label)
Set the label shown to the right of the box.
std::shared_ptr< Checkbox > makeCheckbox(std::shared_ptr< ecs::Entity > parent, State state, Variant variant, const std::string &label)
Build a checkbox, register it under parent and reset the builder.
std::shared_ptr< Checkbox > buildEntity(void) override
Build a Checkbox, with its check glyph and label children, from the current configuration,...
A box the user checks, unchecks or leaves indeterminate, with an optional label next to it.
bool isChecked(void) const
Check whether the checkbox's components::Selectable is selected.
components::Checkbox::Variant Variant
Checkbox & setCheckedColor(std::optional< utility::graphic::Color32Bit > color)
Override the fill color of the checked and indeterminate box (Paper color). Restyles at once.
State getState(void) const
Get the state.
Variant getVariant(void) const
Get the visual variant.
Checkbox & setVariant(Variant variant)
Set the visual variant. Restyles at once.
Checkbox & setOnValueChange(std::function< void(State)> onValueChange)
Set the handler called when the user toggles the box, or when toggle() is called.
Checkbox & toggle(void)
Toggle as a user activation would: a checked box becomes unchecked, an unchecked or indeterminate box...
bool isDisabled(void) const
Check whether the checkbox ignores input.
Checkbox & setState(State state)
Set the state. Restyles at once.
components::Checkbox::State State
Checked state: Unchecked, Checked or Indeterminate.
Checkbox & setLabel(const std::string &label)
Set the label text and the accessibility label. Restyles at once.
static std::shared_ptr< Checkbox > create(Arguments &&...arguments)
Create a checkbox and its check glyph and label children, without registering it in an entity registr...
Checkbox & setUncheckedColor(std::optional< utility::graphic::Color32Bit > color)
Override the outline color of the unchecked box (Paper uncheckedColor). Restyles at once.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
SurfaceBase(ecs::ComponentRegistry ®istry, const SurfaceConfig &config)
SurfaceBase & setChildren(const Children &children)
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.
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.
static void toggle(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Toggle the checkbox as a click does.
Makes the interaction helpers callable from guillaume::entities without qualification.
Makes the placement 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.
@ BodyLarge
16 / 24, regular.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...