23#include "guillaume/entities/navigation_bar_destination.hpp"
28#include "guillaume/entities/badge.hpp"
29#include "guillaume/entities/builder_base.hpp"
30#include "guillaume/entities/content_helpers.hpp"
31#include "guillaume/entities/icon.hpp"
33#include "guillaume/entities/text.hpp"
34#include "guillaume/entities/view.hpp"
35#include "guillaume/systems/navigation_bar_destination.hpp"
36#include "guillaume/theme.hpp"
38namespace guillaume::entities::detail
40 BarDestination::BarDestination(ecs::ComponentRegistry ®istry,
42 : ecs::ParentEntityFiller<components::
Layout, components::Transform,
43 components::Bound, components::Color,
44 components::Borders, components::Selectable,
45 components::NavigationBarDestination>(
48 getComponentRegistry()
49 .getComponent<components::NavigationBarDestination>(getIdentifier())
51 .setFocusedIcon(spec.focusedIcon)
53 .setBadge(spec.badge);
54 systems::NavigationBarDestination::install(getComponentRegistry(),
56 systems::NavigationBarDestination::apply(getComponentRegistry(),
60 void BarDestination::build(
void)
62 auto ®istry = getComponentRegistry();
65 registry.getComponent<components::NavigationBarDestination>(
68 if (spec.getIndicator() == ecs::Entity::InvalidIdentifier) {
69 View::Builder pillBuilder(registry, *
this);
70 const auto pill = pillBuilder.makeDefaultView(
71 shared_from_this(), utility::graphic::PoseF(), {});
74 pill->setAxis(components::Layout::Axis::Horizontal);
75 pill->setMainAxisAlignment(
76 components::Layout::MainAxisAlignment::Center);
77 pill->setCrossAxisAlignment(
78 components::Layout::CrossAxisAlignment::Center);
79 pill->setPadding(0.0f);
81 components::NavigationBarDestination::IndicatorWidth);
83 components::NavigationBarDestination::IndicatorHeight);
86 buildIcon(registry, *pill, pill, spec.getIcon(),
87 components::NavigationBarDestination::IconSize,
89 if (icon !=
nullptr) {
90 pill->setEntities({ icon });
94 buildText(registry, *
this, shared_from_this(), spec.getLabel(),
95 theme::TypeRole::LabelMedium,
99 .getComponent<components::NavigationBarDestination>(
101 .setIndicator(pill->getIdentifier())
102 .setIconEntity(icon !=
nullptr ? icon->getIdentifier()
103 : ecs::Entity::InvalidIdentifier)
104 .setLabelEntity(label !=
nullptr
105 ? label->getIdentifier()
106 : ecs::Entity::InvalidIdentifier);
110 systems::NavigationBarDestination::apply(registry, getIdentifier());
113 void BarDestination::buildBadge(
void)
116 if (weak_from_this().expired()) {
120 auto ®istry = getComponentRegistry();
123 registry.getComponent<components::NavigationBarDestination>(
126 if (spec.getBadgeEntity() != ecs::Entity::InvalidIdentifier
127 || spec.getBadge().empty()) {
131 const auto pill = getEntity<View>(spec.getIndicator());
132 if (pill ==
nullptr) {
136 Badge::Builder builder(registry, *pill);
137 const auto badge = builder.withVariant(Badge::Variant::Large)
138 .withLabel(spec.getBadge())
139 .registerEntity(pill);
140 if (badge !=
nullptr) {
142 .getComponent<components::NavigationBarDestination>(
144 .setBadgeEntity(badge->getIdentifier());
180 .setOnSelectionChangedHandler(handler);
State of one destination of a navigation bar: an icon in a pill, a label under it and an optional bad...
Selected/unselected flag of an entity, with a callback run when it changes.
std::function< void(bool)> Handler
Callback receiving the new state: true when just selected.
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...
ComponentRegistry & getComponentRegistry(void)
components::NavigationBar::Destination Destination
void setOnPress(std::function< void(void)> onPress)
Set the handler called when the user presses the destination.
void setOnSelectionChanged(const components::Selectable::Handler &handler)
Set the handler of the destination's components::Selectable.
ecs::Entity::Identifier getLabelIdentifier(void) const
Get the label entity.
bool isSelected(void) const
Whether the destination is the selected one of its bar.
ecs::Entity::Identifier getIconIdentifier(void) const
Get the icon entity.
ecs::Entity::Identifier getIndicatorIdentifier(void) const
Get the active-indicator pill: the rounded shape behind the icon.
void setShowLabel(bool show)
Show or hide the label. Restyles at once.
ecs::Entity::Identifier getBadgeIdentifier(void) const
Get the badge entity.
void setBadge(const std::string &badge)
Change the badge label.
static bool isSelected(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the destination is the selected one.
static void apply(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Style one destination from its selection and interaction state, then arrange it.
Makes the color helpers callable from guillaume::entities without qualification.
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.
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.
utility::graphic::Color32Bit transparentColor(void)
The color written to hide a fill or an outline without removing its component.
utility::graphic::Color32Bit schemeColor(SchemeColorRole role)
Look up a color role in the color scheme of the active theme.
float getShapeRadius(theme::ShapeRole role)
Get the corner radius the active theme gives to a shape role.