guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
navigation_bar.cpp
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#include "guillaume/components/navigation_bar.hpp"
24
25#include <utility>
26
28{
30 {
31 return _variant;
32 }
33
35 {
36 if (_variant != variant) {
37 _variant = variant;
38 setHasChanged(true);
39 }
40 return *this;
41 }
42
43 const std::vector<NavigationBar::Destination> &
44 NavigationBar::getDestinations(void) const noexcept
45 {
46 return _destinations;
47 }
48
50 const std::vector<Destination> &destinations)
51 {
52 if (_destinations != destinations) {
53 _destinations = destinations;
54 setHasChanged(true);
55 }
56 return *this;
57 }
58
60 {
61 _destinations.push_back(destination);
62 setHasChanged(true);
63 return *this;
64 }
65
67 const std::string &badge)
68 {
69 if (index < _destinations.size()
70 && _destinations[index].badge != badge) {
71 _destinations[index].badge = badge;
72 setHasChanged(true);
73 }
74 return *this;
75 }
76
77 const std::vector<ecs::Entity::Identifier> &
79 {
80 return _destinationEntities;
81 }
82
84 const std::vector<ecs::Entity::Identifier> &identifiers)
85 {
86 if (_destinationEntities != identifiers) {
87 _destinationEntities = identifiers;
88 setHasChanged(true);
89 }
90 return *this;
91 }
92
95 {
96 return _onIndexChange;
97 }
98
100 {
101 _onIndexChange = std::move(handler);
102 return *this;
103 }
104
106 NavigationBar::getOnTabPress(void) const noexcept
107 {
108 return _onTabPress;
109 }
110
112 {
113 _onTabPress = std::move(handler);
114 return *this;
115 }
116
117 bool NavigationBar::isUpdatingSelection(void) const noexcept
118 {
119 return _updatingSelection;
120 }
121
123 {
124 if (_updatingSelection != updating) {
125 _updatingSelection = updating;
126 setHasChanged(true);
127 }
128 return *this;
129 }
130} // namespace guillaume::components
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 & 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.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
State. Every class here is plain data attached to an entity.
Description of one destination, as given by the user.