26 float x{0.0f}, y{0.0f};
28 inline Vec2 operator+(
Vec2 a,
Vec2 b) {
return {a.x + b.x, a.y + b.y}; }
29 inline Vec2 operator-(
Vec2 a,
Vec2 b) {
return {a.x - b.x, a.y - b.y}; }
30 inline Vec2 operator*(
Vec2 a,
float k) {
return {a.x * k, a.y * k}; }
35 float x{0.0f}, y{0.0f}, z{0.0f};
41 float x{0.0f}, y{0.0f}, z{0.0f}, w{1.0f};
47 float x{0.0f}, y{0.0f}, width{0.0f}, height{0.0f};
52 return p.x >= x && p.x <= x + width && p.y >= y && p.y <= y + height;
55 Vec2 center()
const {
return {x + width * 0.5f, y + height * 0.5f}; }
63 float top{0.0f}, right{0.0f}, bottom{0.0f}, left{0.0f};
67 return top == 0.0f && right == 0.0f && bottom == 0.0f && left == 0.0f;
71 return top == o.top && right == o.right && bottom == o.bottom && left == o.left;
73 bool operator!=(
const EdgeInsets &o)
const {
return !(*
this == o); }
79 uint8_t r{255}, g{255}, b{255}, a{255};
87 float f = std::clamp(k, 0.0f, 1.0f);
88 return {r, g, b,
static_cast<uint8_t
>(std::lround(a * f))};
90 bool operator==(
const Color &o)
const {
return r == o.r && g == o.g && b == o.b && a == o.a; }
91 bool operator!=(
const Color &o)
const {
return !(*
this == o); }
97 inline constexpr Color White{255, 255, 255, 255};
98 inline constexpr Color Black{0, 0, 0, 255};
99 inline constexpr Color Blank{0, 0, 0, 0};
100 inline constexpr Color Red{230, 41, 55, 255};
101 inline constexpr Color Maroon{190, 33, 55, 255};
102 inline constexpr Color Green{0, 228, 48, 255};
103 inline constexpr Color DarkGreen{0, 117, 44, 255};
104 inline constexpr Color Blue{0, 121, 241, 255};
105 inline constexpr Color Yellow{253, 249, 0, 255};
106 inline constexpr Color Gray{130, 130, 130, 255};
107 inline constexpr Color DarkGray{80, 80, 80, 255};
108 inline constexpr Color LightGray{200, 200, 200, 255};
121 Color color{255, 255, 255, 255};
123 static_assert(
sizeof(
Vertex2D) == 20,
"Vertex2D must stay tightly packed (20 bytes)");
129 int width{0}, height{0};
130 bool valid()
const {
return id != 0; }
137 bool valid()
const noexcept {
return id != 0; }
144 bool valid()
const {
return id != 0; }
157 int width{0}, height{0};
158 bool valid()
const {
return id != 0; }
164 int left{0}, top{0}, right{0}, bottom{0};
181 float rotationDeg{0.0f};
196 using Vec = std::vector<std::string>;
197 using value_type = std::string;
198 using iterator = Vec::iterator;
199 using const_iterator = Vec::const_iterator;
204 mutable std::atomic<uint32_t> refCount{1};
208 Data *data_{
nullptr};
210 static const Vec &emptyVec()
noexcept
212 static const Vec kEmpty{};
216 static Vec &emptyMutVec()
noexcept
222 static void release(Data *p)
noexcept
224 if (p && p->refCount.fetch_sub(1u, std::memory_order_acq_rel) == 1u)
235 if (data_->refCount.load(std::memory_order_acquire) > 1u)
237 auto *copy =
new Data();
238 copy->vec = data_->vec;
246 FontStack()
noexcept =
default;
247 FontStack(
const char *s)
252 data_->vec.emplace_back(s);
255 FontStack(std::string s)
260 data_->vec.push_back(std::move(s));
263 FontStack(std::string_view s)
268 data_->vec.emplace_back(s);
271 FontStack(std::initializer_list<std::string> init)
276 data_->vec.assign(init.begin(), init.end());
279 FontStack(
const FontStack &o) noexcept : data_(o.data_)
282 data_->refCount.fetch_add(1u, std::memory_order_relaxed);
284 FontStack(FontStack &&o) noexcept : data_(o.data_)
288 FontStack &operator=(
const FontStack &o)
noexcept
295 data_->refCount.fetch_add(1u, std::memory_order_relaxed);
299 FontStack &operator=(FontStack &&o)
noexcept
308 ~FontStack()
noexcept { release(data_); }
310 bool empty()
const noexcept {
return !data_ || data_->vec.empty(); }
311 size_t size()
const noexcept {
return data_ ? data_->vec.size() : 0u; }
312 bool sharesStorageWith(
const FontStack &o)
const noexcept {
return data_ == o.data_; }
314 const Vec &asVector()
const noexcept {
return data_ ? data_->vec : emptyVec(); }
316 const_iterator begin()
const noexcept {
return asVector().begin(); }
317 const_iterator end()
const noexcept {
return asVector().end(); }
318 const_iterator cbegin()
const noexcept {
return asVector().cbegin(); }
319 const_iterator cend()
const noexcept {
return asVector().cend(); }
320 iterator begin() {
return empty() ? emptyMutVec().begin() : detach().begin(); }
321 iterator end() {
return empty() ? emptyMutVec().end() : detach().end(); }
323 const std::string &operator[](
size_t i)
const {
return asVector()[i]; }
324 std::string &operator[](
size_t i) {
return detach()[i]; }
325 const std::string &front()
const {
return asVector().front(); }
326 std::string &front() {
return detach().front(); }
327 const std::string &back()
const {
return asVector().back(); }
328 std::string &back() {
return detach().back(); }
330 void push_back(
const std::string &s) { detach().push_back(s); }
331 void push_back(std::string &&s) { detach().push_back(std::move(s)); }
332 template <
typename... Args>
333 std::string &emplace_back(Args &&...args) {
return detach().emplace_back(std::forward<Args>(args)...); }
335 void reserve(
size_t n)
341 void clear()
noexcept
347 bool operator==(
const FontStack &o)
const
349 if (data_ == o.data_)
351 if (empty() && o.empty())
353 return asVector() == o.asVector();
355 bool operator!=(
const FontStack &o)
const {
return !(*
this == o); }
357 static_assert(
sizeof(
FontStack) ==
sizeof(
void *),
"FontStack must remain pointer-sized");
382 std::array<
ButtonState, (size_t)MouseButton::Count> buttons{};
412 constexpr int Backspace = 1;
413 constexpr int Delete = 2;
414 constexpr int Enter = 3;
415 constexpr int Escape = 4;
416 constexpr int Left = 5;
417 constexpr int Right = 6;
418 constexpr int Home = 7;
419 constexpr int End = 8;
420 constexpr int Tab = 9;
421 constexpr int Space = 10;
423 constexpr int Up = 11;
424 constexpr int Down = 12;
426 constexpr int A = 65;
427 constexpr int C = 67;
428 constexpr int V = 86;
429 constexpr int X = 88;
431 constexpr int Y = 89;
432 constexpr int Z = 90;
438 std::vector<int> chars;
439 std::vector<int> keys;
440 std::vector<int> held;
477 float dx = p.x - t.pivot.x;
478 float dy = p.y - t.pivot.y;
482 float rad = t.rotationDeg * 3.14159265358979323846f / 180.0f;
483 float c = std::cos(rad), s = std::sin(rad);
484 float rx = dx * c - dy * s;
485 float ry = dx * s + dy * c;
487 return {rx + t.pivot.x + t.translate.x, ry + t.pivot.y + t.translate.y};
500 p.x -= t.translate.x;
501 p.y -= t.translate.y;
502 float dx = p.x - t.pivot.x, dy = p.y - t.pivot.y;
503 float rad = -t.rotationDeg * 3.14159265358979323846f / 180.0f;
504 float c = std::cos(rad), s = std::sin(rad);
505 float rx = dx * c - dy * s;
506 float ry = dx * s + dy * c;
509 return {rx + t.pivot.x, ry + t.pivot.y};
Centralized standard library includes used throughout ZenitUI.
Fixed-capacity inline-storage vector with heap fallback.
Ordered list of font family names to try, first match wins.
Definition CoreTypes.hpp:194
Justify
Main-axis distribution for flex containers.
Definition CoreTypes.hpp:462
Align
Cross-axis alignment for flex items and content.
Definition CoreTypes.hpp:452
MouseButton
Mouse buttons tracked by the input system.
Definition CoreTypes.hpp:361
Vec2 applyInverseTransform(const Transform2D &t, Vec2 p)
Invert a Transform2D and apply it to a point.
Definition CoreTypes.hpp:498
Vec2 applyTransform(const Transform2D &t, Vec2 p)
Apply a Transform2D to a point.
Definition CoreTypes.hpp:475
@ SpaceBetween
Distribute leftover space between items.
Definition CoreTypes.hpp:466
@ Center
Center within the available space.
Definition CoreTypes.hpp:455
@ End
Pack at the trailing edge.
Definition CoreTypes.hpp:456
@ Start
Pack at the leading edge.
Definition CoreTypes.hpp:454
@ Stretch
Stretch to fill the cross axis.
Definition CoreTypes.hpp:457
Named color constants.
Definition CoreTypes.hpp:96
Global viewport metrics, updated once per frame from the platform.
Definition CoreTypes.hpp:411
8-bit-per-channel RGBA color, non-premultiplied.
Definition CoreTypes.hpp:78
Color withAlpha(float k) const
Return a copy with the alpha channel scaled by k.
Definition CoreTypes.hpp:85
Four-sided edge inset (used for padding, margin, borders).
Definition CoreTypes.hpp:62
Opaque handle to a shader/effect owned by the asset provider.
Definition CoreTypes.hpp:142
Opaque handle to a font loaded by TextEngine.
Definition CoreTypes.hpp:135
Keyboard modifier snapshot.
Definition CoreTypes.hpp:390
Nine-slice inset values for scalable textures.
Definition CoreTypes.hpp:163
Pointer position, wheel delta, and per-button state for one frame.
Definition CoreTypes.hpp:378
Axis-aligned rectangle in screen coordinates.
Definition CoreTypes.hpp:46
Vec2 center() const
Center point of the rectangle.
Definition CoreTypes.hpp:55
Vec2 size() const
Same data as a Vec2.
Definition CoreTypes.hpp:57
bool contains(Vec2 p) const
Inclusive point-in-rect test.
Definition CoreTypes.hpp:50
Opaque handle to an off-screen render target.
Definition CoreTypes.hpp:155
Opaque handle to a GPU/software texture owned by the asset provider.
Definition CoreTypes.hpp:127
2D vector with component-wise arithmetic.
Definition CoreTypes.hpp:25
3D vector.
Definition CoreTypes.hpp:34
4D vector with an implicit w = 1 default.
Definition CoreTypes.hpp:40
Interleaved 2D vertex passed to IRenderer::drawGeometry.
Definition CoreTypes.hpp:118