lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
ui_loader.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include "lmgl/ui/canvas.hpp"
13
14#include <functional>
15#include <map>
16#include <memory>
17#include <string>
18
19namespace lmgl {
20
21namespace ui {
22
27 public:
34 void register_callback(const std::string &name, std::function<void()> callback);
35
42 std::function<void()> get_callback(const std::string &name) const;
43
50 bool has_callback(const std::string &name) const;
51
52 private:
53 std::map<std::string, std::function<void()>> m_callbacks;
54};
55
61 bool success{false};
62
64 std::string error;
65
67 std::shared_ptr<Canvas> canvas;
68
70 std::map<std::string, std::shared_ptr<UIElement>> elements;
71};
72
78class UILoader {
79 public:
83 UILoader();
84
92 UILoadResult load_from_file(const std::string &filepath, const UICallbackRegistry &callbacks);
93
101 UILoadResult load_from_string(const std::string &json_str, const UICallbackRegistry &callbacks);
102
108 void set_base_path(const std::string &base_path);
109
110 private:
112 std::string m_base_path;
113
121 UILoadResult load_internal(const void *json_data, const UICallbackRegistry &callbacks);
122};
123
124} // namespace ui
125
126} // namespace lmgl
Canvas for 2D UI rendering with orthographic projection.
Callback registry for UI event handlers.
Definition ui_loader.hpp:26
std::function< void()> get_callback(const std::string &name) const
Get a registered callback.
Definition ui_loader.cpp:86
void register_callback(const std::string &name, std::function< void()> callback)
Register a callback function.
Definition ui_loader.cpp:82
bool has_callback(const std::string &name) const
Check if callback exists.
Definition ui_loader.cpp:94
UILoadResult load_from_file(const std::string &filepath, const UICallbackRegistry &callbacks)
Load UI from JSON file.
Definition ui_loader.cpp:104
void set_base_path(const std::string &base_path)
Set base path for resolving relative paths (fonts, images).
Definition ui_loader.cpp:102
UILoader()
Constructor.
Definition ui_loader.cpp:100
UILoadResult load_from_string(const std::string &json_str, const UICallbackRegistry &callbacks)
Load UI from JSON string.
Definition ui_loader.cpp:128
Definition button.cpp:15
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12
Result of UI loading operation.
Definition ui_loader.hpp:59
bool success
Whether loading succeeded.
Definition ui_loader.hpp:61
std::string error
Error message if loading failed.
Definition ui_loader.hpp:64
std::map< std::string, std::shared_ptr< UIElement > > elements
Map of element names to elements.
Definition ui_loader.hpp:70
std::shared_ptr< Canvas > canvas
Loaded canvas.
Definition ui_loader.hpp:67
Base class for all UI elements.