@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
package/ui/tree_events.h
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "css_atom.h"
|
|
5
|
+
#include "events.h"
|
|
6
|
+
#include "node_model.h"
|
|
7
|
+
|
|
8
|
+
#include <cstdint>
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
namespace gea::embedded::ui {
|
|
13
|
+
|
|
14
|
+
inline constexpr int kMaxNodeAttributes = 8;
|
|
15
|
+
inline constexpr int kNodeAttributeNameMax = 32;
|
|
16
|
+
inline constexpr int kNodeAttributeValueMax = 64;
|
|
17
|
+
|
|
18
|
+
struct NodeAttribute {
|
|
19
|
+
char name[kNodeAttributeNameMax]{};
|
|
20
|
+
char value[kNodeAttributeValueMax]{};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
struct NodeAttributeStore {
|
|
24
|
+
int16_t pressId = -1;
|
|
25
|
+
int16_t pressValue = -1;
|
|
26
|
+
CssAtomId idAtom = kInvalidCssAtom;
|
|
27
|
+
uint8_t count = 0;
|
|
28
|
+
NodeAttribute values[kMaxNodeAttributes]{};
|
|
29
|
+
|
|
30
|
+
void clear();
|
|
31
|
+
void set(const char *name, const char *value);
|
|
32
|
+
bool remove(const char *name);
|
|
33
|
+
const char *get(const char *name) const;
|
|
34
|
+
bool has(const char *name) const;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
using gea::framework::events::EventListenerId;
|
|
38
|
+
using gea::framework::events::kInvalidEventListenerId;
|
|
39
|
+
|
|
40
|
+
struct NodeEventListenerEntry {
|
|
41
|
+
EventListenerId id = kInvalidEventListenerId;
|
|
42
|
+
std::shared_ptr<gea::framework::events::EventListener> listener;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
struct NodeEventListenerList {
|
|
46
|
+
std::vector<NodeEventListenerEntry> entries;
|
|
47
|
+
|
|
48
|
+
bool empty() const { return entries.empty(); }
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
struct NodeEventListeners {
|
|
52
|
+
NodeEventListenerList click;
|
|
53
|
+
NodeEventListenerList touchstart;
|
|
54
|
+
NodeEventListenerList touchmove;
|
|
55
|
+
NodeEventListenerList touchend;
|
|
56
|
+
NodeEventListenerList input;
|
|
57
|
+
NodeEventListenerList keydown;
|
|
58
|
+
|
|
59
|
+
void clear();
|
|
60
|
+
NodeEventListenerList *listenersFor(const char *type);
|
|
61
|
+
const NodeEventListenerList *listenersFor(const char *type) const;
|
|
62
|
+
bool hasAny() const;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// NOTE: the NodeRareData block (which bundles attributes + listeners + other
|
|
66
|
+
// cold per-node state) is defined in tree_state.h, after the remaining
|
|
67
|
+
// cold-state structs (NodeCustomPropertyStore, VirtualListNodeState) it embeds.
|
|
68
|
+
|
|
69
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "canvas.h"
|
|
5
|
+
#include "events.h"
|
|
6
|
+
#include "node_model.h"
|
|
7
|
+
#include "style.h"
|
|
8
|
+
|
|
9
|
+
#include <string>
|
|
10
|
+
|
|
11
|
+
namespace gea::embedded::ui {
|
|
12
|
+
|
|
13
|
+
class Tree {
|
|
14
|
+
public:
|
|
15
|
+
static Tree &instance();
|
|
16
|
+
|
|
17
|
+
Node *nodes();
|
|
18
|
+
const Node *nodes() const;
|
|
19
|
+
Node &node(int id);
|
|
20
|
+
const Node &node(int id) const;
|
|
21
|
+
int nodeCount() const;
|
|
22
|
+
int mountedRoot() const;
|
|
23
|
+
int mountedWidth() const;
|
|
24
|
+
int mountedHeight() const;
|
|
25
|
+
|
|
26
|
+
int createNode(NodeType type);
|
|
27
|
+
int createView();
|
|
28
|
+
int createButton();
|
|
29
|
+
int createText();
|
|
30
|
+
int createImage();
|
|
31
|
+
int createCanvas();
|
|
32
|
+
int createCamera();
|
|
33
|
+
int createAudio();
|
|
34
|
+
int createVirtualList();
|
|
35
|
+
// Deep/shallow duplicate of a node subtree (DOM cloneNode semantics: copies
|
|
36
|
+
// tag, text, attributes, classes, styles; NOT event listeners; the clone is
|
|
37
|
+
// detached until the caller parents it).
|
|
38
|
+
int cloneNode(int sourceId, bool deep);
|
|
39
|
+
|
|
40
|
+
// DOM-style child traversal for compiled templates (firstChild/childNodes[i]).
|
|
41
|
+
int firstChildOf(int node);
|
|
42
|
+
int childAt(int node, int index);
|
|
43
|
+
|
|
44
|
+
void setParent(int child, int parent);
|
|
45
|
+
void insertBefore(int child, int parent, int reference);
|
|
46
|
+
void setStyle(int node, Property prop, int value);
|
|
47
|
+
void setDefaultStyle(int node, Property prop, int value);
|
|
48
|
+
void setStyleFromClass(int node, Property prop, int value);
|
|
49
|
+
void resetStyleForClassRecompute(int node);
|
|
50
|
+
void setText(int node, const char *text);
|
|
51
|
+
void setAttribute(int node, const char *name, const char *value);
|
|
52
|
+
void removeAttribute(int node, const char *name);
|
|
53
|
+
bool toggleAttribute(int node, const char *name, bool force);
|
|
54
|
+
const char *getAttribute(int node, const char *name) const;
|
|
55
|
+
bool hasAttribute(int node, const char *name) const;
|
|
56
|
+
void setTagName(int node, const char *tagName);
|
|
57
|
+
const char *tagName(int node) const;
|
|
58
|
+
void setClassName(int node, const char *className);
|
|
59
|
+
void setClassName(int node, const std::string &className);
|
|
60
|
+
bool addClass(int node, const std::string &token);
|
|
61
|
+
bool removeClass(int node, const std::string &token);
|
|
62
|
+
bool toggleClass(int node, const std::string &token);
|
|
63
|
+
bool toggleClass(int node, const std::string &token, bool force);
|
|
64
|
+
void clearClasses(int node);
|
|
65
|
+
bool hasClass(int node, const std::string &token) const;
|
|
66
|
+
std::string className(int node) const;
|
|
67
|
+
void setPressId(int node, int pressId);
|
|
68
|
+
int pressId(int node) const;
|
|
69
|
+
void setPressValue(int node, int pressValue);
|
|
70
|
+
int pressValue(int node) const;
|
|
71
|
+
gea::framework::events::EventListenerId setEventListener(int node, const char *type, gea::framework::events::EventListener listener);
|
|
72
|
+
bool removeEventListener(int node, const char *type, gea::framework::events::EventListenerId listenerId);
|
|
73
|
+
bool hasEventListener(int node) const;
|
|
74
|
+
// True if any node currently has a listener for `type` (a DOM event-type
|
|
75
|
+
// string, e.g. "touchmove"). Dispatchers query this to skip building and
|
|
76
|
+
// walking an event nobody listens to. Conservatively returns true for
|
|
77
|
+
// event types not tracked by the listener tables.
|
|
78
|
+
bool hasListenersForType(const char *type) const;
|
|
79
|
+
bool dispatchEvent(gea::framework::events::PointerEvent &event);
|
|
80
|
+
bool containsNode(int ancestor, int node) const;
|
|
81
|
+
void removeNode(int node);
|
|
82
|
+
gea::framework::graphics::Canvas *ensureCanvas(int node, int width = 0, int height = 0);
|
|
83
|
+
const gea::framework::graphics::Canvas *canvas(int node) const;
|
|
84
|
+
bool canUseDisplayBackedCanvas(int node, int width = 0, int height = 0);
|
|
85
|
+
bool markDisplayBackedCanvas(int node, int width = 0, int height = 0);
|
|
86
|
+
bool isDisplayBackedCanvas(int node) const;
|
|
87
|
+
void displayBackedFailDebug(int *reason, int *extra, int *count) const;
|
|
88
|
+
void canvasSlotDebug(int id, int *mode, int *rebinds) const;
|
|
89
|
+
void markCanvasDirty(int node);
|
|
90
|
+
|
|
91
|
+
// A <camera> leaf reuses the same per-node RGB565 surface machinery as a
|
|
92
|
+
// canvas, but the pixels are produced by the platform camera backend each
|
|
93
|
+
// frame (framebuffer preview mode) rather than by app drawing calls.
|
|
94
|
+
gea::framework::graphics::Canvas *ensureCameraSurface(int node, int width = 0, int height = 0);
|
|
95
|
+
|
|
96
|
+
void mount(int root, int width, int height);
|
|
97
|
+
void refresh(int root, int width, int height);
|
|
98
|
+
// Native targets (macOS) that bypass the display-list pipeline and drive
|
|
99
|
+
// platform widgets directly need just the flex-layout pass without any
|
|
100
|
+
// rendering / dirty-region / present side effects. computeLayout is that
|
|
101
|
+
// pass in isolation; other targets keep calling refresh() unchanged.
|
|
102
|
+
void computeLayout(int root, int width, int height);
|
|
103
|
+
void frame(int timestampMs);
|
|
104
|
+
void clear();
|
|
105
|
+
|
|
106
|
+
int hitTest(int x, int y);
|
|
107
|
+
int hitTestNode(int x, int y);
|
|
108
|
+
void pointerDown(int x, int y);
|
|
109
|
+
int pointerMove(int x, int y);
|
|
110
|
+
int pointerUp();
|
|
111
|
+
// Programmatic vertical scroll of the first scrollable container by `dy`
|
|
112
|
+
// layout px (positive = scroll toward the end of the content). Drives the
|
|
113
|
+
// default Up/Down-button scroll on touchless hardware. Returns true if the
|
|
114
|
+
// scroll offset changed.
|
|
115
|
+
bool scrollByKeyStep(int dy);
|
|
116
|
+
void tickInput(int timestampMs);
|
|
117
|
+
void resetInput();
|
|
118
|
+
int scrollLeft(int node) const;
|
|
119
|
+
void setScrollLeft(int node, int scrollLeft);
|
|
120
|
+
int scrollTop(int node) const;
|
|
121
|
+
void setScrollTop(int node, int scrollTop);
|
|
122
|
+
void scrollIntoView(int node);
|
|
123
|
+
void applyPendingScrollIntoView();
|
|
124
|
+
|
|
125
|
+
// Active focus for `<input>` elements. Pixel-only targets can paint the
|
|
126
|
+
// caret + open the virtual keyboard based on this; native text targets
|
|
127
|
+
// can use their platform responder/focus chain instead.
|
|
128
|
+
// setActiveInput(-1) clears focus.
|
|
129
|
+
int activeInputId() const;
|
|
130
|
+
void setActiveInput(int nodeId);
|
|
131
|
+
bool activeInputCaretVisible() const;
|
|
132
|
+
void tickInputCaret(int timestampMs);
|
|
133
|
+
|
|
134
|
+
void markDisplayListDirty();
|
|
135
|
+
void markDisplayListContentDirty();
|
|
136
|
+
void markNodeDisplayCommandsDirty(int node);
|
|
137
|
+
void markScrollDirty(int node);
|
|
138
|
+
bool displayListRebuildRequired() const;
|
|
139
|
+
bool refreshRequired() const;
|
|
140
|
+
// Bumped on every mount()/refresh(); native renderers diff against the last
|
|
141
|
+
// value they synced to decide whether a re-sync is needed at all.
|
|
142
|
+
uint64_t refreshSerial() const;
|
|
143
|
+
void setDisplayListRebuildRequired(bool required);
|
|
144
|
+
bool nodeDisplayCommandsDirty(int node) const;
|
|
145
|
+
void clearNodeDisplayCommandDirty(int node);
|
|
146
|
+
|
|
147
|
+
int lastFrameMs() const;
|
|
148
|
+
void setLastFrameMs(int timestampMs);
|
|
149
|
+
|
|
150
|
+
private:
|
|
151
|
+
Tree() = default;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// Document-level (off-tree) events: `rotary` always, and `keydown` bound on a
|
|
155
|
+
// non-input element. These belong to `document`, not to any node, so they are
|
|
156
|
+
// stored as singletons (not per-node listener slots) and dispatched directly by
|
|
157
|
+
// the runtime rather than through Tree::dispatchEvent's tree walk.
|
|
158
|
+
void setDocumentEventListener(const char *type, gea::framework::events::EventListener listener);
|
|
159
|
+
void dispatchDocumentRotary(int delta);
|
|
160
|
+
bool dispatchDocumentKeyDown(gea::framework::events::PointerEvent &event);
|
|
161
|
+
void resetDocumentEventListeners();
|
|
162
|
+
void resetDocumentDelegatedEventListeners();
|
|
163
|
+
|
|
164
|
+
// Deliver a pointer/touch event straight to document-level listeners with no
|
|
165
|
+
// tree walk. Immediate-mode apps (Display.ctx games) mount no UI tree, so there
|
|
166
|
+
// is no root node to bubble to or to bind document listeners onto; without this
|
|
167
|
+
// path, `document.addEventListener('pointerdown', …)` would never fire on-device
|
|
168
|
+
// (it does on web, where the DOM document sees every pointer event). Returns true
|
|
169
|
+
// if any listener ran. Caller invokes this only when no UI tree is mounted.
|
|
170
|
+
bool dispatchDocumentPointer(gea::framework::events::PointerEvent &event);
|
|
171
|
+
|
|
172
|
+
// Tag interning: the per-node tag is stored as a small int16 id (Node::tag_id)
|
|
173
|
+
// indexing a global table of unique tag strings, instead of a 16-byte inline
|
|
174
|
+
// buffer. internTag returns the id for a tag string (creating it on first use);
|
|
175
|
+
// tagFromId returns the stable interned string (id 0 = "").
|
|
176
|
+
int16_t internTag(const char *tag);
|
|
177
|
+
const char *tagFromId(int16_t id);
|
|
178
|
+
|
|
179
|
+
// Blink-style rare-data pool accessors. A node's cold/optional state lives in a
|
|
180
|
+
// pooled NodeRareData block referenced by Node::rare_data (-1 = none).
|
|
181
|
+
struct NodeRareData;
|
|
182
|
+
NodeRareData &ensureRareData(int node); // allocates a block on first use
|
|
183
|
+
NodeRareData *rareDataFor(int node); // nullptr when the node has none
|
|
184
|
+
void releaseRareData(int node); // frees the block back to the pool
|
|
185
|
+
|
|
186
|
+
// Re-replay the live retained display list full-screen into `dst` (rgb565) for a
|
|
187
|
+
// screenshot, working around the fused flush leaving the PSRAM framebuffer stale.
|
|
188
|
+
// Caller must hold AppState::lock(). Returns false for canvas/present apps.
|
|
189
|
+
bool renderRetainedSnapshotRgb565(std::uint16_t *dst, int width, int height);
|
|
190
|
+
|
|
191
|
+
} // namespace gea::embedded::ui
|