guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
navigation_drawer.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
60 {
61 public:
72
81
87 struct Entry {
89 std::string icon {};
90 std::string label {};
91 std::string right {};
93 bool disabled { false };
95
101 bool operator==(const Entry &other) const = default;
102 };
103
105 using IndexHandler = std::function<void(std::size_t)>;
106
108 static constexpr float Width = 320.0f;
109
111 static constexpr float CollapsedWidth = 80.0f;
112
114 static constexpr float Height = 640.0f;
115
116 private:
117 Variant _variant { Variant::Standard };
118 std::vector<Entry> _entries {};
119 std::vector<ecs::Entity::Identifier>
120 _entryEntities {};
121 std::vector<ecs::Entity::Identifier>
122 _destinationEntities {};
123 std::vector<ecs::Entity::Identifier>
124 _sectionEntities {};
125 std::vector<ecs::Entity::Identifier>
126 _dividerEntities {};
127 ecs::Entity::Identifier _backdrop {
129 };
130
131 IndexHandler _onIndexChange {};
132 bool _updatingSelection { false };
133
134 public:
139 NavigationDrawer(void) = default;
140
144 ~NavigationDrawer(void) = default;
145
150 Variant getVariant(void) const noexcept;
151
160
165 const std::vector<Entry> &getEntries(void) const noexcept;
166
175 NavigationDrawer &setEntries(const std::vector<Entry> &entries);
176
188 NavigationDrawer &setDestinationDisabled(std::size_t index,
189 bool disabled);
190
195 std::size_t getDestinationCount(void) const noexcept;
196
202 const std::vector<ecs::Entity::Identifier> &
203 getEntryEntities(void) const noexcept;
204
213 const std::vector<ecs::Entity::Identifier> &identifiers);
214
219 const std::vector<ecs::Entity::Identifier> &
220 getDestinationEntities(void) const noexcept;
221
230 const std::vector<ecs::Entity::Identifier> &identifiers);
231
237 const std::vector<ecs::Entity::Identifier> &
238 getSectionEntities(void) const noexcept;
239
249 const std::vector<ecs::Entity::Identifier> &identifiers);
250
255 const std::vector<ecs::Entity::Identifier> &
256 getDividerEntities(void) const noexcept;
257
266 const std::vector<ecs::Entity::Identifier> &identifiers);
267
273 ecs::Entity::Identifier getBackdrop(void) const noexcept;
274
284
290 const IndexHandler &getOnIndexChange(void) const noexcept;
291
304
310 bool isUpdatingSelection(void) const noexcept;
311
323 };
324
325} // namespace guillaume::components
State of a divider: a thin horizontal line separating content.
Definition divider.hpp:59
@ Modal
that dims the content and closes it on a click.
@ Standard
Sheet docked beside the content, on surface.
const std::vector< ecs::Entity::Identifier > & getSectionEntities(void) const noexcept
Get the section header children.
static constexpr float Width
Width of a standard or modal drawer, in dp.
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.
static constexpr float CollapsedWidth
Width of a collapsed drawer (rail), in dp.
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.
static constexpr float Height
Height of the drawer, in dp.
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.
~NavigationDrawer(void)=default
Default destructor.
ecs::Entity::Identifier getBackdrop(void) const noexcept
Get the child that dims the content behind a modal drawer.
Base class of every component: a piece of state attached to an entity, plus a "changed" flag.
Definition component.hpp:72
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
static constexpr Identifier InvalidIdentifier
"No entity": never the identifier of a real entity
Definition entity.hpp:93
State. Every class here is plain data attached to an entity.
Description of one drawer entry, as given by the user.
std::string label
Destination label or section title.
bool operator==(const Entry &other) const =default
Compare two entries.
std::string icon
Icon glyph name of a destination.