@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.
Files changed (86) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +29 -0
  3. package/bitmap_font.cpp +165 -0
  4. package/canvas.cpp +4608 -0
  5. package/components/Button.d.ts +4 -0
  6. package/components/Button.tsx +32 -0
  7. package/components/Image.d.ts +3 -0
  8. package/components/Image.tsx +17 -0
  9. package/components/Text.d.ts +3 -0
  10. package/components/Text.tsx +9 -0
  11. package/components/View.d.ts +3 -0
  12. package/components/View.tsx +24 -0
  13. package/components/index.d.ts +8 -0
  14. package/components/index.ts +4 -0
  15. package/css/animation.h +252 -0
  16. package/css/declarative.h +131 -0
  17. package/css/easing.h +160 -0
  18. package/css/engine.h +223 -0
  19. package/css/interpolate.h +38 -0
  20. package/image_store.cpp +807 -0
  21. package/package.json +62 -0
  22. package/rasterized_font.cpp +570 -0
  23. package/touch_runtime.cpp +513 -0
  24. package/ui/absolute_leaf_refresh.cpp +279 -0
  25. package/ui/absolute_leaf_refresh.h +12 -0
  26. package/ui/canvas_element.cpp +2314 -0
  27. package/ui/canvas_element.h +353 -0
  28. package/ui/canvas_store.cpp +188 -0
  29. package/ui/canvas_store.h +59 -0
  30. package/ui/core.cpp +135 -0
  31. package/ui/css_atom.cpp +155 -0
  32. package/ui/css_atom.h +21 -0
  33. package/ui/dirty_regions.cpp +66 -0
  34. package/ui/dirty_regions.h +34 -0
  35. package/ui/display_invalidation.cpp +101 -0
  36. package/ui/display_invalidation.h +15 -0
  37. package/ui/document.cpp +356 -0
  38. package/ui/document.h +101 -0
  39. package/ui/image.h +16 -0
  40. package/ui/image_element.cpp +13 -0
  41. package/ui/image_node.cpp +165 -0
  42. package/ui/input.cpp +936 -0
  43. package/ui/input_render.cpp +213 -0
  44. package/ui/internal.h +567 -0
  45. package/ui/layout.cpp +2025 -0
  46. package/ui/layout_snapshot.cpp +82 -0
  47. package/ui/layout_snapshot.h +12 -0
  48. package/ui/mirror.h +25 -0
  49. package/ui/node.cpp +243 -0
  50. package/ui/node.h +154 -0
  51. package/ui/node_lifecycle.cpp +137 -0
  52. package/ui/node_lifecycle.h +13 -0
  53. package/ui/node_model.h +597 -0
  54. package/ui/refresh_perf.h +235 -0
  55. package/ui/refresh_trace.h +68 -0
  56. package/ui/render.cpp +12097 -0
  57. package/ui/root_scroll_refresh.cpp +859 -0
  58. package/ui/root_scroll_refresh.h +30 -0
  59. package/ui/state_init.h +21 -0
  60. package/ui/style.cpp +14994 -0
  61. package/ui/style.h +727 -0
  62. package/ui/style_values.h +31 -0
  63. package/ui/text.cpp +2010 -0
  64. package/ui/text.h +15 -0
  65. package/ui/text_element.cpp +15 -0
  66. package/ui/tree_events.cpp +621 -0
  67. package/ui/tree_events.h +69 -0
  68. package/ui/tree_internal.h +191 -0
  69. package/ui/tree_nodes.cpp +628 -0
  70. package/ui/tree_render.cpp +3138 -0
  71. package/ui/tree_scroll_mirror.cpp +101 -0
  72. package/ui/tree_state.cpp +574 -0
  73. package/ui/tree_state.h +235 -0
  74. package/ui/tree_style.cpp +698 -0
  75. package/ui/ui.h +9 -0
  76. package/ui/view.cpp +2232 -0
  77. package/ui/view.h +14 -0
  78. package/ui/view_element.cpp +13 -0
  79. package/ui/viewport_region.cpp +36 -0
  80. package/ui/viewport_region.h +12 -0
  81. package/ui/virtual_keyboard.cpp +908 -0
  82. package/ui/virtual_keyboard.h +59 -0
  83. package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
  84. package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
  85. package/vendor/stb/stb_image.h +7988 -0
  86. package/vendor/stb/stb_truetype.h +5079 -0
