Avara3D 0.2.0
C++ 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
29 class Panel {
30
31 public:
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
129 bool button(std::string_view label, Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
130
139 bool option(std::string_view label, bool selected, Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
140
149 bool subOption(std::string_view label, bool selected, Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
150
156 bool slider(std::string_view label,
157 float& value,
158 float minimum,
159 float maximum,
160 std::string_view format = "%.2f",
161 Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
162
168 bool slider(std::string_view label,
169 int& value,
170 int minimum,
171 int maximum,
172 std::string_view format = "%d",
173 Padding padding = {2.0f, 0.0f, 0.0f, 0.0f});
174
180 bool toggle(std::string_view label, bool& value, Padding padding = Padding::Default());
181
183 bool hovered() const;
184
185 private:
186 // [Private Member Functions]
187
188 float beginItem() const;
189 void endItem();
190 bool drawButton(std::string_view label, bool selected, Padding padding);
191
192 // [Private Member Variables]
193
194 std::string _windowName;
195 unsigned _rowItemsRemaining;
196 float _rowItemWidth;
197 float _rowSpacing;
198 bool _visible;
199 bool _hovered;
200 };
201
202}
203
204#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 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