Toast Engine
Toggle main menu visibility
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
18
namespace
Rml {
19
class
Context;
20
}
21
22
namespace
toast {
23
class
Node
;
24
}
25
26
namespace
ui {
27
28
struct
DocumentScan
;
29
33
class
TOAST_API UIBindStore {
34
public
:
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
48
private
:
49
std::unordered_map<std::string, Rml::Variant> m_values;
50
};
51
52
class
UIBinds {
53
public
:
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
87
private
:
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
}
toast::Node
Definition
node.hpp:81
ui::UIBindStore
Persistent values shared by Lua and the active RmlUi data model.
Definition
ui_binds.hpp:33
ui::UIBinds::forNode
static auto forNode(const toast::Node *node) -> UIBinds *
Definition
ui_binds.cpp:137
ui::UIBinds::set
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
ui::UIBinds::get
auto get(std::string_view name) const -> Rml::Variant
Definition
ui_binds.cpp:110
ui::UIBinds::has
auto has(std::string_view name) const -> bool
Definition
ui_binds.cpp:106
export.hpp
ui::DocumentScan
Definition
document_preprocess.hpp:27
engine
src
toast
ui
ui_binds.hpp
Generated by
1.17.0