Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
ui-system.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4
5#include "flint/ui/ui-context.h"
6
7#include <memory>
8#include <string>
9#include <unordered_map>
10
11namespace Flint {
12
13 class UICanvas;
14
24 class UISystem {
25 public:
26 UISystem() = default;
27 ~UISystem() = default;
28
29 UISystem(const UISystem &) = delete;
30 UISystem &operator=(const UISystem &) = delete;
31 UISystem(UISystem &&) = delete;
32 UISystem &operator=(UISystem &&) = delete;
33
39 UIContext *createContext(std::string name);
40
46 void destroyContext(std::string name);
47
52 [[nodiscard]] UIContext *getContext(const std::string &name) const;
53
59 [[nodiscard]] UIContext *getActiveContext() const;
60
63 [[nodiscard]] float getDisplayScale() const {
64 return m_displayScale;
65 }
66
73 void setActiveContext(const std::string &name);
74
80 void setDisplayScale(float scale);
81
85
88 void update(float deltaTime) const;
89
103 void handleEvent(const AppEvent &event);
104
113 void render(UICanvas &canvas) const;
114
115 private:
116 std::unordered_map<std::string, std::unique_ptr<UIContext>>
117 m_contexts;
118 UIContext *m_activeContext = nullptr;
121 bool m_axisNavFiredX = false;
123 bool m_axisNavFiredY = false;
126 static constexpr float NAV_FIRE_THRESHOLD = 0.8f;
128 static constexpr float NAV_RESET_THRESHOLD = 0.3f;
131 float m_displayScale =
132 1.0f;
133 };
134
135}
Dynamic 2D batching engine processing shape vector geometry and hardware-accelerated text strings....
Definition ui-canvas.h:106
Manages an isolated user interface canvas workspace sandbox, hosting its own independent node tree an...
Definition ui-context.h:27
UIContext * getActiveContext() const
Fetches the current user interface workspace layer targeted for frame inputs and draw pipelines.
UIContext * getContext(const std::string &name) const
Queries the context map registry to extract a specific UI canvas reference block.
float getDisplayScale() const
Returns the current resolution scalar factor applied across the layout metric generation loop.
Definition ui-system.h:63
void setDisplayScale(float scale)
Sets the global layout transformation multiplier factor to support clean high-DPI/resolution renderin...
UIContext * createContext(std::string name)
Spawns and registers a uniquely named UI canvas sandbox workspace.
void setActiveContext(const std::string &name)
Switches frame event processing focus directly over to a specific pre-registered context layout tree.
void render(UICanvas &canvas) const
Dispatches the active context layout node tree to push text structures and primitives down to the ren...
void destroyContext(std::string name)
Completely unloads the targeted context container and immediately releases its bound VRAM elements.
void handleEvent(const AppEvent &event)
Translates raw platform engine input messages into structured, semantic UIEvent actions.
Central gateway subsystem managing UI multi-context lifetimes, resolution scaling,...
Definition ui-system.h:24
void update(float deltaTime) const
Advances frame animation trackers and ticking metrics within the currently active UI context tree.
void clearActiveContext()
De-allocates focus assignments, forcing the active layout view track to return to null.
A tagged union representing a single application input or window event.
Definition event.h:90