@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/css/engine.h
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
//
|
|
4
|
+
// gea::css — the animation engine/driver. Holds the active animations, advances
|
|
5
|
+
// them each frame, and applies the interpolated value to the target node via
|
|
6
|
+
// ui::Style. Tick from the frame loop. Header-only (inline) so it links into any
|
|
7
|
+
// TU that uses it without a build source-list change. The singleton lives in an
|
|
8
|
+
// inline function-local static (one instance across all TUs). See
|
|
9
|
+
// docs/geaos-grand-vision.md (M1).
|
|
10
|
+
|
|
11
|
+
#include <algorithm>
|
|
12
|
+
#include <array>
|
|
13
|
+
#include <cmath>
|
|
14
|
+
#include <cstdint>
|
|
15
|
+
#include <cstddef>
|
|
16
|
+
#include <utility>
|
|
17
|
+
#include <vector>
|
|
18
|
+
|
|
19
|
+
#include "../ui/style.h"
|
|
20
|
+
#include "animation.h"
|
|
21
|
+
|
|
22
|
+
#ifndef GEA_CSS_ANIMATION_INLINE_RUNNING
|
|
23
|
+
#define GEA_CSS_ANIMATION_INLINE_RUNNING 8
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace gea::css {
|
|
27
|
+
|
|
28
|
+
class AnimationEngine {
|
|
29
|
+
public:
|
|
30
|
+
static AnimationEngine &instance()
|
|
31
|
+
{
|
|
32
|
+
static AnimationEngine engine;
|
|
33
|
+
return engine;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Register an animation; returns a handle (>0) for later cancel.
|
|
37
|
+
int start(Animation a, uint32_t nowMs)
|
|
38
|
+
{
|
|
39
|
+
const int handle = nextHandle_++;
|
|
40
|
+
running_.push_back(Running{std::move(a), nowMs, handle});
|
|
41
|
+
return handle;
|
|
42
|
+
}
|
|
43
|
+
void cancel(int handle)
|
|
44
|
+
{
|
|
45
|
+
running_.eraseIf([&](const Running &r) { return r.handle == handle; });
|
|
46
|
+
}
|
|
47
|
+
void cancelNode(int nodeId) // cancel all animations targeting a node
|
|
48
|
+
{
|
|
49
|
+
running_.eraseIf([&](const Running &r) { return r.anim.nodeId == nodeId; });
|
|
50
|
+
}
|
|
51
|
+
void clear() { running_.clear(); }
|
|
52
|
+
|
|
53
|
+
bool active() const { return !running_.empty(); }
|
|
54
|
+
std::size_t count() const { return running_.size(); }
|
|
55
|
+
|
|
56
|
+
// Advance all animations to `nowMs`, applying values and dropping finished
|
|
57
|
+
// ones (forwards-fill holds the final value before removal). Call once/frame.
|
|
58
|
+
void tick(uint32_t nowMs)
|
|
59
|
+
{
|
|
60
|
+
for (std::size_t i = 0; i < running_.size();) {
|
|
61
|
+
const Running &first = running_[i];
|
|
62
|
+
const double elapsed = static_cast<double>(static_cast<int32_t>(nowMs - first.startMs));
|
|
63
|
+
const Progress pr = computeProgress(first.anim, elapsed);
|
|
64
|
+
std::size_t groupEnd = i + 1;
|
|
65
|
+
while (groupEnd < running_.size() && sameTimeline(first, running_[groupEnd])) ++groupEnd;
|
|
66
|
+
if (pr.active) {
|
|
67
|
+
for (std::size_t j = i; j < groupEnd; ++j) {
|
|
68
|
+
applyValue(running_[j].anim, sampleTrack(running_[j].anim, pr.p));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (pr.done)
|
|
72
|
+
running_.erase(i, groupEnd);
|
|
73
|
+
else
|
|
74
|
+
i = groupEnd;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private:
|
|
79
|
+
AnimationEngine() = default;
|
|
80
|
+
|
|
81
|
+
struct Running {
|
|
82
|
+
Animation anim;
|
|
83
|
+
uint32_t startMs;
|
|
84
|
+
int handle;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
class RunningList {
|
|
88
|
+
public:
|
|
89
|
+
bool empty() const { return size() == 0; }
|
|
90
|
+
std::size_t size() const { return spilled_ ? spill_.size() : count_; }
|
|
91
|
+
|
|
92
|
+
Running &operator[](std::size_t index) { return spilled_ ? spill_[index] : inline_[index]; }
|
|
93
|
+
const Running &operator[](std::size_t index) const { return spilled_ ? spill_[index] : inline_[index]; }
|
|
94
|
+
|
|
95
|
+
void push_back(Running value)
|
|
96
|
+
{
|
|
97
|
+
if (spilled_) {
|
|
98
|
+
spill_.push_back(std::move(value));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (count_ < kInlineCapacity) {
|
|
102
|
+
inline_[count_++] = std::move(value);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
spillToVector(kInlineCapacity + 1);
|
|
106
|
+
spill_.push_back(std::move(value));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
void erase(std::size_t first, std::size_t last)
|
|
110
|
+
{
|
|
111
|
+
if (first >= last) return;
|
|
112
|
+
if (spilled_) {
|
|
113
|
+
spill_.erase(spill_.begin() + static_cast<std::ptrdiff_t>(first),
|
|
114
|
+
spill_.begin() + static_cast<std::ptrdiff_t>(last));
|
|
115
|
+
if (spill_.size() <= kInlineCapacity) moveSpillBackInline();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const std::size_t removed = last - first;
|
|
119
|
+
for (std::size_t read = last; read < count_; ++read) {
|
|
120
|
+
inline_[read - removed] = std::move(inline_[read]);
|
|
121
|
+
}
|
|
122
|
+
const std::size_t nextCount = count_ - removed;
|
|
123
|
+
for (std::size_t i = nextCount; i < count_; ++i) inline_[i] = Running{};
|
|
124
|
+
count_ = nextCount;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
template <typename Predicate>
|
|
128
|
+
void eraseIf(Predicate pred)
|
|
129
|
+
{
|
|
130
|
+
if (spilled_) {
|
|
131
|
+
spill_.erase(std::remove_if(spill_.begin(), spill_.end(), pred), spill_.end());
|
|
132
|
+
if (spill_.size() <= kInlineCapacity) moveSpillBackInline();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
std::size_t write = 0;
|
|
136
|
+
for (std::size_t read = 0; read < count_; ++read) {
|
|
137
|
+
if (pred(inline_[read])) continue;
|
|
138
|
+
if (write != read) inline_[write] = std::move(inline_[read]);
|
|
139
|
+
++write;
|
|
140
|
+
}
|
|
141
|
+
for (std::size_t i = write; i < count_; ++i) inline_[i] = Running{};
|
|
142
|
+
count_ = write;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
void clear()
|
|
146
|
+
{
|
|
147
|
+
if (spilled_) {
|
|
148
|
+
std::vector<Running>().swap(spill_);
|
|
149
|
+
spilled_ = false;
|
|
150
|
+
count_ = 0;
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
for (std::size_t i = 0; i < count_; ++i) inline_[i] = Running{};
|
|
154
|
+
count_ = 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
private:
|
|
158
|
+
static constexpr std::size_t kInlineCapacity =
|
|
159
|
+
static_cast<std::size_t>(GEA_CSS_ANIMATION_INLINE_RUNNING);
|
|
160
|
+
|
|
161
|
+
void spillToVector(std::size_t reserveCount)
|
|
162
|
+
{
|
|
163
|
+
if (spilled_) {
|
|
164
|
+
spill_.reserve(reserveCount);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
spill_.reserve(reserveCount);
|
|
168
|
+
for (std::size_t i = 0; i < count_; ++i) spill_.push_back(std::move(inline_[i]));
|
|
169
|
+
for (std::size_t i = 0; i < count_; ++i) inline_[i] = Running{};
|
|
170
|
+
count_ = 0;
|
|
171
|
+
spilled_ = true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
void moveSpillBackInline()
|
|
175
|
+
{
|
|
176
|
+
if (!spilled_ || spill_.size() > kInlineCapacity) return;
|
|
177
|
+
count_ = spill_.size();
|
|
178
|
+
for (std::size_t i = 0; i < count_; ++i) inline_[i] = std::move(spill_[i]);
|
|
179
|
+
std::vector<Running>().swap(spill_);
|
|
180
|
+
spilled_ = false;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
std::array<Running, kInlineCapacity> inline_{};
|
|
184
|
+
std::vector<Running> spill_;
|
|
185
|
+
std::size_t count_ = 0;
|
|
186
|
+
bool spilled_ = false;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
static bool sameTimeline(const Running &a, const Running &b)
|
|
190
|
+
{
|
|
191
|
+
return a.startMs == b.startMs && a.anim.durationMs == b.anim.durationMs &&
|
|
192
|
+
a.anim.delayMs == b.anim.delayMs && a.anim.iterations == b.anim.iterations &&
|
|
193
|
+
a.anim.direction == b.anim.direction && a.anim.fill == b.anim.fill;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
static void applyValue(const Animation &a, double value)
|
|
197
|
+
{
|
|
198
|
+
using gea::embedded::ui::Property;
|
|
199
|
+
using gea::embedded::ui::applyAnimatedStyleValue;
|
|
200
|
+
switch (a.kind) {
|
|
201
|
+
case ValueKind::Angle:
|
|
202
|
+
applyAnimatedStyleValue(a.nodeId, a.property, static_cast<int>(std::llround(value * 10.0)));
|
|
203
|
+
return;
|
|
204
|
+
case ValueKind::Color: {
|
|
205
|
+
const int rgb565 = static_cast<int>(std::llround(value));
|
|
206
|
+
applyAnimatedStyleValue(a.nodeId, a.property, rgb565);
|
|
207
|
+
if (a.property == Property::BackgroundColor)
|
|
208
|
+
applyAnimatedStyleValue(a.nodeId, Property::HasBackground, 1);
|
|
209
|
+
else if (a.property == Property::ActiveBackgroundColor)
|
|
210
|
+
applyAnimatedStyleValue(a.nodeId, Property::HasActiveBackground, 1);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
case ValueKind::Scalar:
|
|
214
|
+
applyAnimatedStyleValue(a.nodeId, a.property, static_cast<int>(std::llround(value)));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
RunningList running_;
|
|
220
|
+
int nextHandle_ = 1;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
} // namespace gea::css
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
//
|
|
4
|
+
// gea::css — value interpolation for animated CSS properties. Pure math, no UI
|
|
5
|
+
// coupling (the Property→kind mapping lives in the animation layer). Header-only
|
|
6
|
+
// (inline). Part of the gea CSS animation engine. See docs/geaos-grand-vision.md (M1).
|
|
7
|
+
|
|
8
|
+
#include <cmath>
|
|
9
|
+
|
|
10
|
+
namespace gea::css {
|
|
11
|
+
|
|
12
|
+
// Linear interpolation for scalar / angle property values. t is the eased
|
|
13
|
+
// progress; overshoot (t<0 or t>1, e.g. spring-like cubic-beziers) is allowed —
|
|
14
|
+
// callers clamp the *property* range where it matters.
|
|
15
|
+
inline double lerp(double from, double to, double t) { return from + (to - from) * t; }
|
|
16
|
+
|
|
17
|
+
namespace detail {
|
|
18
|
+
inline int clampi(int v, int lo, int hi) { return v < lo ? lo : (v > hi ? hi : v); }
|
|
19
|
+
inline int roundi(double v) { return static_cast<int>(std::lround(v)); }
|
|
20
|
+
} // namespace detail
|
|
21
|
+
|
|
22
|
+
// Interpolate two RGB565 colors. Interpolating the packed 16-bit int directly is
|
|
23
|
+
// wrong (channels bleed), so unpack R5/G6/B5, lerp each channel, clamp, repack.
|
|
24
|
+
inline int lerpColor565(int fromRgb565, int toRgb565, double t)
|
|
25
|
+
{
|
|
26
|
+
const int ar = (fromRgb565 >> 11) & 0x1F;
|
|
27
|
+
const int ag = (fromRgb565 >> 5) & 0x3F;
|
|
28
|
+
const int ab = fromRgb565 & 0x1F;
|
|
29
|
+
const int br = (toRgb565 >> 11) & 0x1F;
|
|
30
|
+
const int bg = (toRgb565 >> 5) & 0x3F;
|
|
31
|
+
const int bb = toRgb565 & 0x1F;
|
|
32
|
+
const int r = detail::clampi(detail::roundi(lerp(ar, br, t)), 0, 0x1F);
|
|
33
|
+
const int g = detail::clampi(detail::roundi(lerp(ag, bg, t)), 0, 0x3F);
|
|
34
|
+
const int b = detail::clampi(detail::roundi(lerp(ab, bb, t)), 0, 0x1F);
|
|
35
|
+
return (r << 11) | (g << 5) | b;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
} // namespace gea::css
|