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 <utility>
26#include <functional>
27#include <memory>
28#include <string>
29#include <vector>
30
31#include <utility/graphic/color.hpp>
32#include <utility/graphic/pose.hpp>
33
34#include "guillaume/ecs/component_registry.hpp"
35#include "guillaume/ecs/entity_builder.hpp"
36
37#include "guillaume/components/app_bar.hpp"
38#include "guillaume/components/elevation.hpp"
39#include "guillaume/entities/icon.hpp"
40#include "guillaume/entities/icon_button.hpp"
41#include "guillaume/entities/builder_base.hpp"
42#include "guillaume/entities/surface.hpp"
43#include "guillaume/entities/text.hpp"
44
46{
47
91 class AppBar: public SurfaceBase<components::Elevation, components::AppBar>
92 {
93 public:
97
101
106 class Builder: public EntityBuilderBase<AppBar>
107 {
108 private:
109 SurfaceConfig _config;
110 Variant _variant { Variant::Small };
111 std::string _title {};
112 Action _navigation {};
113 std::vector<Action> _actions {};
114 bool _elevated { false };
115
116 public:
123 Builder(ecs::ComponentRegistry &componentRegistry,
124 ecs::EntityRegistry &entityRegistry);
125
131 std::shared_ptr<AppBar> buildEntity(void) override;
132
139 void reset(void) override;
140
147 Builder &withPose(const utility::graphic::PoseF &pose);
148
155 Builder &withVariant(Variant variant);
156
163 Builder &withTitle(const std::string &title);
164
175 Builder &withNavigationIcon(const std::string &iconGlyphName);
176
184 Builder &addAction(const std::string &iconGlyphName);
185
195 Builder &addAction(const std::string &iconGlyphName,
196 std::function<void(void)> onPress,
197 const std::string &accessibilityLabel = "");
198
211 std::function<void(void)> onPress,
212 const std::string &accessibilityLabel = "Navigate up");
213
220 Builder &withElevated(bool elevated);
221
227 Builder &withFixedWidth(float width);
228
240 std::shared_ptr<AppBar>
241 makeAppBar(std::shared_ptr<ecs::Entity> parent,
242 Variant variant);
243 };
244
261 template<typename... Arguments>
262 static std::shared_ptr<AppBar> create(Arguments &&...arguments)
263 {
264 std::shared_ptr<AppBar> entity(
265 new AppBar(std::forward<Arguments>(arguments)...));
266 entity->build();
267 return entity;
268 }
269
273 ~AppBar(void) override;
274
283 AppBar &setVariant(Variant variant);
284
289 Variant getVariant(void) const;
290
300 AppBar &setTitle(const std::string &title);
301
309 AppBar &setElevated(bool elevated);
310
315 bool isElevated(void) const;
316
322 std::shared_ptr<IconButton> getNavigationButton(void) const;
323
330 std::shared_ptr<IconButton> getActionButton(std::size_t index) const;
331
337 std::shared_ptr<Text> getTitle(void) const;
338
343 static constexpr float HorizontalPadding =
345
346 private:
354 std::shared_ptr<IconButton> buildAction(const Action &action);
355
363 void buildContent(void);
364
365 private:
380 AppBar(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
381 Variant variant, const std::string &title,
382 const std::string &navigationIcon,
383 const std::vector<std::string> &actions);
384
399 AppBar(ecs::ComponentRegistry &registry, const SurfaceConfig &config,
400 Variant variant, const std::string &title,
401 const Action &navigation, const std::vector<Action> &actions,
402 bool elevated);
403
410 void build(void);
411 };
412
413} // namespace guillaume::entities
Variant
Shape of the bar. It sets the height and the title size.
Definition app_bar.hpp:64
static constexpr float HorizontalPadding
Padding on each side of the bar and gap between its children, in dp.
Definition app_bar.hpp:85
Stores every component of a scene, per component type and per entity identifier, and knows which ones...
Owns entities and gives the systems the list of entities to visit.
Builder & withPose(const utility::graphic::PoseF &pose)
Set where the app bar is placed.
Definition app_bar.cpp:69
Builder & withFixedWidth(float width)
Set the width of the app bar.
Definition app_bar.cpp:131
Builder & withElevated(bool elevated)
Choose the elevated look (Paper elevated).
Definition app_bar.cpp:125
Builder & addAction(const std::string &iconGlyphName)
Append a trailing action button without press handler.
Definition app_bar.cpp:98
std::shared_ptr< AppBar > makeAppBar(std::shared_ptr< ecs::Entity > parent, Variant variant)
Build an app bar, register it under parent and reset the builder.
Definition app_bar.cpp:139
Builder & withOnNavigation(std::function< void(void)> onPress, const std::string &accessibilityLabel="Navigate up")
Set the press handler of the navigation button (Paper Appbar.BackAction).
Definition app_bar.cpp:117
Builder & withNavigationIcon(const std::string &iconGlyphName)
Set the icon of the leading navigation button.
Definition app_bar.cpp:88
Builder & withTitle(const std::string &title)
Set the title text.
Definition app_bar.cpp:81
Builder(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
Create a builder set to the defaults of reset().
Definition app_bar.cpp:36
Builder & withVariant(Variant variant)
Set the variant.
Definition app_bar.cpp:75
void reset(void) override
Restore the defaults.
Definition app_bar.cpp:51
std::shared_ptr< AppBar > buildEntity(void) override
Build an app bar and its children from the current configuration, without registering it or setting i...
Definition app_bar.cpp:43
A horizontal bar with a leading navigation icon button, a title and trailing action icon buttons.
Definition app_bar.hpp:92
std::shared_ptr< Text > getTitle(void) const
Get the title child.
Definition app_bar.cpp:309
AppBar & setVariant(Variant variant)
Change the variant.
Definition app_bar.cpp:260
static std::shared_ptr< AppBar > create(Arguments &&...arguments)
Create an app bar and its children, without registering it in an entity registry.
Definition app_bar.hpp:262
std::shared_ptr< IconButton > getActionButton(std::size_t index) const
Get a trailing action button.
Definition app_bar.cpp:295
static constexpr float HorizontalPadding
Padding around the children and spacing between them, in dp (Paper: 4 dp).
Definition app_bar.hpp:343
bool isElevated(void) const
Whether the app bar uses the elevated look.
Definition app_bar.cpp:278
Variant getVariant(void) const
Get the variant.
Definition app_bar.cpp:317
components::AppBar::Action Action
Definition app_bar.hpp:100
AppBar & setElevated(bool elevated)
Choose the elevated look (Paper elevated). Restyles at once.
Definition app_bar.cpp:269
~AppBar(void) override
Default destructor.
Definition app_bar.cpp:185
std::shared_ptr< IconButton > getNavigationButton(void) const
Get the leading navigation button.
Definition app_bar.cpp:285
AppBar & setTitle(const std::string &title)
Change the title text.
Definition app_bar.cpp:324
components::AppBar::Variant Variant
Definition app_bar.hpp:96
EntityBuilderBase(ecs::ComponentRegistry &componentRegistry, ecs::EntityRegistry &entityRegistry)
SurfaceBase(ecs::ComponentRegistry &registry, const SurfaceConfig &config)
Widgets: the classes used to create entities with the right components and children.
Definition app_bar.hpp:46
One pressable icon of the bar: the leading navigation icon or a trailing action.
Definition app_bar.hpp:70
Everything needed to set up a surface in one value: where it is, how it looks and how it arranges its...
Definition surface.hpp:71