23#include "guillaume/systems/app_bar.hpp"
28#include "guillaume/components/accessibility.hpp"
29#include "guillaume/components/button.hpp"
30#include "guillaume/components/color.hpp"
31#include "guillaume/components/elevation.hpp"
32#include "guillaume/components/layout.hpp"
33#include "guillaume/components/text.hpp"
34#include "guillaume/components/typography.hpp"
36#include "guillaume/systems/button.hpp"
37#include "guillaume/systems/layout.hpp"
38#include "guillaume/systems/typography.hpp"
39#include "guillaume/theme.hpp"
54 void styleTitle(ecs::ComponentRegistry ®istry,
55 const components::AppBar &appBar)
57 const auto title = appBar.getTitleEntity();
63 if (registry.hasComponent<components::Typography>(title)
66 registry.getComponent<components::Typography>(title);
70 if (typography.getRole() != role
71 || typography.getFontSize().has_value()) {
72 typography.setRole(role).setFontSize(std::nullopt);
76 if (registry.hasComponent<components::Accessibility>(title)) {
77 registry.getComponent<components::Accessibility>(title)
78 .setLabel(appBar.getTitle());
89 void styleNavigation(ecs::ComponentRegistry ®istry,
101 if (button.getContentColorOverride() != color) {
102 button.setContentColorOverride(color);
137 case Variant::Medium:
141 case Variant::Bottom:
144 case Variant::CenterAligned:
153 case Variant::Medium:
158 case Variant::CenterAligned:
159 case Variant::Bottom:
173 && !appBar.getNavigation().icon.empty();
183 && !appBar.getTitle().empty();
203 const auto variant = appBar.getVariant();
205 const auto navigation = appBar.getNavigationButton();
206 const auto title = appBar.getTitleEntity();
210 if (variant == Variant::CenterAligned) {
211 mainAxisAlignment = (appBar.getNavigation().icon.empty()
212 && appBar.getActions().empty())
217 std::vector<ecs::Entity::Identifier> children;
218 if (navigation != invalid) {
219 children.push_back(navigation);
221 if (title != invalid) {
222 children.push_back(title);
224 for (
const auto action: appBar.getActionButtons()) {
225 if (action != invalid) {
226 children.push_back(action);
231 .setCrossAxisAlignment(
233 .setMainAxisAlignment(mainAxisAlignment)
236 .setFixedHeight(
height(variant))
237 .setChildren(children);
240 const bool tinted = appBar.
isElevated() || variant == Variant::Bottom;
246 .setElevationLevel(appBar.isElevated()
250 styleNavigation(componentRegistry, navigation);
251 styleTitle(componentRegistry, appBar);
253 Layout::apply(componentRegistry, entityIdentifier, layout.getChildren(),
What an entity means to a user who does not see it: its name, its role, its state and its place in th...
Accessibility & setFocusable(bool focusable)
Include the entity in the Tab traversal or leave it out.
Accessibility & setLabel(const std::string &label)
Set the name announced for the entity, such as "Close".
State of an app bar: the strip that carries a screen's title, its navigation icon and its action icon...
ecs::Entity::Identifier getNavigationButton(void) const noexcept
Get the icon button child built for the navigation action.
bool isElevated(void) const noexcept
Tell whether the bar is elevated.
ecs::Entity::Identifier getTitleEntity(void) const noexcept
Get the text child that displays the title.
const Identifiers & getActionButtons(void) const noexcept
Get the icon button children built for the trailing actions.
Variant
Shape of the bar. It sets the height and the title size.
static constexpr float HorizontalPadding
Padding on each side of the bar and gap between its children, in dp.
Main color of an entity: the fill of a shape, or the ink of a text or an icon.
Soft shadow drawn around an elevated surface.
How a container arranges its children: in a row or a column, with which alignment,...
@ Center
Packed in the middle.
@ Start
Packed at the left (row) or top (column).
@ Horizontal
Row: children placed left to right.
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.
ComponentType & addComponent(const Entity::Identifier &entityIdentifier, Args &&...args)
Construct a component for an entity, replacing the one it already has, if any.
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...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
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 bool needsNavigationButton(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the navigation button child still has to be created.
static theme::TypeRole titleRole(components::AppBar::Variant variant)
Get the typescale role the title of a variant is drawn with.
static bool needsActionButtons(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the action button children have to be created again.
static void installTitle(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Expose the title child to assistive technology as a header.
static bool needsTitle(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the title child still has to be created.
static float height(components::AppBar::Variant variant)
Get the fixed height of a variant.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one app bar and arrange its children.
AppBar(void)
Create the system in the Layout phase.
void update(const ecs::Entity::Identifier &entityIdentifier) override
Run apply() on one app bar; called by the frame loop.
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.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Resolve the metrics of one text and write them into its components::Text.
State. Every class here is plain data attached to an entity.
@ Button
Pressable button.
@ Header
Heading (app bar title, list subheader).
The entity-component-system core, independent of any 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 schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
@ Level2
Second raised level.
@ Level0
Flat: no shadow, no tint.
TypeRole
The named text styles of Material Design 3: what a piece of text is, not how big it is.
@ TitleLarge
22 / 28, regular.
@ HeadlineMedium
28 / 36, regular.
@ HeadlineSmall
24 / 32, regular.
utility::graphic::Color32Bit getElevatedSurfaceColor(theme::ElevationLevel level)
Get the background color of a surface raised to an elevation level.
Color helpers shared by the widget systems: scheme lookup, state layers and the disabled colors.