@@ -0,0 +1,213 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // `<input>` rendering for the pixel-backed display targets (ESP32 etc.).
3
+ //
4
+ // JSX `<input>` falls through createElement to createView() (host_document_gea
5
+ // only special-cases button/canvas/img), so input elements are View nodes with
6
+ // tag_name == "input". The framework's View pipeline draws the box / border /
7
+ // background; this file handles the per-input details that diverge from a
8
+ // plain View:
9
+ //
10
+ // 1. The user-visible text comes from the node's `value` attribute (mirrors
11
+ // DOM `input.value`), falling back to `placeholder` when value is empty.
12
+ // The macOS target paints this with an editable NSTextField; on the pixel
13
+ // target we draw the text as a DrawText display command using the same
14
+ // glyph pipeline TextRenderer uses, but with the framework reading the
15
+ // string from the attribute store rather than the Node::text buffer.
16
+ //
17
+ // 2. When the input is the active focus (Tree::activeInputId() returns its
18
+ // id) we additionally record a thin vertical caret at the end of the
19
+ // rendered text for pixel targets that keep input rendering in the
20
+ // framework.
21
+ //
22
+ // Note: this file does NOT manage focus or keyboard services themselves —
23
+ // those live in tree_events.cpp / input.cpp / virtual_keyboard.cpp. We only
24
+ // paint based on the state they expose via Tree.
25
+
26
+ #include "internal.h"
27
+ #include "graphics/font.h"
28
+ #include "pixel.h"
29
+ #include "tree_internal.h"
30
+
31
+ #include <cstring>
32
+
33
+ namespace gea::embedded::ui {
34
+
35
+ namespace {
36
+
37
+ constexpr int kInputCaretWidth = 2;
38
+ constexpr int kInputCaretInsetY = 6;
39
+ // Match text.cpp's local kBitmapFontHeight — used as the implicit font size
40
+ // when an input doesn't have an explicit font_size set, so the vertical
41
+ // centering formula here matches the height the framework's bitmap text path
42
+ // would draw at by default.
43
+ constexpr int kBitmapFontHeight = gea::framework::graphics::BitmapFont8x16::kHeight;
44
+ // #475569 (slate-600). Computed via packRgb565Components because the
45
+ // display layer byte-swaps the wire format — a raw 0x4A69 literal would
46
+ // land as BGR garbage (the "purple placeholder" symptom).
47
+ inline std::uint16_t kPlaceholderColor()
48
+ {
49
+ return gea::framework::graphics::pixel::packRgb565Components(71 / 8, 85 / 4, 105 / 8);
50
+ }
51
+
52
+ const char *inputContentText(int id, std::uint16_t *outColor, std::uint16_t textColor)
53
+ {
54
+ auto &tree = Tree::instance();
55
+ const char *value = tree.getAttribute(id, "value");
56
+ if (value && value[0]) {
57
+ if (outColor) *outColor = textColor;
58
+ return value;
59
+ }
60
+ const char *placeholder = tree.getAttribute(id, "placeholder");
61
+ if (placeholder && placeholder[0]) {
62
+ if (outColor) {
63
+ const gea::framework::graphics::pixel::native_t defaultTextColor = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
64
+ *outColor = textColor != defaultTextColor ? textColor : kPlaceholderColor();
65
+ }
66
+ return placeholder;
67
+ }
68
+ return nullptr;
69
+ }
70
+
71
+ const char *inputMeasureText(int id)
72
+ {
73
+ const char *content = inputContentText(id, nullptr, 0);
74
+ return content && content[0] ? content : "M";
75
+ }
76
+
77
+ } // namespace
78
+
79
+ void InputRenderer::layout(int id, int)
80
+ {
81
+ auto &tree = Tree::instance();
82
+ if (id < 0 || id >= tree.nodeCount()) return;
83
+ Node &n = tree.node(id);
84
+ if (n.type != NodeType::View) return;
85
+ if (std::strcmp(tagFromId(n.tag_id), "input") != 0) return;
86
+
87
+ const char *content = inputContentText(id, nullptr, n.style.text_color);
88
+ const char *measureText = inputMeasureText(id);
89
+ int width = TextRenderer::measureWidth(content, n.style.font_id, n.style.font_size, n.style.text_transform) + n.style.padding[1] + n.style.padding[3];
90
+ int height = TextRenderer::measureHeight(measureText, n.style.font_id, n.style.font_size, n.style.text_transform, n.style.line_height) + n.style.padding[0] + n.style.padding[2];
91
+
92
+ if (n.style.width != kUnset) width = n.style.width;
93
+ else if (n.style.width_percent != kUnset && n.layout.width > 0) width = n.layout.width;
94
+ if (n.style.height != kUnset) height = n.style.height;
95
+ else if (n.style.height_percent != kUnset && n.layout.height > 0) height = n.layout.height;
96
+ n.layout.width = LayoutEngine::instance().clampSize(width, n.style.min_width, n.style.max_width);
97
+ n.layout.height = LayoutEngine::instance().clampSize(height, n.style.min_height, n.style.max_height);
98
+ n.layout.scroll_content_height = n.layout.height;
99
+ n.layout.scroll_y = 0;
100
+ }
101
+
102
+ void InputRenderer::record(int id)
103
+ {
104
+ auto &tree = Tree::instance();
105
+ if (id < 0 || id >= tree.nodeCount()) return;
106
+ const Node &n = tree.node(id);
107
+ if (n.type != NodeType::View) return;
108
+ if (std::strcmp(tagFromId(n.tag_id), "input") != 0) return;
109
+
110
+ std::uint16_t color = n.style.text_color;
111
+ const char *content = inputContentText(id, &color, n.style.text_color);
112
+
113
+ const int x = n.layout.x;
114
+ const int y = n.layout.y;
115
+ const int w = n.layout.width;
116
+ const int h = n.layout.height;
117
+ const int padLeft = n.style.padding[3];
118
+ const int padRight = n.style.padding[1];
119
+ const int padTop = n.style.padding[0];
120
+ const int padBottom = n.style.padding[2];
121
+ const int contentX = x + padLeft;
122
+ const int contentY = y + padTop;
123
+ int contentW = w - padLeft - padRight;
124
+ int contentH = h - padTop - padBottom;
125
+ if (contentW < 0) contentW = 0;
126
+ if (contentH < 0) contentH = 0;
127
+
128
+ if (content) {
129
+ // Matches TextRenderer::record's scale formula. The denominator is
130
+ // the bitmap font's height (BitmapFont8x16::kHeight = 16). This
131
+ // scale is ignored when font_id selects a rasterized TTF — the font
132
+ // system rasterizes at font_size directly — but it still needs to
133
+ // be non-zero to keep the bitmap path's math consistent for callers
134
+ // without `font-family` set.
135
+ const float textScale = n.style.font_size > 0
136
+ ? static_cast<float>(n.style.font_size) / 16.0f
137
+ : 1.0f;
138
+
139
+ DisplayCommand *cmd = DisplayList::instance().append();
140
+ if (cmd) {
141
+ cmd->type = DisplayCommandType::DrawText;
142
+ cmd->bx = x; cmd->by = y; cmd->bw = w; cmd->bh = h;
143
+ cmd->text.text = content;
144
+ // `getAttribute` returns a pointer to the in-tree attribute slot, so
145
+ // the string is stable until the attribute is overwritten. The
146
+ // DisplayList commands are replayed within the same frame, so this
147
+ // stays valid for the duration of the present.
148
+ cmd->text.x = contentX;
149
+ // Vertically center the single-line text within the content area —
150
+ // inputs are conventionally one line and the framework's text
151
+ // renderer would otherwise top-align.
152
+ // 16 = BitmapFont8x16::kHeight (default when no font_size set).
153
+ const int fontSize = n.style.font_size > 0 ? n.style.font_size : 16;
154
+ const int yCenter = contentY + (contentH - fontSize) / 2;
155
+ cmd->text.y = yCenter > contentY ? yCenter : contentY;
156
+ cmd->text.maxWidth = contentW;
157
+ cmd->text.color = color;
158
+ cmd->text.scale = textScale;
159
+ cmd->text.align = n.style.text_align;
160
+ cmd->text.textTransform = n.style.text_transform;
161
+ cmd->text.lineHeight = n.style.line_height;
162
+ cmd->text.containerWidth = contentW;
163
+ cmd->text.fontId = n.style.font_id;
164
+ // append() hands back uninitialized scratch — set these explicitly so
165
+ // the deferred draw doesn't read stale white-space/text-overflow.
166
+ cmd->text.whiteSpace = n.style.white_space;
167
+ cmd->text.textOverflow = n.style.text_overflow;
168
+ cmd->text.maxHeight = 0;
169
+ cmd->text.firstLineIndent = 0;
170
+ }
171
+ }
172
+
173
+ // Caret — drawn only when this input is the active focus. The frame loop
174
+ // in tree_render.cpp flips the caret-blink phase via inputTickRequired,
175
+ // which Tree::activeInputCaretVisible() returns. Showing the caret while
176
+ // unfocused would be misleading on targets where the framework handles
177
+ // the input's visual editing state.
178
+ if (tree.activeInputId() == id && tree.activeInputCaretVisible()) {
179
+ // Caret sits at the END of the user-typed value (consistent with
180
+ // the insertion point of a real text field). When `value` is
181
+ // empty and we're falling back to the placeholder, the caret
182
+ // goes at the START of the content box — typing the first
183
+ // character would land there, and the placeholder gets visually
184
+ // pushed aside by the appearing glyph. Measuring the placeholder
185
+ // here would be wrong: it'd put the caret at the end of a
186
+ // string the user isn't actually editing.
187
+ const char *valueAttr = tree.getAttribute(id, "value");
188
+ const bool hasValue = valueAttr && valueAttr[0];
189
+ int caretX = contentX;
190
+ if (hasValue) {
191
+ const int textWidth = TextRenderer::measureWidth(valueAttr, n.style.font_id, n.style.font_size, n.style.text_transform);
192
+ caretX += textWidth < contentW ? textWidth : contentW - kInputCaretWidth;
193
+ if (caretX < contentX) caretX = contentX;
194
+ }
195
+ const int caretY = contentY + kInputCaretInsetY;
196
+ int caretH = contentH - kInputCaretInsetY * 2;
197
+ if (caretH < 4) caretH = contentH > 4 ? contentH - 2 : contentH;
198
+ const std::uint16_t caretColor = n.style.text_color ? n.style.text_color : 0xFFFF;
199
+
200
+ DisplayCommand *cmd = DisplayList::instance().append();
201
+ if (cmd) {
202
+ cmd->type = DisplayCommandType::FillRect;
203
+ cmd->bx = x; cmd->by = y; cmd->bw = w; cmd->bh = h;
204
+ cmd->fill.x = caretX;
205
+ cmd->fill.y = caretY;
206
+ cmd->fill.w = kInputCaretWidth;
207
+ cmd->fill.h = caretH;
208
+ cmd->fill.color = caretColor;
209
+ }
210
+ }
211
+ }
212
+
213
+ } // namespace gea::embedded::ui