Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
widgets.hpp
Go to the documentation of this file.
1
3#pragma once
4
9#include <aegis2d/ui/export.hpp>
10#include <aegis2d/ui/menu.hpp>
12
13#include <cstddef>
14#include <cstdint>
15#include <optional>
16#include <span>
17#include <string>
18#include <vector>
19
20namespace aegis2d::ui {
21
25 float min = 0.0F;
27 float max = 1.0F;
29 float step = 0.1F;
31 float value = 0.0F;
32};
33
53
65class AEGIS2D_UI_EXPORT Slider {
66public:
74 Slider(WidgetTree& tree, render::Rect bounds, const SliderConfig& config,
75 WidgetId group = root);
76
79 [[nodiscard]] WidgetId id() const noexcept;
80
83 [[nodiscard]] const SliderConfig& config() const noexcept;
84
87 [[nodiscard]] float value() const noexcept;
88
91 void set_value(float value) noexcept;
92
101 bool update(Navigation& navigation, const WidgetTree& tree);
102
107 void draw(render::IRenderer& renderer, const WidgetTree& tree,
108 const SliderStyle& style = {}) const;
109
110private:
111 SliderConfig config_;
112 WidgetId id_ = root;
113 float value_ = 0.0F;
114};
115
137
151class AEGIS2D_UI_EXPORT ListView {
152public:
161 ListView(WidgetTree& tree, render::Rect bounds, std::vector<std::string> items,
162 std::size_t visible, WidgetId group = root);
163
166 [[nodiscard]] WidgetId id() const noexcept;
167
170 [[nodiscard]] std::span<const std::string> items() const noexcept;
171
174 [[nodiscard]] std::size_t selected() const noexcept;
175
179 void select(std::size_t item);
180
183 [[nodiscard]] std::size_t top() const noexcept;
184
187 [[nodiscard]] std::size_t visible() const noexcept;
188
197 std::optional<std::size_t> update(Navigation& navigation, const WidgetTree& tree);
198
204 void draw(render::IRenderer& renderer, const WidgetTree& tree, const render::BitmapFont& font,
205 const ListStyle& style = {}) const;
206
207private:
208 void show_selection() noexcept;
209
210 std::vector<std::string> items_;
211 WidgetId id_ = root;
212 std::size_t visible_ = 1;
213 std::size_t selected_ = 0;
214 std::size_t top_ = 0;
215};
216
217} // namespace aegis2d::ui
Text drawn with a bitmap font, through the sprite batcher.
A scrollable list of items, one selected, as a widget of a WidgetTree.
Definition widgets.hpp:151
WidgetId id() const noexcept
The list's widget in its tree.
ListView(WidgetTree &tree, render::Rect bounds, std::vector< std::string > items, std::size_t visible, WidgetId group=root)
Adds the list to a tree.
A value picked between two bounds, as a widget of a WidgetTree.
Definition widgets.hpp:65
Slider(WidgetTree &tree, render::Rect bounds, const SliderConfig &config, WidgetId group=root)
Adds the slider to a tree.
WidgetId id() const noexcept
The slider's widget in its tree.
Widgets of a menu or a form, in groups, and which one has the focus.
Definition widget_tree.hpp:72
RGBA color used by the renderer.
Vector and matrix types of the engine (GLM behind engine names).
Buttons and labels of a menu, their states, and how they are drawn.
constexpr Color rgb(std::uint32_t hex, float alpha=1.0F) noexcept
Color from its hexadecimal sRGB code, as design tools and palettes give it.
Definition color.hpp:25
Menus and forms: widgets and their focus, moved by keyboard, gamepad and mouse (client only).
Definition console.hpp:21
std::size_t WidgetId
Identifier of a widget in its WidgetTree, given by WidgetTree::add().
Definition widget_tree.hpp:18
constexpr WidgetId root
The root group of every tree, which the other widgets go under.
Definition widget_tree.hpp:21
Definition endpoint.hpp:85
Backend-independent renderer interface and the sprite it draws.
RGBA color with components in [0, 1].
Definition color.hpp:10
Axis-aligned rectangle.
Definition renderer.hpp:20
Colors, text size and layer of a ListView.
Definition widgets.hpp:117
render::Color selected
Background of the selected row.
Definition widgets.hpp:121
render::Color disabled
Text and rows of a disabled list.
Definition widgets.hpp:125
std::int32_t layer
Layer of the rows; the text and the scrollbar go one layer above.
Definition widgets.hpp:135
render::Color outline
Outline around the focused list.
Definition widgets.hpp:127
render::Color scrollbar
The scrollbar on the right edge, shown when some items are off screen.
Definition widgets.hpp:129
float text_scale
Scale of the text at 100%, multiplied by the tree's scale.
Definition widgets.hpp:133
render::Color background
Background of the rows.
Definition widgets.hpp:119
render::Color text
Text of the rows.
Definition widgets.hpp:123
float outline_width
Width of the outline and the scrollbar, in logical pixels at 100%.
Definition widgets.hpp:131
What the player asked of the focus during a frame.
Definition widget_tree.hpp:37
Range, step and starting value of a Slider.
Definition widgets.hpp:23
float step
How much one Left or Right moves the value, above 0.
Definition widgets.hpp:29
float value
Starting value, clamped between min and max.
Definition widgets.hpp:31
float max
Value at the right end, above min.
Definition widgets.hpp:27
float min
Value at the left end.
Definition widgets.hpp:25
Colors and layer of a Slider.
Definition widgets.hpp:37
std::int32_t layer
Layer of the track; the fill and the handle go one layer above.
Definition widgets.hpp:51
float outline_width
Width of the outline, in logical pixels at 100%.
Definition widgets.hpp:49
render::Color fill
The filled part of the track, up to the value.
Definition widgets.hpp:41
render::Color outline
Outline around the focused slider.
Definition widgets.hpp:47
render::Color disabled
Track, fill and handle of a disabled slider.
Definition widgets.hpp:45
render::Color handle
The handle at the value.
Definition widgets.hpp:43
render::Color track
The groove the handle slides in.
Definition widgets.hpp:39
Widgets of a menu or a form, and which one has the focus.