guillaume 2026.6.1
A C++ UI framework designed for modern desktop and extended reality (XR) applications.
Loading...
Searching...
No Matches
app_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 <functional>
26#include <string>
27#include <vector>
28
29#include "guillaume/ecs/component.hpp"
30#include "guillaume/ecs/entity.hpp"
31
33{
34
53 class AppBar: public ecs::Component
54 {
55 public:
64 enum class Variant { Small, CenterAligned, Medium, Large, Bottom };
65
70 struct Action {
71 std::string icon {};
72 std::function<void(void)> onPress {};
73 std::string accessibilityLabel {};
75 bool disabled { false };
76 };
77
79 using Identifiers = std::vector<ecs::Entity::Identifier>;
80
85 static constexpr float HorizontalPadding = 4.0f;
86
87 private:
88 Variant _variant { Variant::Small };
89 std::string _title {};
90 Action _navigation {};
91 std::vector<Action> _actions {};
92 bool _elevated { false };
93 ecs::Entity::Identifier _navigationButton {
95 };
96
97 ecs::Entity::Identifier _titleEntity {
99 };
100
101 Identifiers _actionButtons {};
102
103 public:
108 AppBar(void) = default;
109
113 ~AppBar(void) = default;
114
119 Variant getVariant(void) const noexcept;
120
129 AppBar &setVariant(Variant variant);
130
135 const std::string &getTitle(void) const noexcept;
136
145 AppBar &setTitle(const std::string &title);
146
151 const Action &getNavigation(void) const noexcept;
152
162 AppBar &setNavigation(Action navigation);
163
168 const std::vector<Action> &getActions(void) const noexcept;
169
178 AppBar &setActions(std::vector<Action> actions);
179
185 bool isElevated(void) const noexcept;
186
196 AppBar &setElevated(bool elevated);
197
203 ecs::Entity::Identifier getNavigationButton(void) const noexcept;
204
215
221 ecs::Entity::Identifier getTitleEntity(void) const noexcept;
222
232
239 const Identifiers &getActionButtons(void) const noexcept;
240
251 AppBar &setActionButtons(const Identifiers &identifiers);
252 };
253
254} // namespace guillaume::components
ecs::Entity::Identifier getNavigationButton(void) const noexcept
Get the icon button child built for the navigation action.
Definition app_bar.cpp:97
Variant getVariant(void) const noexcept
Get the shape of the bar.
Definition app_bar.cpp:29
AppBar & setTitleEntity(ecs::Entity::Identifier identifier)
Record the text child that displays the title.
Definition app_bar.cpp:116
AppBar(void)=default
Create the configuration of a small, flat bar with no title and no icon.
AppBar & setVariant(Variant variant)
Set the shape of the bar, which decides its height and the size of its title.
Definition app_bar.cpp:34
bool isElevated(void) const noexcept
Tell whether the bar is elevated.
Definition app_bar.cpp:83
AppBar & setElevated(bool elevated)
Raise or flatten the bar.
Definition app_bar.cpp:88
ecs::Entity::Identifier getTitleEntity(void) const noexcept
Get the text child that displays the title.
Definition app_bar.cpp:111
~AppBar(void)=default
Default destructor.
const Identifiers & getActionButtons(void) const noexcept
Get the icon button children built for the trailing actions.
Definition app_bar.cpp:125
std::vector< ecs::Entity::Identifier > Identifiers
Identifiers of child entities, in display order.
Definition app_bar.hpp:79
AppBar & setNavigationButton(ecs::Entity::Identifier identifier)
Record the icon button child built for the navigation action.
Definition app_bar.cpp:102
const std::string & getTitle(void) const noexcept
Get the title shown in the bar.
Definition app_bar.cpp:43
AppBar & setActionButtons(const Identifiers &identifiers)
Record the icon button children built for the trailing actions.
Definition app_bar.cpp:130
Variant
Shape of the bar. It sets the height and the title size.
Definition app_bar.hpp:64
AppBar & setTitle(const std::string &title)
Set the title shown in the bar.
Definition app_bar.cpp:48
AppBar & setNavigation(Action navigation)
Set the leading navigation action.
Definition app_bar.cpp:62
AppBar & setActions(std::vector< Action > actions)
Replace the trailing actions.
Definition app_bar.cpp:75
const Action & getNavigation(void) const noexcept
Get the leading navigation action (back arrow, menu icon).
Definition app_bar.cpp:57
static constexpr float HorizontalPadding
Padding on each side of the bar and gap between its children, in dp.
Definition app_bar.hpp:85
const std::vector< Action > & getActions(void) const noexcept
Get the trailing actions.
Definition app_bar.cpp:70
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.
One pressable icon of the bar: the leading navigation icon or a trailing action.
Definition app_bar.hpp:70
bool disabled
True when the icon ignores input.
Definition app_bar.hpp:75
std::function< void(void)> onPress
Called on press.
Definition app_bar.hpp:72
std::string icon
Icon glyph name; empty means no icon.
Definition app_bar.hpp:71