23#include "guillaume/entities/navigation_drawer_destination.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_drawer_destination.hpp"
36#include "guillaume/theme.hpp"
38namespace guillaume::entities::detail
50 std::shared_ptr<View> makeGroup(ecs::ComponentRegistry ®istry,
51 ecs::EntityRegistry &entityRegistry,
52 std::shared_ptr<ecs::Entity> parent,
55 View::Builder builder(registry, entityRegistry);
57 builder.makeDefaultView(parent, utility::graphic::PoseF(), {});
60 view->setMainAxisAlignment(
62 view->setCrossAxisAlignment(
64 view->setPadding(0.0f);
75 identifierOf(
const std::shared_ptr<ecs::Entity> &child)
77 return child !=
nullptr ? child->getIdentifier()
82 DrawerDestination::DrawerDestination(ecs::ComponentRegistry ®istry,
84 bool collapsed,
float width)
85 : ecs::ParentEntityFiller<components::
Layout, components::Transform,
86 components::Bound, components::Color,
87 components::Borders, components::Selectable,
88 components::NavigationDrawerDestination>(
91 getComponentRegistry()
92 .getComponent<components::NavigationDrawerDestination>(
95 .setLabel(entry.label)
96 .setRight(entry.right)
97 .setDisabled(entry.disabled)
98 .setCollapsed(collapsed);
99 getComponentRegistry()
100 .getComponent<components::Layout>(getIdentifier())
101 .setFixedWidth(width);
102 systems::NavigationDrawerDestination::install(getComponentRegistry(),
104 systems::NavigationDrawerDestination::apply(getComponentRegistry(),
108 void DrawerDestination::build(
void)
110 auto ®istry = getComponentRegistry();
113 registry.getComponent<components::NavigationDrawerDestination>(
116 if (entry.getLead() == ecs::Entity::InvalidIdentifier) {
117 const auto lead = makeGroup(registry, *
this, shared_from_this(),
118 components::Layout::Axis::Horizontal);
120 buildIcon(registry, *lead, lead, entry.getIcon(),
121 components::NavigationDrawerDestination::IconSize,
123 std::shared_ptr<Text> label;
124 std::shared_ptr<Text> right;
125 std::vector<std::shared_ptr<ecs::Entity>> content;
127 if (icon !=
nullptr) {
128 content.push_back(icon);
131 if (entry.isCollapsed()) {
135 lead->setFixedWidth(components::NavigationDrawerDestination::
136 CollapsedIndicatorWidth);
137 lead->setFixedHeight(components::NavigationDrawerDestination::
138 CollapsedIndicatorHeight);
140 buildText(registry, *
this, shared_from_this(),
141 entry.getLabel(), theme::TypeRole::LabelMedium,
147 buildText(registry, *lead, lead, entry.getLabel(),
148 theme::TypeRole::LabelLarge,
150 if (label !=
nullptr) {
151 content.push_back(label);
154 buildText(registry, *
this, shared_from_this(),
155 entry.getRight(), theme::TypeRole::LabelLarge,
158 if (!content.empty() || !entry.isCollapsed()) {
159 lead->setEntities(content);
163 .getComponent<components::NavigationDrawerDestination>(
165 .setLead(lead->getIdentifier())
166 .setIconEntity(identifierOf(icon))
167 .setLabelEntity(identifierOf(label))
168 .setRightEntity(identifierOf(right));
171 systems::NavigationDrawerDestination::apply(registry, getIdentifier());
199 .setOnSelectionChangedHandler(handler);
@ Center
Packed in the middle.
Axis
Direction along which children are arranged.
State of one destination of a navigation drawer: an icon, a label and an optional text at the trailin...
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...
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
ComponentRegistry & getComponentRegistry(void)
components::NavigationDrawer::Entry Entry
void setDisabled(bool disabled)
Enable or disable the destination. Restyles at once.
bool isSelected(void) const
Whether the destination is the selected one of its drawer.
void setOnPress(std::function< void(void)> onPress)
Set the handler called when the user presses the destination while it is enabled.
ecs::Entity::Identifier getRightIdentifier(void) const
Get the trailing text entity.
void setOnSelectionChanged(const components::Selectable::Handler &handler)
Set the handler of the destination's components::Selectable.
bool isDisabled(void) const
Whether the destination ignores presses.
static bool isDisabled(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the destination ignores input.
static void setDisabled(ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier, bool disabled)
Enable or disable the destination and restyle it.
static bool isSelected(const ecs::ComponentRegistry &componentRegistry, const ecs::Entity::Identifier &entityIdentifier)
Whether the destination is the selected one.
static constexpr float get(unsigned int steps)
Get a spacing as a number of grid units.
Makes the color helpers callable from guillaume::entities without qualification.
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.
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 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.