26#include "guillaume/entities/app_bar.hpp"
28#include "guillaume/entities/content_helpers.hpp"
29#include "guillaume/entities/builder_base.hpp"
31#include "guillaume/systems/app_bar.hpp"
32#include "guillaume/theme.hpp"
47 _title, _navigation, _actions, _elevated);
54 _variant = Variant::Small;
61 _config.crossAxisAlignment =
65 _config.setFixedWidth(360.0f);
90 _navigation.icon = iconGlyphName;
91 if (_navigation.accessibilityLabel.empty()) {
92 _navigation.accessibilityLabel = iconGlyphName;
100 _actions.push_back(
Action { iconGlyphName, {}, iconGlyphName,
false });
106 std::function<
void(
void)> onPress,
107 const std::string &accessibilityLabel)
109 _actions.push_back(
Action {
110 iconGlyphName, std::move(onPress),
111 accessibilityLabel.empty() ? iconGlyphName : accessibilityLabel,
118 const std::string &accessibilityLabel)
120 _navigation.onPress = std::move(onPress);
121 _navigation.accessibilityLabel = accessibilityLabel;
127 _elevated = elevated;
133 _config.hasFixedWidth =
true;
134 _config.fixedWidth = width;
138 std::shared_ptr<AppBar>
142 return withVariant(variant).registerEntity(parent);
147 std::vector<AppBar::Action>
148 toActions(
const std::vector<std::string> &icons)
150 std::vector<AppBar::Action> actions;
151 for (
const auto &icon: icons) {
158 AppBar::AppBar(ecs::ComponentRegistry ®istry,
159 const SurfaceConfig &config,
Variant variant,
160 const std::string &title,
const std::string &navigationIcon,
161 const std::vector<std::string> &actions)
162 : AppBar(registry, config, variant, title,
163 Action { navigationIcon, {}, navigationIcon,
false },
164 toActions(actions),
false)
168 AppBar::AppBar(ecs::ComponentRegistry ®istry,
170 const std::string &title,
const Action &navigation,
171 const std::vector<Action> &actions,
bool elevated)
179 .setNavigation(navigation)
189 std::shared_ptr<IconButton> AppBar::buildAction(
const Action &action)
192 return builder.withIcon(action.icon)
193 .withOnClick(action.onPress)
194 .withVariant(IconButton::Variant::Standard)
195 .withSize(IconButton::Size::Medium)
196 .withDisabled(action.disabled)
197 .withAccessibilityLabel(action.accessibilityLabel)
198 .registerEntity(this->shared_from_this());
201 void AppBar::buildContent(
void)
204 if (weak_from_this().expired()) {
215 const auto navigation = buildAction(appBar.getNavigation());
216 if (navigation !=
nullptr) {
217 appBar.setNavigationButton(navigation->getIdentifier());
223 registry, *
this, shared_from_this(), appBar.getTitle(),
226 if (title !=
nullptr) {
227 appBar.setTitleEntity(title->getIdentifier());
234 for (
const auto &action: appBar.getActions()) {
235 const auto button = buildAction(action);
236 identifiers.push_back(button !=
nullptr
237 ? button->getIdentifier()
240 appBar.setActionButtons(identifiers);
244 std::vector<std::shared_ptr<ecs::Entity>> children;
245 if (
auto navigation =
247 children.push_back(std::move(navigation));
250 children.push_back(std::move(title));
252 for (
const auto identifier: appBar.getActionButtons()) {
254 children.push_back(std::move(action));
297 const auto &actions =
302 if (index >= actions.size()) {
305 return std::const_pointer_cast<IconButton>(
335 void AppBar::build(
void)
State of an app bar: the strip that carries a screen's title, its navigation icon and its action icon...
std::vector< ecs::Entity::Identifier > Identifiers
Identifiers of child entities, in display order.
@ 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.
ComponentRegistry & getComponentRegistry(void)
Get the registry in which the builder creates components.
Owns entities and gives the systems the list of entities to visit.
std::shared_ptr< EntityType > getEntity(Entity::Identifier identifier)
Find an entity owned directly by this registry, by identifier.
Entity::Identifier getIdentifier(void) const noexcept
Get the identifier of the entity.
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
ComponentRegistry & getComponentRegistry(void)
Configures an AppBar, creates it and registers it in an entity registry.
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the app bar is placed.
Builder & withFixedWidth(float width)
Set the width of the app bar.
Builder & withElevated(bool elevated)
Choose the elevated look (Paper elevated).
Builder & addAction(const std::string &iconGlyphName)
Append a trailing action button without press handler.
std::shared_ptr< AppBar > makeAppBar(std::shared_ptr< ecs::Entity > parent, Variant variant)
Build an app bar, register it under parent and reset the builder.
Builder & withOnNavigation(std::function< void(void)> onPress, const std::string &accessibilityLabel="Navigate up")
Set the press handler of the navigation button (Paper Appbar.BackAction).
Builder & withNavigationIcon(const std::string &iconGlyphName)
Set the icon of the leading navigation button.
Builder & withTitle(const std::string &title)
Set the title text.
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Builder & withVariant(Variant variant)
Set the variant.
void reset(void) override
Restore the defaults.
std::shared_ptr< AppBar > buildEntity(void) override
Build an app bar and its children from the current configuration, without registering it or setting i...
A horizontal bar with a leading navigation icon button, a title and trailing action icon buttons.
std::shared_ptr< Text > getTitle(void) const
Get the title child.
AppBar & setVariant(Variant variant)
Change the variant.
static std::shared_ptr< AppBar > create(Arguments &&...arguments)
Create an app bar and its children, without registering it in an entity registry.
std::shared_ptr< IconButton > getActionButton(std::size_t index) const
Get a trailing action button.
static constexpr float HorizontalPadding
Padding around the children and spacing between them, in dp (Paper: 4 dp).
bool isElevated(void) const
Whether the app bar uses the elevated look.
Variant getVariant(void) const
Get the variant.
components::AppBar::Action Action
AppBar & setElevated(bool elevated)
Choose the elevated look (Paper elevated). Restyles at once.
~AppBar(void) override
Default destructor.
std::shared_ptr< IconButton > getNavigationButton(void) const
Get the leading navigation button.
AppBar & setTitle(const std::string &title)
Change the title text.
components::AppBar::Variant Variant
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Base of the widgets that are a rectangle containing other widgets (Card, Dialog, Checkbox,...
SurfaceBase & setChildren(const Children &children)
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 void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one app bar and arrange its children.
Makes the color helpers callable from guillaume::entities without qualification.
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.
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...