@geastack/engine 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +29 -0
- package/bitmap_font.cpp +165 -0
- package/canvas.cpp +4608 -0
- package/components/Button.d.ts +4 -0
- package/components/Button.tsx +32 -0
- package/components/Image.d.ts +3 -0
- package/components/Image.tsx +17 -0
- package/components/Text.d.ts +3 -0
- package/components/Text.tsx +9 -0
- package/components/View.d.ts +3 -0
- package/components/View.tsx +24 -0
- package/components/index.d.ts +8 -0
- package/components/index.ts +4 -0
- package/css/animation.h +252 -0
- package/css/declarative.h +131 -0
- package/css/easing.h +160 -0
- package/css/engine.h +223 -0
- package/css/interpolate.h +38 -0
- package/image_store.cpp +807 -0
- package/package.json +62 -0
- package/rasterized_font.cpp +570 -0
- package/touch_runtime.cpp +513 -0
- package/ui/absolute_leaf_refresh.cpp +279 -0
- package/ui/absolute_leaf_refresh.h +12 -0
- package/ui/canvas_element.cpp +2314 -0
- package/ui/canvas_element.h +353 -0
- package/ui/canvas_store.cpp +188 -0
- package/ui/canvas_store.h +59 -0
- package/ui/core.cpp +135 -0
- package/ui/css_atom.cpp +155 -0
- package/ui/css_atom.h +21 -0
- package/ui/dirty_regions.cpp +66 -0
- package/ui/dirty_regions.h +34 -0
- package/ui/display_invalidation.cpp +101 -0
- package/ui/display_invalidation.h +15 -0
- package/ui/document.cpp +356 -0
- package/ui/document.h +101 -0
- package/ui/image.h +16 -0
- package/ui/image_element.cpp +13 -0
- package/ui/image_node.cpp +165 -0
- package/ui/input.cpp +936 -0
- package/ui/input_render.cpp +213 -0
- package/ui/internal.h +567 -0
- package/ui/layout.cpp +2025 -0
- package/ui/layout_snapshot.cpp +82 -0
- package/ui/layout_snapshot.h +12 -0
- package/ui/mirror.h +25 -0
- package/ui/node.cpp +243 -0
- package/ui/node.h +154 -0
- package/ui/node_lifecycle.cpp +137 -0
- package/ui/node_lifecycle.h +13 -0
- package/ui/node_model.h +597 -0
- package/ui/refresh_perf.h +235 -0
- package/ui/refresh_trace.h +68 -0
- package/ui/render.cpp +12097 -0
- package/ui/root_scroll_refresh.cpp +859 -0
- package/ui/root_scroll_refresh.h +30 -0
- package/ui/state_init.h +21 -0
- package/ui/style.cpp +14994 -0
- package/ui/style.h +727 -0
- package/ui/style_values.h +31 -0
- package/ui/text.cpp +2010 -0
- package/ui/text.h +15 -0
- package/ui/text_element.cpp +15 -0
- package/ui/tree_events.cpp +621 -0
- package/ui/tree_events.h +69 -0
- package/ui/tree_internal.h +191 -0
- package/ui/tree_nodes.cpp +628 -0
- package/ui/tree_render.cpp +3138 -0
- package/ui/tree_scroll_mirror.cpp +101 -0
- package/ui/tree_state.cpp +574 -0
- package/ui/tree_state.h +235 -0
- package/ui/tree_style.cpp +698 -0
- package/ui/ui.h +9 -0
- package/ui/view.cpp +2232 -0
- package/ui/view.h +14 -0
- package/ui/view_element.cpp +13 -0
- package/ui/viewport_region.cpp +36 -0
- package/ui/viewport_region.h +12 -0
- package/ui/virtual_keyboard.cpp +908 -0
- package/ui/virtual_keyboard.h +59 -0
- package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
- package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
- package/vendor/stb/stb_image.h +7988 -0
- package/vendor/stb/stb_truetype.h +5079 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "mirror.h"
|
|
3
|
+
|
|
4
|
+
#include "internal.h"
|
|
5
|
+
#include "tree_state.h"
|
|
6
|
+
|
|
7
|
+
namespace gea::embedded::ui {
|
|
8
|
+
|
|
9
|
+
Mirror &Mirror::instance()
|
|
10
|
+
{
|
|
11
|
+
static Mirror mirror;
|
|
12
|
+
return mirror;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
bool Mirror::scrollDirtyAny() const
|
|
16
|
+
{
|
|
17
|
+
return treeState().scrollDirtyAny;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
void Mirror::copyScrollDirty(uint64_t *dst, int word_count) const
|
|
21
|
+
{
|
|
22
|
+
if (!dst || word_count <= 0) return;
|
|
23
|
+
auto &state = treeState();
|
|
24
|
+
for (int i = 0; i < word_count; i++)
|
|
25
|
+
dst[i] = i < kScrollDirtyWordCount ? state.scrollDirtyNodes[i] : 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void Mirror::clearScrollDirty() const
|
|
29
|
+
{
|
|
30
|
+
auto &state = treeState();
|
|
31
|
+
for (int i = 0; i < kScrollDirtyWordCount; i++)
|
|
32
|
+
state.scrollDirtyNodes[i] = 0;
|
|
33
|
+
state.scrollDirtyAny = false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
bool Mirror::nodeIsScrollable(int node) const
|
|
37
|
+
{
|
|
38
|
+
auto &state = treeState();
|
|
39
|
+
if (node < 0 || node >= state.nodeCount) return false;
|
|
40
|
+
Node *n = &state.nodes[node];
|
|
41
|
+
return isViewLikeNodeType(n->type) &&
|
|
42
|
+
((n->type != NodeType::VirtualList && scrollsOverflowX(n->style) && ViewRenderer::scrollMaxX(*n) > 0) ||
|
|
43
|
+
((n->type == NodeType::VirtualList || scrollsOverflowY(n->style)) && ViewRenderer::scrollMaxY(*n) > 0));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
int Mirror::scrollX(int node) const
|
|
47
|
+
{
|
|
48
|
+
auto &state = treeState();
|
|
49
|
+
if (node < 0 || node >= state.nodeCount) return 0;
|
|
50
|
+
return state.nodes[node].layout.scroll_x;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void Mirror::setScrollX(int node, int scroll_x) const
|
|
54
|
+
{
|
|
55
|
+
auto &state = treeState();
|
|
56
|
+
if (node < 0 || node >= state.nodeCount) return;
|
|
57
|
+
Node *n = &state.nodes[node];
|
|
58
|
+
if (!isViewLikeNodeType(n->type) || !scrollsOverflowX(n->style) || n->type == NodeType::VirtualList) return;
|
|
59
|
+
|
|
60
|
+
int max_x = ViewRenderer::scrollMaxX(*n);
|
|
61
|
+
if (scroll_x < 0) scroll_x = 0;
|
|
62
|
+
if (scroll_x > max_x) scroll_x = max_x;
|
|
63
|
+
if (scroll_x == n->layout.scroll_x) return;
|
|
64
|
+
|
|
65
|
+
n->layout.scroll_x = scroll_x;
|
|
66
|
+
n->render.dirty = 1;
|
|
67
|
+
n->render.layout_dirty = 1;
|
|
68
|
+
n->render.non_scroll_dirty = 1;
|
|
69
|
+
n->render.scroll_dirty = 1;
|
|
70
|
+
state.scrollDirtyNodes[node / 64] |= (1ull << (node % 64));
|
|
71
|
+
state.scrollDirtyAny = true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
int Mirror::scrollY(int node) const
|
|
75
|
+
{
|
|
76
|
+
auto &state = treeState();
|
|
77
|
+
if (node < 0 || node >= state.nodeCount) return 0;
|
|
78
|
+
return state.nodes[node].layout.scroll_y;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void Mirror::setScrollY(int node, int scroll_y) const
|
|
82
|
+
{
|
|
83
|
+
auto &state = treeState();
|
|
84
|
+
if (node < 0 || node >= state.nodeCount) return;
|
|
85
|
+
Node *n = &state.nodes[node];
|
|
86
|
+
if (!isViewLikeNodeType(n->type) || (n->type != NodeType::VirtualList && !scrollsOverflowY(n->style))) return;
|
|
87
|
+
|
|
88
|
+
int max_y = ViewRenderer::scrollMaxY(*n);
|
|
89
|
+
if (scroll_y < 0) scroll_y = 0;
|
|
90
|
+
if (scroll_y > max_y) scroll_y = max_y;
|
|
91
|
+
if (scroll_y == n->layout.scroll_y) return;
|
|
92
|
+
|
|
93
|
+
n->layout.scroll_y = scroll_y;
|
|
94
|
+
n->render.dirty = 1;
|
|
95
|
+
n->render.layout_dirty = 1;
|
|
96
|
+
n->render.scroll_dirty = 1;
|
|
97
|
+
state.scrollDirtyNodes[node / 64] |= (1ull << (node % 64));
|
|
98
|
+
state.scrollDirtyAny = true;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "tree_state.h"
|
|
3
|
+
|
|
4
|
+
#include <algorithm>
|
|
5
|
+
#include <cstddef>
|
|
6
|
+
#include <cstring>
|
|
7
|
+
#include <deque>
|
|
8
|
+
#include <new>
|
|
9
|
+
#include <utility>
|
|
10
|
+
|
|
11
|
+
// TreeState is a single large struct (kMaxNodes-scaled per-node arrays: nodes,
|
|
12
|
+
// styles, attributes, class lists, custom props, style overrides, dirty/bounds
|
|
13
|
+
// tables) — on the order of ~170 KB. Internal SRAM is the scarce resource on the
|
|
14
|
+
// ESP32-S3 (~330 KB, and WiFi/BLE need DMA-capable internal RAM that can't live
|
|
15
|
+
// in PSRAM); the default `new` lands this pool in internal RAM, starving the
|
|
16
|
+
// radios (WiFi `mem fail` / socket open `sock < 0` during fetches). The tree is
|
|
17
|
+
// CPU/cache-accessed only (never DMA, never touched with the flash cache off),
|
|
18
|
+
// so it belongs in PSRAM like the framebuffer. Other targets keep plain `new`.
|
|
19
|
+
#if defined(ESP_PLATFORM)
|
|
20
|
+
#include "esp_heap_caps.h"
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
namespace gea::embedded::ui {
|
|
24
|
+
|
|
25
|
+
namespace {
|
|
26
|
+
|
|
27
|
+
bool isClassWhitespace(char c)
|
|
28
|
+
{
|
|
29
|
+
return static_cast<unsigned char>(c) <= ' ';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
bool validToken(const std::string &token)
|
|
33
|
+
{
|
|
34
|
+
if (token.empty()) return false;
|
|
35
|
+
for (char c : token) {
|
|
36
|
+
if (isClassWhitespace(c)) return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
std::deque<std::vector<CssAtomId>> &classListOverflowLists()
|
|
42
|
+
{
|
|
43
|
+
static std::deque<std::vector<CssAtomId>> lists;
|
|
44
|
+
return lists;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
std::vector<std::uint16_t> &classListOverflowFreeList()
|
|
48
|
+
{
|
|
49
|
+
static std::vector<std::uint16_t> handles;
|
|
50
|
+
return handles;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
std::vector<CssAtomId> *classListOverflow(std::uint16_t handle)
|
|
54
|
+
{
|
|
55
|
+
auto &lists = classListOverflowLists();
|
|
56
|
+
if (handle == NodeClassList::kNoOverflow || static_cast<std::size_t>(handle) >= lists.size()) return nullptr;
|
|
57
|
+
return &lists[handle];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const std::vector<CssAtomId> *classListOverflowConst(std::uint16_t handle)
|
|
61
|
+
{
|
|
62
|
+
const auto &lists = classListOverflowLists();
|
|
63
|
+
if (handle == NodeClassList::kNoOverflow || static_cast<std::size_t>(handle) >= lists.size()) return nullptr;
|
|
64
|
+
return &lists[handle];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
std::vector<CssAtomId> *ensureClassListOverflow(NodeClassList &list)
|
|
68
|
+
{
|
|
69
|
+
if (auto *existing = classListOverflow(list.overflowHandle)) return existing;
|
|
70
|
+
auto &lists = classListOverflowLists();
|
|
71
|
+
auto &freeList = classListOverflowFreeList();
|
|
72
|
+
std::uint16_t handle = NodeClassList::kNoOverflow;
|
|
73
|
+
if (!freeList.empty()) {
|
|
74
|
+
handle = freeList.back();
|
|
75
|
+
freeList.pop_back();
|
|
76
|
+
lists[handle].clear();
|
|
77
|
+
} else if (lists.size() < NodeClassList::kNoOverflow) {
|
|
78
|
+
handle = static_cast<std::uint16_t>(lists.size());
|
|
79
|
+
lists.emplace_back();
|
|
80
|
+
}
|
|
81
|
+
list.overflowHandle = handle;
|
|
82
|
+
return classListOverflow(handle);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
void releaseClassListOverflow(NodeClassList &list)
|
|
86
|
+
{
|
|
87
|
+
if (list.overflowHandle == NodeClassList::kNoOverflow) return;
|
|
88
|
+
if (auto *overflow = classListOverflow(list.overflowHandle)) overflow->clear();
|
|
89
|
+
classListOverflowFreeList().push_back(list.overflowHandle);
|
|
90
|
+
list.overflowHandle = NodeClassList::kNoOverflow;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
bool appendClassAtom(NodeClassList &list, CssAtomId atom)
|
|
94
|
+
{
|
|
95
|
+
if (atom == kInvalidCssAtom || list.count == 0xFFu) return false;
|
|
96
|
+
if (list.count < NodeClassList::kInlineTokenCount) {
|
|
97
|
+
list.inlineTokens[list.count++] = atom;
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
auto *overflow = ensureClassListOverflow(list);
|
|
101
|
+
if (!overflow || list.overflowHandle == NodeClassList::kNoOverflow) return false;
|
|
102
|
+
overflow->push_back(atom);
|
|
103
|
+
++list.count;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void eraseClassAtomAt(NodeClassList &list, std::size_t index)
|
|
108
|
+
{
|
|
109
|
+
if (index >= list.count) return;
|
|
110
|
+
if (index < NodeClassList::kInlineTokenCount) {
|
|
111
|
+
const std::size_t inlineEnd = std::min<std::size_t>(list.count, NodeClassList::kInlineTokenCount);
|
|
112
|
+
for (std::size_t i = index + 1; i < inlineEnd; ++i)
|
|
113
|
+
list.inlineTokens[i - 1] = list.inlineTokens[i];
|
|
114
|
+
if (list.count > NodeClassList::kInlineTokenCount) {
|
|
115
|
+
auto *overflow = classListOverflow(list.overflowHandle);
|
|
116
|
+
if (overflow && !overflow->empty()) {
|
|
117
|
+
list.inlineTokens[NodeClassList::kInlineTokenCount - 1] = overflow->front();
|
|
118
|
+
overflow->erase(overflow->begin());
|
|
119
|
+
if (overflow->empty()) releaseClassListOverflow(list);
|
|
120
|
+
}
|
|
121
|
+
} else if (list.count > 0) {
|
|
122
|
+
list.inlineTokens[list.count - 1] = kInvalidCssAtom;
|
|
123
|
+
}
|
|
124
|
+
--list.count;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
auto *overflow = classListOverflow(list.overflowHandle);
|
|
128
|
+
if (!overflow) return;
|
|
129
|
+
const std::size_t overflowIndex = index - NodeClassList::kInlineTokenCount;
|
|
130
|
+
if (overflowIndex >= overflow->size()) return;
|
|
131
|
+
overflow->erase(overflow->begin() + static_cast<std::ptrdiff_t>(overflowIndex));
|
|
132
|
+
--list.count;
|
|
133
|
+
if (overflow->empty()) releaseClassListOverflow(list);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
bool classListsEqual(const NodeClassList &a, const NodeClassList &b)
|
|
137
|
+
{
|
|
138
|
+
if (a.size() != b.size()) return false;
|
|
139
|
+
for (std::size_t i = 0, n = a.size(); i < n; ++i)
|
|
140
|
+
if (a.at(i) != b.at(i)) return false;
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
NodeClassList splitClassNameAtoms(const char *className, std::size_t length)
|
|
145
|
+
{
|
|
146
|
+
NodeClassList out;
|
|
147
|
+
const char *text = className ? className : "";
|
|
148
|
+
std::size_t i = 0;
|
|
149
|
+
while (i < length) {
|
|
150
|
+
while (i < length && isClassWhitespace(text[i])) ++i;
|
|
151
|
+
const std::size_t start = i;
|
|
152
|
+
while (i < length && !isClassWhitespace(text[i])) ++i;
|
|
153
|
+
if (i <= start) continue;
|
|
154
|
+
const CssAtomId token = internCssAtom(text + start, i - start);
|
|
155
|
+
if (token == kInvalidCssAtom) continue;
|
|
156
|
+
bool seen = false;
|
|
157
|
+
for (std::size_t existingIndex = 0, count = out.size(); existingIndex < count; ++existingIndex) {
|
|
158
|
+
if (out.at(existingIndex) == token) {
|
|
159
|
+
seen = true;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!seen) appendClassAtom(out, token);
|
|
164
|
+
}
|
|
165
|
+
return out;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
} // namespace
|
|
169
|
+
|
|
170
|
+
NodeClassList::NodeClassList(const NodeClassList &other)
|
|
171
|
+
{
|
|
172
|
+
for (std::size_t i = 0, n = other.size(); i < n; ++i)
|
|
173
|
+
appendClassAtom(*this, other.at(i));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
NodeClassList &NodeClassList::operator=(const NodeClassList &other)
|
|
177
|
+
{
|
|
178
|
+
if (this == &other) return *this;
|
|
179
|
+
clear();
|
|
180
|
+
for (std::size_t i = 0, n = other.size(); i < n; ++i)
|
|
181
|
+
appendClassAtom(*this, other.at(i));
|
|
182
|
+
return *this;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
NodeClassList::NodeClassList(NodeClassList &&other) noexcept
|
|
186
|
+
{
|
|
187
|
+
for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
|
|
188
|
+
inlineTokens[i] = other.inlineTokens[i];
|
|
189
|
+
overflowHandle = other.overflowHandle;
|
|
190
|
+
count = other.count;
|
|
191
|
+
other.overflowHandle = kNoOverflow;
|
|
192
|
+
other.count = 0;
|
|
193
|
+
for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
|
|
194
|
+
other.inlineTokens[i] = kInvalidCssAtom;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
NodeClassList &NodeClassList::operator=(NodeClassList &&other) noexcept
|
|
198
|
+
{
|
|
199
|
+
if (this == &other) return *this;
|
|
200
|
+
clear();
|
|
201
|
+
for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
|
|
202
|
+
inlineTokens[i] = other.inlineTokens[i];
|
|
203
|
+
overflowHandle = other.overflowHandle;
|
|
204
|
+
count = other.count;
|
|
205
|
+
other.overflowHandle = kNoOverflow;
|
|
206
|
+
other.count = 0;
|
|
207
|
+
for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
|
|
208
|
+
other.inlineTokens[i] = kInvalidCssAtom;
|
|
209
|
+
return *this;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
NodeClassList::~NodeClassList()
|
|
213
|
+
{
|
|
214
|
+
releaseClassListOverflow(*this);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
void NodeClassList::clear()
|
|
218
|
+
{
|
|
219
|
+
releaseClassListOverflow(*this);
|
|
220
|
+
for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
|
|
221
|
+
inlineTokens[i] = kInvalidCssAtom;
|
|
222
|
+
count = 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
bool NodeClassList::set(const std::string &className)
|
|
226
|
+
{
|
|
227
|
+
return set(className.c_str());
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
bool NodeClassList::set(const char *className)
|
|
231
|
+
{
|
|
232
|
+
NodeClassList next = splitClassNameAtoms(className, className ? std::strlen(className) : 0);
|
|
233
|
+
if (classListsEqual(*this, next)) return false;
|
|
234
|
+
*this = std::move(next);
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
bool NodeClassList::add(const std::string &token)
|
|
239
|
+
{
|
|
240
|
+
if (!validToken(token)) return false;
|
|
241
|
+
const CssAtomId atom = internCssAtom(token);
|
|
242
|
+
if (containsAtom(atom)) return false;
|
|
243
|
+
return appendClassAtom(*this, atom);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
bool NodeClassList::remove(const std::string &token)
|
|
247
|
+
{
|
|
248
|
+
if (!validToken(token)) return false;
|
|
249
|
+
const CssAtomId atom = findCssAtom(token);
|
|
250
|
+
if (atom == kInvalidCssAtom) return false;
|
|
251
|
+
for (std::size_t i = 0, n = size(); i < n; ++i) {
|
|
252
|
+
if (at(i) != atom) continue;
|
|
253
|
+
eraseClassAtomAt(*this, i);
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
bool NodeClassList::toggle(const std::string &token)
|
|
260
|
+
{
|
|
261
|
+
if (contains(token)) {
|
|
262
|
+
remove(token);
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
if (!add(token)) return false;
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
bool NodeClassList::toggle(const std::string &token, bool force)
|
|
270
|
+
{
|
|
271
|
+
return force ? add(token) || contains(token) : !(remove(token) || !contains(token));
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
bool NodeClassList::contains(const std::string &token) const
|
|
275
|
+
{
|
|
276
|
+
if (!validToken(token)) return false;
|
|
277
|
+
return containsAtom(findCssAtom(token));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
bool NodeClassList::containsAtom(CssAtomId token) const
|
|
281
|
+
{
|
|
282
|
+
if (token == kInvalidCssAtom) return false;
|
|
283
|
+
for (std::size_t i = 0, n = size(); i < n; ++i)
|
|
284
|
+
if (at(i) == token) return true;
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
CssAtomId NodeClassList::at(std::size_t index) const
|
|
289
|
+
{
|
|
290
|
+
if (index >= count) return kInvalidCssAtom;
|
|
291
|
+
if (index < kInlineTokenCount) return inlineTokens[index];
|
|
292
|
+
const auto *overflow = classListOverflowConst(overflowHandle);
|
|
293
|
+
if (!overflow) return kInvalidCssAtom;
|
|
294
|
+
const std::size_t overflowIndex = index - kInlineTokenCount;
|
|
295
|
+
if (overflowIndex >= overflow->size()) return kInvalidCssAtom;
|
|
296
|
+
return (*overflow)[overflowIndex];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
std::string NodeClassList::value() const
|
|
300
|
+
{
|
|
301
|
+
std::string out;
|
|
302
|
+
for (std::size_t i = 0, n = size(); i < n; ++i) {
|
|
303
|
+
const CssAtomId token = at(i);
|
|
304
|
+
if (!out.empty()) out.push_back(' ');
|
|
305
|
+
out += cssAtomText(token);
|
|
306
|
+
}
|
|
307
|
+
return out;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
namespace {
|
|
311
|
+
|
|
312
|
+
NodeStyleOverride &styleOverrideAt(NodeStyleOverrideStore &store, std::size_t index)
|
|
313
|
+
{
|
|
314
|
+
return store.spilled ? store.spillValues[index] : store.inlineValues[index];
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
void appendStyleOverride(NodeStyleOverrideStore &store, NodeStyleOverride entry)
|
|
318
|
+
{
|
|
319
|
+
if (!store.spilled && store.inlineCount < NodeStyleOverrideStore::kInlineCount) {
|
|
320
|
+
store.inlineValues[store.inlineCount++] = entry;
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (!store.spilled) {
|
|
324
|
+
store.spillCapacity = NodeStyleOverrideStore::kInlineCount * 2;
|
|
325
|
+
store.spillValues = new NodeStyleOverride[store.spillCapacity];
|
|
326
|
+
for (std::size_t i = 0; i < store.inlineCount; ++i)
|
|
327
|
+
store.spillValues[i] = store.inlineValues[i];
|
|
328
|
+
store.spillCount = store.inlineCount;
|
|
329
|
+
store.spilled = true;
|
|
330
|
+
}
|
|
331
|
+
if (store.spillCount >= store.spillCapacity) {
|
|
332
|
+
const std::size_t nextCapacity = store.spillCapacity ? store.spillCapacity * 2 : NodeStyleOverrideStore::kInlineCount * 2;
|
|
333
|
+
auto *next = new NodeStyleOverride[nextCapacity];
|
|
334
|
+
for (std::size_t i = 0; i < store.spillCount; ++i)
|
|
335
|
+
next[i] = store.spillValues[i];
|
|
336
|
+
delete[] store.spillValues;
|
|
337
|
+
store.spillValues = next;
|
|
338
|
+
store.spillCapacity = nextCapacity;
|
|
339
|
+
}
|
|
340
|
+
store.spillValues[store.spillCount++] = entry;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
} // namespace
|
|
344
|
+
|
|
345
|
+
NodeStyleOverrideStore::NodeStyleOverrideStore(const NodeStyleOverrideStore &other)
|
|
346
|
+
{
|
|
347
|
+
for (std::size_t i = 0, n = other.size(); i < n; ++i)
|
|
348
|
+
appendStyleOverride(*this, other.at(i));
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
NodeStyleOverrideStore &NodeStyleOverrideStore::operator=(const NodeStyleOverrideStore &other)
|
|
352
|
+
{
|
|
353
|
+
if (this == &other) return *this;
|
|
354
|
+
clear();
|
|
355
|
+
for (std::size_t i = 0, n = other.size(); i < n; ++i)
|
|
356
|
+
appendStyleOverride(*this, other.at(i));
|
|
357
|
+
return *this;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
NodeStyleOverrideStore::NodeStyleOverrideStore(NodeStyleOverrideStore &&other) noexcept
|
|
361
|
+
{
|
|
362
|
+
for (std::uint8_t i = 0; i < kInlineCount; ++i)
|
|
363
|
+
inlineValues[i] = other.inlineValues[i];
|
|
364
|
+
spillValues = other.spillValues;
|
|
365
|
+
spillCount = other.spillCount;
|
|
366
|
+
spillCapacity = other.spillCapacity;
|
|
367
|
+
inlineCount = other.inlineCount;
|
|
368
|
+
spilled = other.spilled;
|
|
369
|
+
other.spillValues = nullptr;
|
|
370
|
+
other.spillCount = 0;
|
|
371
|
+
other.spillCapacity = 0;
|
|
372
|
+
other.inlineCount = 0;
|
|
373
|
+
other.spilled = false;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
NodeStyleOverrideStore &NodeStyleOverrideStore::operator=(NodeStyleOverrideStore &&other) noexcept
|
|
377
|
+
{
|
|
378
|
+
if (this == &other) return *this;
|
|
379
|
+
delete[] spillValues;
|
|
380
|
+
for (std::uint8_t i = 0; i < kInlineCount; ++i)
|
|
381
|
+
inlineValues[i] = other.inlineValues[i];
|
|
382
|
+
spillValues = other.spillValues;
|
|
383
|
+
spillCount = other.spillCount;
|
|
384
|
+
spillCapacity = other.spillCapacity;
|
|
385
|
+
inlineCount = other.inlineCount;
|
|
386
|
+
spilled = other.spilled;
|
|
387
|
+
other.spillValues = nullptr;
|
|
388
|
+
other.spillCount = 0;
|
|
389
|
+
other.spillCapacity = 0;
|
|
390
|
+
other.inlineCount = 0;
|
|
391
|
+
other.spilled = false;
|
|
392
|
+
return *this;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
NodeStyleOverrideStore::~NodeStyleOverrideStore()
|
|
396
|
+
{
|
|
397
|
+
delete[] spillValues;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
void NodeStyleOverrideStore::clear()
|
|
401
|
+
{
|
|
402
|
+
if (spilled)
|
|
403
|
+
spillCount = 0;
|
|
404
|
+
else
|
|
405
|
+
inlineCount = 0;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
void NodeStyleOverrideStore::set(Property property, int value)
|
|
409
|
+
{
|
|
410
|
+
for (std::size_t i = 0, n = size(); i < n; ++i) {
|
|
411
|
+
auto &entry = styleOverrideAt(*this, i);
|
|
412
|
+
if (entry.property != property) continue;
|
|
413
|
+
entry.value = value;
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
appendStyleOverride(*this, {property, value});
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
bool NodeStyleOverrideStore::remove(Property property)
|
|
420
|
+
{
|
|
421
|
+
for (std::size_t i = 0, n = size(); i < n; ++i) {
|
|
422
|
+
if (at(i).property != property) continue;
|
|
423
|
+
if (spilled) {
|
|
424
|
+
for (std::size_t j = i + 1; j < spillCount; ++j)
|
|
425
|
+
spillValues[j - 1] = spillValues[j];
|
|
426
|
+
--spillCount;
|
|
427
|
+
} else {
|
|
428
|
+
for (std::size_t j = i + 1; j < inlineCount; ++j)
|
|
429
|
+
inlineValues[j - 1] = inlineValues[j];
|
|
430
|
+
--inlineCount;
|
|
431
|
+
}
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
const NodeStyleOverride &NodeStyleOverrideStore::at(std::size_t index) const
|
|
438
|
+
{
|
|
439
|
+
return spilled ? spillValues[index] : inlineValues[index];
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
void NodeCustomPropertyStore::clear()
|
|
443
|
+
{
|
|
444
|
+
values.clear();
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
void NodeCustomPropertyStore::set(const std::string &name, const std::string &value)
|
|
448
|
+
{
|
|
449
|
+
if (name.empty()) return;
|
|
450
|
+
set(internCssAtom(name), value);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
CssAtomId customPropertyValueAtom(const std::string &value)
|
|
454
|
+
{
|
|
455
|
+
return value.empty() ? kInvalidCssAtom : internCssAtom(value);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
void NodeCustomPropertyStore::set(CssAtomId nameId, const std::string &value)
|
|
459
|
+
{
|
|
460
|
+
if (nameId == kInvalidCssAtom) return;
|
|
461
|
+
for (auto &entry : values) {
|
|
462
|
+
if (entry.nameId != nameId) continue;
|
|
463
|
+
entry.value = value;
|
|
464
|
+
entry.valueAtom = customPropertyValueAtom(value);
|
|
465
|
+
entry.flags = 0;
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
NodeCustomProperty entry;
|
|
469
|
+
entry.nameId = nameId;
|
|
470
|
+
entry.value = value;
|
|
471
|
+
entry.valueAtom = customPropertyValueAtom(value);
|
|
472
|
+
values.push_back(std::move(entry));
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
void NodeCustomPropertyStore::setColor(CssAtomId nameId,
|
|
476
|
+
const std::string &value,
|
|
477
|
+
std::int32_t styleColor,
|
|
478
|
+
std::int32_t nativeColor,
|
|
479
|
+
std::uint8_t alpha)
|
|
480
|
+
{
|
|
481
|
+
if (nameId == kInvalidCssAtom) return;
|
|
482
|
+
for (auto &entry : values) {
|
|
483
|
+
if (entry.nameId != nameId) continue;
|
|
484
|
+
entry.value = value;
|
|
485
|
+
entry.valueAtom = customPropertyValueAtom(value);
|
|
486
|
+
entry.colorStyle = styleColor;
|
|
487
|
+
entry.colorNative = nativeColor;
|
|
488
|
+
entry.colorAlpha = alpha;
|
|
489
|
+
entry.flags = static_cast<std::uint8_t>((entry.flags & ~2u) | 1u);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
NodeCustomProperty entry;
|
|
493
|
+
entry.nameId = nameId;
|
|
494
|
+
entry.value = value;
|
|
495
|
+
entry.valueAtom = customPropertyValueAtom(value);
|
|
496
|
+
entry.colorStyle = styleColor;
|
|
497
|
+
entry.colorNative = nativeColor;
|
|
498
|
+
entry.colorAlpha = alpha;
|
|
499
|
+
entry.flags = 1;
|
|
500
|
+
values.push_back(std::move(entry));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
void NodeCustomPropertyStore::setLength(CssAtomId nameId,
|
|
504
|
+
const std::string &value,
|
|
505
|
+
float lengthValue,
|
|
506
|
+
std::uint8_t lengthUnit)
|
|
507
|
+
{
|
|
508
|
+
if (nameId == kInvalidCssAtom) return;
|
|
509
|
+
for (auto &entry : values) {
|
|
510
|
+
if (entry.nameId != nameId) continue;
|
|
511
|
+
entry.value = value;
|
|
512
|
+
entry.valueAtom = customPropertyValueAtom(value);
|
|
513
|
+
entry.lengthValue = lengthValue;
|
|
514
|
+
entry.lengthUnit = lengthUnit;
|
|
515
|
+
entry.flags = static_cast<std::uint8_t>((entry.flags & ~1u) | 2u);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
NodeCustomProperty entry;
|
|
519
|
+
entry.nameId = nameId;
|
|
520
|
+
entry.value = value;
|
|
521
|
+
entry.valueAtom = customPropertyValueAtom(value);
|
|
522
|
+
entry.lengthValue = lengthValue;
|
|
523
|
+
entry.lengthUnit = lengthUnit;
|
|
524
|
+
entry.flags = 2;
|
|
525
|
+
values.push_back(std::move(entry));
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
const std::string *NodeCustomPropertyStore::get(const std::string &name) const
|
|
529
|
+
{
|
|
530
|
+
if (name.empty()) return nullptr;
|
|
531
|
+
return get(findCssAtom(name));
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const std::string *NodeCustomPropertyStore::get(CssAtomId nameId) const
|
|
535
|
+
{
|
|
536
|
+
if (nameId == kInvalidCssAtom) return nullptr;
|
|
537
|
+
if (const NodeCustomProperty *entry = getEntry(nameId)) return &entry->value;
|
|
538
|
+
return nullptr;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
const NodeCustomProperty *NodeCustomPropertyStore::getEntry(CssAtomId nameId) const
|
|
542
|
+
{
|
|
543
|
+
if (nameId == kInvalidCssAtom) return nullptr;
|
|
544
|
+
for (const auto &entry : values)
|
|
545
|
+
if (entry.nameId == nameId) return &entry;
|
|
546
|
+
return nullptr;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// File-scope lazy pointer rather than a function-local static. On this Xtensa
|
|
550
|
+
// toolchain the static-local guard is NOT inlined, so a Meyers singleton pays a
|
|
551
|
+
// __cxa_guard_acquire CALL on every access — and treeState() sits on the hottest
|
|
552
|
+
// style-recompute path (called per rule, per node). UI state is single-threaded
|
|
553
|
+
// (the mount task and the frame task never run concurrently), so the guard is
|
|
554
|
+
// unnecessary; a zero-initialized pointer + null check is one load and a branch.
|
|
555
|
+
static TreeState *g_treeState = nullptr;
|
|
556
|
+
|
|
557
|
+
TreeState &treeState()
|
|
558
|
+
{
|
|
559
|
+
if (!g_treeState) {
|
|
560
|
+
#if defined(ESP_PLATFORM)
|
|
561
|
+
// The tree pool belongs in PSRAM (it's CPU/cache-only, never DMA), so it
|
|
562
|
+
// doesn't eat the scarce internal SRAM the radios need. esp_psram is brought
|
|
563
|
+
// up before app code runs (CONFIG_SPIRAM_BOOT_INIT), so the first access
|
|
564
|
+
// here lands in PSRAM directly.
|
|
565
|
+
void *mem = heap_caps_malloc(sizeof(TreeState), MALLOC_CAP_SPIRAM);
|
|
566
|
+
g_treeState = mem ? new (mem) TreeState() : new TreeState();
|
|
567
|
+
#else
|
|
568
|
+
g_treeState = new TreeState();
|
|
569
|
+
#endif
|
|
570
|
+
}
|
|
571
|
+
return *g_treeState;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
} // namespace gea::embedded::ui
|