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/core/api.h"
6#include "flint/ui/ui-context.h"
7
8#include <memory>
9#include <string>
10#include <unordered_map>
11
12namespace Flint {
13
14 class UICanvas;
15
25 class UISystem {
26 public:
27 UISystem() = default;
28 ~UISystem() = default;
29
30 UISystem(const UISystem &) = delete;
31 UISystem &operator=(const UISystem &) = delete;
32 UISystem(UISystem &&) = delete;
33 UISystem &operator=(UISystem &&) = delete;
34
40 FLINT_API UIContext *createContext(std::string name);
41
47 FLINT_API void destroyContext(std::string name);
48
53 [[nodiscard]] FLINT_API UIContext *getContext(const std::string &name) const;
54
60 [[nodiscard]] FLINT_API UIContext *getActiveContext() const;
61
64 [[nodiscard]] float getDisplayScale() const {
65 return m_displayScale;
66 }
67
74 FLINT_API void setActiveContext(const std::string &name);
75
81 FLINT_API void setDisplayScale(float scale);
82
85 FLINT_API void clearActiveContext();
86
89 FLINT_API void update(float deltaTime) const;
90
104 FLINT_API void handleEvent(const AppEvent &event);
105
114 FLINT_API void render(UICanvas &canvas) const;
115
116 private:
117 std::unordered_map<std::string, std::unique_ptr<UIContext>>
118 m_contexts;
119 UIContext *m_activeContext = nullptr;
122 bool m_axisNavFiredX = false;
124 bool m_axisNavFiredY = false;
127 static constexpr float NAV_FIRE_THRESHOLD = 0.8f;
129 static constexpr float NAV_RESET_THRESHOLD = 0.3f;
132 float m_displayScale =
133 1.0f;
134 };
135
136}
Dynamic 2D batching engine processing shape vector geometry and hardware-accelerated text strings....
Definition ui-canvas.h:107
Manages an isolated user interface canvas workspace sandbox, hosting its own independent node tree an...
Definition ui-context.h:28
Central gateway subsystem managing UI multi-context lifetimes, resolution scaling,...
Definition ui-system.h:25
FLINT_API void clearActiveContext()
De-allocates focus assignments, forcing the active layout view track to return to null.
FLINT_API UIContext * getActiveContext() const
Fetches the current user interface workspace layer targeted for frame inputs and draw pipelines.
FLINT_API void update(float deltaTime) const
Advances frame animation trackers and ticking metrics within the currently active UI context tree.
FLINT_API void handleEvent(const AppEvent &event)
Translates raw platform engine input messages into structured, semantic UIEvent actions.
float getDisplayScale() const
Returns the current resolution scalar factor applied across the layout metric generation loop.
Definition ui-system.h:64
FLINT_API void setActiveContext(const std::string &name)
Switches frame event processing focus directly over to a specific pre-registered context layout tree.
FLINT_API UIContext * createContext(std::string name)
Spawns and registers a uniquely named UI canvas sandbox workspace.
FLINT_API UIContext * getContext(const std::string &name) const
Queries the context map registry to extract a specific UI canvas reference block.
FLINT_API void setDisplayScale(float scale)
Sets the global layout transformation multiplier factor to support clean high-DPI/resolution renderin...
FLINT_API void render(UICanvas &canvas) const
Dispatches the active context layout node tree to push text structures and primitives down to the ren...
FLINT_API void destroyContext(std::string name)
Completely unloads the targeted context container and immediately releases its bound VRAM elements.
A tagged union representing a single application input or window event.
Definition event.h:90