v0.3.0 API Reference
Panel.h
1//
2// Panel.h
3// avara3d
4//
5// Created by Morgan Davis on 8/10/26.
6// Copyright © 2026 Morgan K Davis. All rights reserved.
7//
8
9#ifndef AVARA3D_UI_PANEL_H
10#define AVARA3D_UI_PANEL_H
11
12#include <optional>
13#include <string>
14#include <string_view>
15
16namespace a3d::ui {
17
29class Panel {
30
31public:
32 // [Public Types]
33
35 struct Options {
36 float width {260.0f};
37 float margin {12.0f};
38
45 static Options Default() {
46 return {0.0f, 0.0f};
47 }
48 };
49
51 struct Padding {
52 float top {0.0f};
53 float bottom {0.0f};
54 float left {0.0f};
55 float right {0.0f};
56
58 static Padding Default() {
59 return {0.0f, 0.0f, 0.0f, 0.0f};
60 }
61 };
62
65 bool line {true};
66 bool uppercase {false};
67
70 return {true, false};
71 }
72 };
73
74 // [Public Lifecycle Functions]
75
86 explicit Panel(std::string_view id, const Options& options = Options::Default());
87
88 Panel(const Panel&) = delete;
89 Panel& operator=(const Panel&) = delete;
90
91 Panel(Panel&&) = delete;
92 Panel& operator=(Panel&&) = delete;
93
94 ~Panel();
95
96 // [Public Member Functions]
97
99 void section(std::string_view text,
101 Padding padding = {12.0f, 4.0f, 0.0f, 0.0f});
102
104 void text(std::string_view text, Padding padding = Padding::Default());
105
107 void value(std::string_view label, std::string_view value, Padding padding = Padding::Default());
108
114 void spacer(float height);
115
122 void row(unsigned itemCount);
123
130 void segmentedRow(unsigned itemCount);
131
137 bool button(std::string_view label, Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
138
147 bool option(std::string_view label, bool selected, Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
148
157 bool subOption(std::string_view label, bool selected, Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
158
164 bool slider(std::string_view label,
165 float& value,
166 float minimum,
167 float maximum,
168 std::string_view format = "%.2f",
169 Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
170
176 bool slider(std::string_view label,
177 int& value,
178 int minimum,
179 int maximum,
180 std::string_view format = "%d",
181 Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
182
188 bool toggle(std::string_view label, bool& value, Padding padding = Padding::Default());
189
191 bool hovered() const;
192
193private:
194 // [Private Member Functions]
195
196 float beginItem() const;
197 void endItem();
198 bool drawButton(std::string_view label, bool selected, Padding padding);
199
200 // [Private Member Variables]
201
202 std::string _windowName;
203 unsigned _rowItemsRemaining;
204 unsigned _rowItemCount;
205 float _rowItemWidth;
206 float _rowSpacing;
207 bool _segmentedRow;
208 bool _visible;
209 bool _hovered;
210};
211
212} // namespace a3d::ui
213
214#endif // AVARA3D_UI_PANEL_H
Transient immediate-mode overlay panel for application controls and status.
Definition: Panel.h:29
bool slider(std::string_view label, float &value, float minimum, float maximum, std::string_view format="%.2f", Padding padding={2.0f, 0.0f, 0.0f, 0.0f})
Draws a floating-point slider and reports whether value changed.
void row(unsigned itemCount)
Arranges the next itemCount items horizontally with equal widths.
bool button(std::string_view label, Padding padding={2.0f, 0.0f, 0.0f, 0.0f})
Draws a button and reports activation once.
void text(std::string_view text, Padding padding=Padding::Default())
Draws body text, wrapping it to the available item width.
void segmentedRow(unsigned itemCount)
Arranges the next itemCount items as a contiguous horizontal segmented row.
void value(std::string_view label, std::string_view value, Padding padding=Padding::Default())
Draws a left-aligned label and right-aligned textual value.
bool slider(std::string_view label, int &value, int minimum, int maximum, std::string_view format="%d", Padding padding={2.0f, 0.0f, 0.0f, 0.0f})
Draws an integer slider and reports whether value changed.
bool toggle(std::string_view label, bool &value, Padding padding=Padding::Default())
Draws a boolean toggle and reports whether value changed.
void spacer(float height)
Inserts vertical space of height logical UI units.
bool hovered() const
Returns whether the pointer is hovering the panel during the current frame.
Panel(std::string_view id, const Options &options=Options::Default())
Begins an immediate-mode panel for the current frame.
bool subOption(std::string_view label, bool selected, Padding padding={2.0f, 0.0f, 0.0f, 0.0f})
Draws a visually subordinate selectable option button and reports activation once.
void section(std::string_view text, SectionConfig config=SectionConfig::Default(), Padding padding={12.0f, 4.0f, 0.0f, 0.0f})
Draws a section heading with optional separator line, capitalization, and padding.
bool option(std::string_view label, bool selected, Padding padding={2.0f, 0.0f, 0.0f, 0.0f})
Draws a selectable option button and reports activation once.
Controls panel width and its inset from the upper-right viewport corner.
Definition: Panel.h:35
float width
Panel width in logical UI units.
Definition: Panel.h:36
static Options Default()
Returns the Options value currently used as Panel's default argument.
Definition: Panel.h:45
float margin
Top and right viewport margin in logical UI units.
Definition: Panel.h:37
Per-item padding in logical UI units.
Definition: Panel.h:51
float left
Padding to the left of the item contents.
Definition: Panel.h:54
static Padding Default()
Returns zero padding on all sides.
Definition: Panel.h:58
float bottom
Padding below the item contents.
Definition: Panel.h:53
float right
Padding to the right of the item contents.
Definition: Panel.h:55
float top
Padding above the item contents.
Definition: Panel.h:52
Controls the optional separator line and capitalization of section headings.
Definition: Panel.h:64
static SectionConfig Default()
Returns the default section-heading configuration.
Definition: Panel.h:69
bool line
Draw a separator line beneath the heading when true.
Definition: Panel.h:65
bool uppercase
Convert the displayed heading to uppercase when true.
Definition: Panel.h:66