27#include "guillaume/entities/segmented_button.hpp"
28#include "guillaume/entities/builder_base.hpp"
29#include "guillaume/entities/button.hpp"
30#include "guillaume/systems/segmented_button.hpp"
41 std::vector<SegmentedButton::Segment>
42 segmentsFromLabels(
const std::vector<std::string> &labels)
44 std::vector<SegmentedButton::Segment> segments;
46 segments.reserve(labels.size());
47 for (
const auto &label: labels) {
64 if (!_segmentConfigs.empty()) {
66 _segmentConfigs, _selectionMode,
77 _segmentConfigs.clear();
78 _selectionMode = SelectionMode::Single;
83 const std::vector<std::string> &labels)
92 _selectionMode = selectionMode;
97 const std::vector<Segment> &segments)
99 _segmentConfigs = segments;
104 std::function<
void(std::size_t)> onChange)
106 _onChange = std::move(onChange);
110 std::shared_ptr<SegmentedButton>
112 std::shared_ptr<Entity> parent,
113 const std::vector<std::string> &labels,
SelectionMode selectionMode,
114 std::function<
void(std::size_t)> onChange)
117 .withSelectionMode(selectionMode)
118 .withOnChange(onChange)
119 .registerEntity(parent);
123 const std::vector<std::string> &labels,
125 std::function<
void(std::size_t)> onChange)
126 : SegmentedButton(registry, segmentsFromLabels(labels), selectionMode,
132 const std::vector<Segment> &segments,
134 std::function<
void(std::size_t)> onChange)
141 .setSegments(segments)
197 const auto &buttons =
202 return index < buttons.size() ? buttons[index]
206 void SegmentedButton::build(
void)
210 const std::vector<Segment> segments =
214 std::vector<ecs::Entity::Identifier> identifiers;
216 for (
const auto &segment: segments) {
219 const auto button = buttonBuilder.makeButton(
220 shared_from_this(), segment.label, std::function<
void(
void)>(),
221 Button::Color::Segmented, Button::Shape::Square,
222 Button::Size::Medium,
false);
223 identifiers.push_back(button->getIdentifier());
227 .setButtons(identifiers);
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.
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.
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
ParentEntityFiller(ComponentRegistry &componentRegistry)
ComponentRegistry & getComponentRegistry(void)
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
State. Every class here is plain data attached to an entity.
The entity-component-system core, independent of any widget.
Widgets: the classes used to create entities with the right components and children.