28#include "guillaume/entities/list.hpp"
30#include "guillaume/components/accessibility.hpp"
31#include "guillaume/components/layout.hpp"
32#include "guillaume/entities/builder_base.hpp"
33#include "guillaume/entities/content_helpers.hpp"
34#include "guillaume/entities/divider.hpp"
35#include "guillaume/entities/image.hpp"
37#include "guillaume/systems/list.hpp"
38#include "guillaume/theme.hpp"
44 using Row = components::List::Row;
45 using Children = std::vector<std::shared_ptr<ecs::Entity>>;
57 std::shared_ptr<View> makeView(ecs::ComponentRegistry ®istry,
58 ecs::EntityRegistry &entityRegistry,
59 std::shared_ptr<ecs::Entity> parent)
63 builder.makeDefaultView(parent, utility::graphic::PoseF(), {});
65 view->setPadding(0.0f);
66 view->setSpacing(0.0f);
77 std::shared_ptr<ecs::Entity>
78 buildSubheader(ecs::ComponentRegistry ®istry,
79 const std::shared_ptr<List> &list,
83 buildText(registry, *list, list, item.headline,
86 if (header !=
nullptr) {
87 registry.addComponent<components::Accessibility>(
88 header->getIdentifier());
90 .getComponent<components::Accessibility>(
91 header->getIdentifier())
93 .setLabel(item.headline)
108 void buildRowLead(ecs::ComponentRegistry ®istry,
109 const std::shared_ptr<View> &view, Row &row,
112 const auto lead = makeView(registry, *view, view);
113 row.lead = lead->getIdentifier();
116 row.spacer = makeView(registry, *lead, lead)->getIdentifier();
119 if (!item.leadingImage.empty()) {
121 if (
const auto image =
122 builder.makeImage(lead, item.leadingImage)) {
123 row.leadingImage = image->getIdentifier();
126 registry, *lead, lead, item.leadingIcon,
129 row.leadingIcon = icon->getIdentifier();
132 const auto content = makeView(registry, *lead, lead);
133 row.content = content->getIdentifier();
135 if (
const auto headline =
136 buildText(registry, *content, content, item.headline,
139 row.headline = headline->getIdentifier();
143 if (
const auto supporting =
144 buildText(registry, *content, content, item.supporting,
147 row.supporting = supporting->getIdentifier();
161 Row buildRow(ecs::ComponentRegistry ®istry,
162 const std::shared_ptr<List> &list,
const List::Item &item,
163 float width,
bool nested, Children &roots)
167 if (item.kind == List::ItemKind::Subheader) {
168 if (
const auto header = buildSubheader(registry, list, item)) {
169 row.entity = header->getIdentifier();
170 roots.push_back(header);
175 if (item.kind == List::ItemKind::Divider) {
177 if (
const auto divider = builder.makeDivider(
178 list, width, Divider::Variant::FullWidth)) {
179 row.entity = divider->getIdentifier();
180 roots.push_back(divider);
185 const auto view = makeView(registry, *list, list);
186 row.view = view->getIdentifier();
187 row.entity = row.view;
188 roots.push_back(view);
190 buildRowLead(registry, view, row, item, nested);
194 const std::string trailing = item.children.empty()
201 row.trailingIcon = icon->getIdentifier();
204 for (
const auto &child: item.children) {
205 row.children.push_back(
206 buildRow(registry, list, child, width,
true, roots));
230 _variant = Variant::SingleLine;
234 _config.mainAxisAlignment =
236 _config.crossAxisAlignment =
238 _config.padding = 0.0f;
239 _config.spacing = 0.0f;
263 _config.hasFixedWidth =
true;
264 _config.fixedWidth = width;
268 std::shared_ptr<List>
270 Variant variant,
const std::vector<Item> &items)
272 return withVariant(variant).withItems(items).registerEntity(parent);
278 item.
kind = ItemKind::Subheader;
286 item.
kind = ItemKind::Divider;
291 Variant variant,
const std::vector<Item> &items)
351 std::size_t childIndex)
const
355 .findRow({ index, childIndex });
389 void List::build(
void)
395 void List::buildItems(
void)
398 if (weak_from_this().expired()) {
409 const auto self = std::static_pointer_cast<List>(shared_from_this());
412 const float width = layout.hasFixedWidth()
413 ? layout.getFixedWidth()
423 std::vector<Row> rows;
426 for (
const auto &item: items) {
427 rows.push_back(buildRow(registry, self, item, width,
false, roots));
432 .setRowsDirty(
false);
@ Start
At the top (row) or left (column).
@ Start
Packed at the left (row) or top (column).
@ Vertical
Column: children placed top to bottom.
State of a list: a column of rows, each with a headline and optional supporting text,...
static constexpr float DefaultWidth
Default width of a list, in dp.
static constexpr const char * CollapsedGlyph
Glyph name of the trailing icon of a collapsed accordion.
static constexpr const char * ExpandedGlyph
Glyph name of the trailing icon of an expanded accordion.
static constexpr float IconSize
Size of the leading and trailing icons, in dp.
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.
Owns entities and gives the systems the list of entities to visit.
void clearEntities(void)
Remove every entity owned by this registry, with everything they own and all their components.
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
ComponentRegistry & getComponentRegistry(void)
Configures Divider widgets and registers them in the scene's entity registry.
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Configures Image widgets and registers them in the scene's entity registry.
Configures a List, creates it and registers it in an entity registry.
std::shared_ptr< List > buildEntity(void) override
Build a list and its rows from the current configuration, without registering it or setting its paren...
std::shared_ptr< List > makeList(std::shared_ptr< ecs::Entity > parent, Variant variant, const std::vector< Item > &items)
Build a list, register it under parent and reset the builder.
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the list is placed.
Builder & withItems(const std::vector< Item > &items)
Set the entries, replacing the ones set before.
Builder & withFixedWidth(float width)
Set the width of the list and of its rows.
void reset(void) override
Restore the defaults.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Builder & withVariant(Variant variant)
Set the variant.
A vertical list of pressable rows, with optional subheaders, dividers and accordions that fold nested...
List & setItems(const std::vector< Item > &items)
Replace the entries.
ecs::Entity::Identifier getContentIdentifier(std::size_t index) const
Get the content column of a top-level row: the container of its headline and supporting text.
static Item divider(void)
Make a divider entry: a horizontal line as wide as the list.
static Item subheader(const std::string &title)
Make a subheader entry: a section title that is not pressable.
components::List::Variant Variant
List variant.
~List(void) override
Default destructor.
List & setVariant(Variant variant)
Change the variant. Restyles at once; the rows are kept.
ecs::Entity::Identifier getItemIdentifier(std::size_t index) const
Get the root entity of a top-level entry: the row container, the subheader text or the divider.
static std::shared_ptr< List > create(Arguments &&...arguments)
Create a list and its rows, without registering it in an entity registry.
bool isExpanded(std::size_t index) const
Whether a top-level accordion shows its nested rows.
Variant getVariant(void) const
Get the variant.
List & setItemDisabled(std::size_t index, bool disabled)
Enable or disable a top-level entry. Restyles at once.
ecs::Entity::Identifier getChildIdentifier(std::size_t index, std::size_t childIndex) const
Get the root entity of a row nested in an accordion.
std::size_t getItemCount(void) const
Get the number of top-level entries.
components::List::Item Item
List entry.
List & setExpanded(std::size_t index, bool expanded)
Expand or collapse a top-level accordion.
Base of the widgets that are a rectangle containing other widgets (Card, Dialog, Checkbox,...
std::vector< std::shared_ptr< ecs::Entity > > Children
SurfaceBase & setChildren(const Children &children)
Configures View widgets and registers them in the scene's entity registry.
static void setItemDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index, bool disabled)
Enable or disable a top-level entry and restyle the list.
static bool isExpanded(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index)
Whether a top-level entry is expanded.
static void install(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Make every row of a list pressable.
static void setExpanded(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, std::size_t index, bool expanded)
Expand or collapse a top-level accordion and arrange the list again.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one list, then size and place its rows.
Makes the color helpers callable from guillaume::entities without qualification.
State. Every class here is plain data attached to an entity.
@ Header
Heading (app bar title, list subheader).
Widgets: the classes used to create entities with the right components and children.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
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.
@ TitleSmall
14 / 20, medium weight.
@ BodyMedium
14 / 20, regular.
ItemKind kind
What the entry is.
std::string headline
Main text of the row.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...