Toast Engine
Loading...
Searching...
No Matches
ui_binds.hpp
Go to the documentation of this file.
1
8
9#pragma once
10#include <RmlUi/Core/DataModelHandle.h>
11#include <RmlUi/Core/Variant.h>
12#include <string>
13#include <string_view>
14#include <toast/export.hpp>
15#include <unordered_map>
16#include <unordered_set>
17
18namespace Rml {
19class Context;
20}
21
22namespace toast {
23class Node;
24}
25
26namespace ui {
27
28struct DocumentScan;
29
33class TOAST_API UIBindStore {
34public:
35 UIBindStore();
36 ~UIBindStore();
37
38 void reconcile(const DocumentScan& scan);
39
40 [[nodiscard]]
41 auto has(std::string_view name) const -> bool;
42
43 [[nodiscard]]
44 auto get(std::string_view name) const -> Rml::Variant;
45
46 void set(std::string_view name, Rml::Variant value);
47
48private:
49 std::unordered_map<std::string, Rml::Variant> m_values;
50};
51
52class UIBinds {
53public:
54 UIBinds(Rml::Context* context, toast::Node* owner, const DocumentScan& scan, UIBindStore& store);
55 ~UIBinds();
56
57 UIBinds(const UIBinds&) = delete;
58 auto operator=(const UIBinds&) -> UIBinds& = delete;
59 UIBinds(UIBinds&&) = delete;
60 auto operator=(UIBinds&&) -> UIBinds& = delete;
61
62 [[nodiscard]]
63 auto handle() -> Rml::DataModelHandle {
64 return m_handle;
65 }
66
68 [[nodiscard]]
69 auto has(std::string_view name) const -> bool;
70
72 [[nodiscard]]
73 auto get(std::string_view name) const -> Rml::Variant;
74
76 void set(std::string_view name, Rml::Variant value);
77
78 void flushDirty();
79 static void flushAllDirty();
80
82 [[nodiscard]]
83 static auto forNode(const toast::Node* node) -> UIBinds*;
84
85 static constexpr const char* k_model_name = "binds";
86
87private:
88 Rml::Context* m_context = nullptr;
89 toast::Node* m_owner = nullptr;
90 Rml::DataModelHandle m_handle;
91 UIBindStore& m_store;
92 std::unordered_set<std::string> m_dirty_names;
93
94 static inline std::unordered_map<const toast::Node*, UIBinds*> s_by_node;
95};
96
97}
Definition node.hpp:81
Persistent values shared by Lua and the active RmlUi data model.
Definition ui_binds.hpp:33
static auto forNode(const toast::Node *node) -> UIBinds *
Definition ui_binds.cpp:137
void set(std::string_view name, Rml::Variant value)
Writes name from script and notifies the data model to refresh the UI.
Definition ui_binds.cpp:114
auto get(std::string_view name) const -> Rml::Variant
Definition ui_binds.cpp:110
auto has(std::string_view name) const -> bool
Definition ui_binds.cpp:106
Definition document_preprocess.hpp:27