guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
navigation_drawer.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_drawer.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<NavigationDrawer::Entry> &
44 NavigationDrawer::getEntries(void) const noexcept
45 {
46 return _entries;
47 }
48
50 NavigationDrawer::setEntries(const std::vector<Entry> &entries)
51 {
52 if (_entries != entries) {
53 _entries = entries;
54 setHasChanged(true);
55 }
56 return *this;
57 }
58
61 bool disabled)
62 {
63 std::size_t destinationIndex = 0;
64
65 for (auto &entry: _entries) {
66 if (entry.kind != EntryKind::Destination) {
67 continue;
68 }
69 if (destinationIndex++ == index) {
70 if (entry.disabled != disabled) {
71 entry.disabled = disabled;
72 setHasChanged(true);
73 }
74 break;
75 }
76 }
77 return *this;
78 }
79
80 std::size_t NavigationDrawer::getDestinationCount(void) const noexcept
81 {
82 std::size_t count = 0;
83
84 for (const auto &entry: _entries) {
85 if (entry.kind == EntryKind::Destination) {
86 ++count;
87 }
88 }
89 return count;
90 }
91
92 const std::vector<ecs::Entity::Identifier> &
94 {
95 return _entryEntities;
96 }
97
99 const std::vector<ecs::Entity::Identifier> &identifiers)
100 {
101 if (_entryEntities != identifiers) {
102 _entryEntities = identifiers;
103 setHasChanged(true);
104 }
105 return *this;
106 }
107
108 const std::vector<ecs::Entity::Identifier> &
110 {
111 return _destinationEntities;
112 }
113
115 const std::vector<ecs::Entity::Identifier> &identifiers)
116 {
117 if (_destinationEntities != identifiers) {
118 _destinationEntities = identifiers;
119 setHasChanged(true);
120 }
121 return *this;
122 }
123
124 const std::vector<ecs::Entity::Identifier> &
126 {
127 return _sectionEntities;
128 }
129
131 const std::vector<ecs::Entity::Identifier> &identifiers)
132 {
133 if (_sectionEntities != identifiers) {
134 _sectionEntities = identifiers;
135 setHasChanged(true);
136 }
137 return *this;
138 }
139
140 const std::vector<ecs::Entity::Identifier> &
142 {
143 return _dividerEntities;
144 }
145
147 const std::vector<ecs::Entity::Identifier> &identifiers)
148 {
149 if (_dividerEntities != identifiers) {
150 _dividerEntities = identifiers;
151 setHasChanged(true);
152 }
153 return *this;
154 }
155
157 {
158 return _backdrop;
159 }
160
163 {
164 if (_backdrop != identifier) {
165 _backdrop = identifier;
166 setHasChanged(true);
167 }
168 return *this;
169 }
170
173 {
174 return _onIndexChange;
175 }
176
178 {
179 _onIndexChange = std::move(handler);
180 return *this;
181 }
182
184 {
185 return _updatingSelection;
186 }
187
189 {
190 if (_updatingSelection != updating) {
191 _updatingSelection = updating;
192 setHasChanged(true);
193 }
194 return *this;
195 }
196} // namespace guillaume::components
State of a navigation drawer: the side sheet that lists the destinations of an app,...
const std::vector< ecs::Entity::Identifier > & getSectionEntities(void) const noexcept
Get the section header children.
NavigationDrawer & setBackdrop(ecs::Entity::Identifier identifier)
Record the child that dims the content behind a modal drawer.
NavigationDrawer & setVariant(Variant variant)
Choose how the drawer is presented.
NavigationDrawer & setDestinationDisabled(std::size_t index, bool disabled)
Change the disabled flag recorded for one destination.
Variant getVariant(void) const noexcept
Get how the drawer is presented.
const IndexHandler & getOnIndexChange(void) const noexcept
Get the callback run when a press changes the selected destination.
std::function< void(std::size_t)> IndexHandler
Callback that receives a destination index, starting at 0.
NavigationDrawer & setEntries(const std::vector< Entry > &entries)
Replace the description of every entry.
const std::vector< ecs::Entity::Identifier > & getDestinationEntities(void) const noexcept
Get the destination children.
NavigationDrawer & setSectionEntities(const std::vector< ecs::Entity::Identifier > &identifiers)
Record the section header children.
NavigationDrawer(void)=default
Create the configuration of a standard drawer with no entry.
std::size_t getDestinationCount(void) const noexcept
Count the entries that are destinations.
NavigationDrawer & setEntryEntities(const std::vector< ecs::Entity::Identifier > &identifiers)
Record the child built for each entry, whatever its kind.
NavigationDrawer & setUpdatingSelection(bool updating)
Raise or lower the guard that stops a selection change from triggering another one.
const std::vector< ecs::Entity::Identifier > & getDividerEntities(void) const noexcept
Get the divider children.
NavigationDrawer & setOnIndexChange(IndexHandler handler)
Set the callback run when a press changes the selected destination.
const std::vector< Entry > & getEntries(void) const noexcept
Get the description of every entry.
NavigationDrawer & setDestinationEntities(const std::vector< ecs::Entity::Identifier > &identifiers)
Record the destination children.
NavigationDrawer & setDividerEntities(const std::vector< ecs::Entity::Identifier > &identifiers)
Record the divider children.
bool isUpdatingSelection(void) const noexcept
Tell whether systems::NavigationDrawer is changing the selection at this moment.
const std::vector< ecs::Entity::Identifier > & getEntryEntities(void) const noexcept
Get the child built for each entry, whatever its kind.
ecs::Entity::Identifier getBackdrop(void) const noexcept
Get the child that dims the content behind a modal drawer.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
Definition component.cpp:32
std::size_t Identifier
The key under which an entity's components are stored. Systems and components refer to entities by th...
Definition entity.hpp:86
State. Every class here is plain data attached to an entity.