guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
navigation_bar.hpp
1/*
2 Copyright (c) 2026 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include <cstddef>
26#include <functional>
27#include <string>
28#include <vector>
29
30#include "guillaume/ecs/component.hpp"
31#include "guillaume/ecs/entity.hpp"
32
34{
35
56 {
57 public:
62 enum class Variant { WithLabels, WithoutLabels };
63
67 struct Destination {
68 std::string icon;
69 std::string label;
70 std::string focusedIcon;
72 std::string badge;
73
79 bool operator==(const Destination &other) const = default;
80 };
81
83 using IndexHandler = std::function<void(std::size_t)>;
84
86 static constexpr float Height = 80.0f;
87
88 private:
89 Variant _variant { Variant::WithLabels };
90 std::vector<Destination> _destinations {};
91 std::vector<ecs::Entity::Identifier>
92 _destinationEntities {};
93 IndexHandler _onIndexChange {};
94 IndexHandler _onTabPress {};
95 bool _updatingSelection { false };
96
97 public:
102 NavigationBar(void) = default;
103
107 ~NavigationBar(void) = default;
108
113 Variant getVariant(void) const noexcept;
114
123
128 const std::vector<Destination> &getDestinations(void) const noexcept;
129
139 setDestinations(const std::vector<Destination> &destinations);
140
149 NavigationBar &addDestination(const Destination &destination);
150
162 NavigationBar &setDestinationBadge(std::size_t index,
163 const std::string &badge);
164
170 const std::vector<ecs::Entity::Identifier> &
171 getDestinationEntities(void) const noexcept;
172
183 const std::vector<ecs::Entity::Identifier> &identifiers);
184
190 const IndexHandler &getOnIndexChange(void) const noexcept;
191
203
208 const IndexHandler &getOnTabPress(void) const noexcept;
209
220
226 bool isUpdatingSelection(void) const noexcept;
227
238 NavigationBar &setUpdatingSelection(bool updating);
239 };
240
241} // namespace guillaume::components
static constexpr float Height
Height of the bar, in dp.
NavigationBar & setVariant(Variant variant)
Choose whether every destination shows its label.
NavigationBar(void)=default
Create the configuration of a bar with labels and no destination.
NavigationBar & setDestinationBadge(std::size_t index, const std::string &badge)
Change the badge text recorded for one destination.
~NavigationBar(void)=default
Default destructor.
NavigationBar & setOnIndexChange(IndexHandler handler)
Set the callback run when a press changes the selected destination.
NavigationBar & addDestination(const Destination &destination)
Append the description of one destination.
const IndexHandler & getOnIndexChange(void) const noexcept
Get the callback run when a press changes the selected destination.
const IndexHandler & getOnTabPress(void) const noexcept
Get the callback run on every destination press.
Variant
Whether every destination shows its label (WithLabels) or only the selected one does (WithoutLabels).
Variant getVariant(void) const noexcept
Get the label visibility rule.
bool isUpdatingSelection(void) const noexcept
Tell whether systems::NavigationBar is changing the selection at this moment.
NavigationBar & setUpdatingSelection(bool updating)
Raise or lower the guard that stops a selection change from triggering another one.
NavigationBar & setDestinationEntities(const std::vector< ecs::Entity::Identifier > &identifiers)
Record the destination children.
std::function< void(std::size_t)> IndexHandler
Callback that receives the index of a destination, starting at 0.
NavigationBar & setOnTabPress(IndexHandler handler)
Set the callback run on every destination press.
const std::vector< ecs::Entity::Identifier > & getDestinationEntities(void) const noexcept
Get the destination children.
NavigationBar & setDestinations(const std::vector< Destination > &destinations)
Replace the description of every destination.
const std::vector< Destination > & getDestinations(void) const noexcept
Get the description of every destination.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
State. Every class here is plain data attached to an entity.
Description of one destination, as given by the user.
std::string icon
Icon glyph name while not selected.
std::string badge
Badge text; empty means no badge.
bool operator==(const Destination &other) const =default
Compare two destinations.