23#include "guillaume/systems/segmented_button.hpp"
28#include "guillaume/components/accessibility.hpp"
29#include "guillaume/components/borders.hpp"
30#include "guillaume/components/bound.hpp"
31#include "guillaume/components/button.hpp"
32#include "guillaume/components/common_button.hpp"
33#include "guillaume/components/layout.hpp"
34#include "guillaume/components/style_state.hpp"
35#include "guillaume/systems/button.hpp"
36#include "guillaume/systems/common_button.hpp"
37#include "guillaume/systems/layout.hpp"
51 bool isButton(
const ecs::ComponentRegistry ®istry,
82 const auto &segments = config.getSegments();
84 for (std::size_t index = 0; index < buttons.size(); ++index) {
85 const auto button = buttons[index];
86 if (!isButton(componentRegistry, button)) {
96 if (index < segments.size()) {
97 const auto &segment = segments[index];
102 .setEnabled(!segment.disabled);
104 if (!segment.accessibilityLabel.empty()
109 .setLabel(segment.accessibilityLabel);
121 const auto &buttons =
126 return index < buttons.size()
127 && isButton(componentRegistry, buttons[index])
137 const std::size_t count =
142 std::vector<std::size_t> indices;
144 for (std::size_t index = 0; index < count; ++index) {
145 if (
isSelected(componentRegistry, entityIdentifier, index)) {
146 indices.push_back(index);
162 if (index >= buttons.size()) {
166 if (config.getSelectionMode() == SelectionMode::Single) {
167 for (std::size_t other = 0; other < buttons.size(); ++other) {
168 if (isButton(componentRegistry, buttons[other])) {
173 }
else if (isButton(componentRegistry, buttons[index])) {
177 apply(componentRegistry, entityIdentifier);
184 const auto &buttons =
189 if (index >= buttons.size()) {
193 if (isButton(componentRegistry, buttons[index])) {
197 apply(componentRegistry, entityIdentifier);
209 if (index >= buttons.size()
210 || !isButton(componentRegistry, buttons[index])) {
214 if (config.getSelectionMode() == SelectionMode::Single) {
217 if (!
isSelected(componentRegistry, entityIdentifier, index)) {
220 for (std::size_t other = 0; other < buttons.size(); ++other) {
222 && isButton(componentRegistry, buttons[other])) {
229 apply(componentRegistry, entityIdentifier);
232 const auto onChange = config.getOnChange();
248 config.setSegmentDisabled(index, disabled);
249 if (index < buttons.size()
254 .setEnabled(!disabled);
255 if (isButton(componentRegistry, buttons[index])) {
261 apply(componentRegistry, entityIdentifier);
271 const auto &segments = config.getSegments();
274 for (std::size_t index = 0; index < buttons.size(); ++index) {
275 if (!isButton(componentRegistry, buttons[index])) {
283 : (index < segments.size() ? segments[index].icon
285 if (button.getIconGlyphName() != icon) {
286 button.setIconGlyphName(icon);
294 for (
const auto button: buttons) {
302 for (
const auto button: buttons) {
311 if (common.getMinWidth() != width) {
312 common.setMinWidth(width);
321 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
324 if (buttons.empty()) {
333 const std::size_t count = buttons.size();
335 for (std::size_t index = 0; index < count; ++index) {
341 const bool isFirst = (index == 0);
342 const bool isLast = (index == count - 1);
344 isFirst ? radius : 0.0f, isLast ? radius : 0.0f,
345 isLast ? radius : 0.0f, isFirst ? radius : 0.0f
352 .setCorners(corners);
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Size of an entity: the width and height, in dp, of the rectangle that starts at the position of its c...
How a container arranges its children: in a row or a column, with which alignment,...
Layout & setChildren(const std::vector< ecs::Entity::Identifier > &children)
Replace the list of children to arrange.
Layout & setPadding(float padding)
Set the inset between the container's edges and its children.
Layout & setMainAxisAlignment(MainAxisAlignment alignment)
Set where the children go along the main axis.
Layout & setCrossAxisAlignment(CrossAxisAlignment alignment)
Set where each child goes along the cross axis.
@ Start
Packed at the left (row) or top (column).
@ Horizontal
Row: children placed left to right.
Layout & setSpacing(float spacing)
Set the gap between two consecutive children.
The interaction state of an entity in one place: enabled or disabled, and whether it is hovered,...
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 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.
Rules. Every class here runs each frame on the entities that have the components it declares.