vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
ui_canvas.h
1#pragma once
2
3#include <cstdint>
4
5#include "core/reflect.h"
6#include "ecs/entity.h"
7
8namespace Vkm::Engine {
9
10class Scene;
11
18struct UICanvas {
22 enum class ScaleMode : uint8_t {
26 };
27
29 float referenceHeight = 1080.0f;
32 int32_t sortOrder = 0;
34 bool visible = true;
35
43 static float scaleIn(const UICanvas& canvas, float viewHeight) {
44 const bool scaled = canvas.scaleMode == ScaleMode::ScaleWithHeight && canvas.referenceHeight > 0.0f;
45 return scaled ? viewHeight / canvas.referenceHeight : 1.0f;
46 }
47};
48
60bool hasCanvasAncestor(const Scene& scene, EntityId id);
61
62} // namespace Vkm::Engine
63
64VKM_ENUM_NAMES(::Vkm::Engine::UICanvas::ScaleMode, "Fixed", "ScaleWithHeight")
65
66VKM_REFLECT_BEGIN(::Vkm::Engine::UICanvas)
67 VKM_F(referenceHeight)
68 VKM_F(scaleMode)
69 VKM_F(sortOrder)
70 VKM_F(visible)
71VKM_REFLECT_END()
Central registry managing entities and an open set of component types.
Definition scene.h:29
Root of a screen-space UI layer.
Definition ui_canvas.h:18
static float scaleIn(const UICanvas &canvas, float viewHeight)
Screen pixels a pixel of canvas spans, drawn into a view viewHeight pixels tall.
Definition ui_canvas.h:43
ScaleMode
How the canvas maps authored pixels to on-screen pixels.
Definition ui_canvas.h:22
@ Fixed
One authored pixel equals one screen pixel.
Definition ui_canvas.h:23
@ ScaleWithHeight
Scale uniformly by viewportHeight / referenceHeight.
Definition ui_canvas.h:24
@ Count
Sentinel; keep last. Drives the VKM_ENUM_NAMES check.
Definition ui_canvas.h:25
float referenceHeight
Authoring height in pixels; ScaleWithHeight scales against it.
Definition ui_canvas.h:29
int32_t sortOrder
Draw order across canvases; higher draws on top.
Definition ui_canvas.h:32
bool visible
Skip the canvas and its whole subtree when false.
Definition ui_canvas.h:34