@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,908 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// On-screen keyboard implemented as document-tree nodes.
|
|
3
|
+
//
|
|
4
|
+
// Architecture (ported from the pre-geatsc C-codegen plugin's
|
|
5
|
+
// `emitSystemKeyboardVisualRuntime`, deleted in commit 071c591a):
|
|
6
|
+
//
|
|
7
|
+
// - One "keyboard root" View, positioned absolute at the bottom of
|
|
8
|
+
// the display, z-index above the app content.
|
|
9
|
+
// - 4 row Views inside it (flex-direction:row). Each row holds up to
|
|
10
|
+
// kColCount key Views; unused slots are display:none.
|
|
11
|
+
// - Each key View holds a single Text label as its child.
|
|
12
|
+
// - Each key View carries a unique pressId in
|
|
13
|
+
// [kPressIdBase, kPressIdBase + kSlotCount). On Press, our listener
|
|
14
|
+
// on body() checks event.pressId and routes the corresponding
|
|
15
|
+
// keyCode into the focused input.
|
|
16
|
+
//
|
|
17
|
+
// Three layouts (modes): `alpha` (QWERTY), `symbols` (numeric +
|
|
18
|
+
// punctuation), `moreSymbols` (brackets / math). Mode-switch keys
|
|
19
|
+
// carry sentinel codes 1001 ("123" → symbols), 1002 ("ABC" → alpha),
|
|
20
|
+
// 1003 ("#+=" → moreSymbols). Shift (code 16) capitalizes the next
|
|
21
|
+
// character key in alpha mode; double-tap could enable caps lock but
|
|
22
|
+
// that's not wired through this port — single-shot only for now.
|
|
23
|
+
//
|
|
24
|
+
// Tap routing: when the keyboard mounts it calls
|
|
25
|
+
// `Tree::setEventListener(body, "click", …)`. That listener:
|
|
26
|
+
// 1. Reads event.pressId. If out of range, returns (lets app handler
|
|
27
|
+
// that registered via JSX onClick fire normally — they're chained
|
|
28
|
+
// by Tree::setEventListener).
|
|
29
|
+
// 2. Calls preventDefault() so the app's body-level click handlers
|
|
30
|
+
// don't see the keyboard tap as a real app tap (they'd see the
|
|
31
|
+
// keyboard's underlying View and fire spurious app actions).
|
|
32
|
+
// 3. Mutates the focused input's `value` attribute, marks the node
|
|
33
|
+
// command-dirty so the input redraws, then synthesizes `input`
|
|
34
|
+
// and `keydown` PointerEvents and dispatches them via
|
|
35
|
+
// Tree::dispatchEvent so the app's `onInput` / `onKeyDown`
|
|
36
|
+
// handlers fire.
|
|
37
|
+
|
|
38
|
+
#include "virtual_keyboard.h"
|
|
39
|
+
|
|
40
|
+
#ifndef GEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD
|
|
41
|
+
#define GEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD 1
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
#if GEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD
|
|
45
|
+
|
|
46
|
+
#include "display.h"
|
|
47
|
+
#include "internal.h"
|
|
48
|
+
#include "tree_internal.h"
|
|
49
|
+
#include "tree_state.h"
|
|
50
|
+
#include "events.h"
|
|
51
|
+
#include "pixel.h"
|
|
52
|
+
#include "style.h"
|
|
53
|
+
|
|
54
|
+
#include <cstdint>
|
|
55
|
+
#include <cstring>
|
|
56
|
+
#include <string>
|
|
57
|
+
|
|
58
|
+
namespace gea::embedded::ui {
|
|
59
|
+
|
|
60
|
+
namespace {
|
|
61
|
+
|
|
62
|
+
constexpr int kRowCount = 4;
|
|
63
|
+
constexpr int kColCount = 10;
|
|
64
|
+
constexpr int kSlotCount = kRowCount * kColCount;
|
|
65
|
+
constexpr int kPressIdBase = 30000;
|
|
66
|
+
constexpr int kKeyboardHeight = 192;
|
|
67
|
+
|
|
68
|
+
// Mode-switch / control sentinel codes (sit above the ASCII range so
|
|
69
|
+
// they never collide with a printable key).
|
|
70
|
+
constexpr int kCodeShift = 16;
|
|
71
|
+
constexpr int kCodeBackspace = 8;
|
|
72
|
+
constexpr int kCodeReturn = 13;
|
|
73
|
+
constexpr int kCodeSpace = 32;
|
|
74
|
+
constexpr int kCodeModeSymbols = 1001;
|
|
75
|
+
constexpr int kCodeModeAlpha = 1002;
|
|
76
|
+
constexpr int kCodeModeMoreSymbols = 1003;
|
|
77
|
+
|
|
78
|
+
enum class KeyKind : std::uint8_t { Light = 0, Utility = 1, Primary = 2 };
|
|
79
|
+
enum class LabelKind : std::uint8_t { Normal = 0, Wide = 1, Small = 2 };
|
|
80
|
+
|
|
81
|
+
struct KeyDef {
|
|
82
|
+
const char *label;
|
|
83
|
+
int code;
|
|
84
|
+
KeyKind kind;
|
|
85
|
+
LabelKind labelKind;
|
|
86
|
+
std::int16_t width;
|
|
87
|
+
std::int16_t flex;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
struct RowDef {
|
|
91
|
+
int count;
|
|
92
|
+
int gap;
|
|
93
|
+
int paddingLeft;
|
|
94
|
+
int paddingRight;
|
|
95
|
+
KeyDef keys[kColCount];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Macros to keep the layout tables readable. width=0+flex=1 means "share
|
|
99
|
+
// the row's leftover space"; width>0+flex=0 means "fixed width".
|
|
100
|
+
#define KEY_L(LABEL, CODE) {LABEL, CODE, KeyKind::Light, LabelKind::Normal, 0, 1}
|
|
101
|
+
#define KEY_U_SMALL(LABEL, CODE) {LABEL, CODE, KeyKind::Utility, LabelKind::Small, 58, 0}
|
|
102
|
+
#define KEY_P_SMALL(LABEL, CODE) {LABEL, CODE, KeyKind::Primary, LabelKind::Small, 86, 0}
|
|
103
|
+
#define KEY_L_WIDE(LABEL, CODE) {LABEL, CODE, KeyKind::Light, LabelKind::Wide, 0, 1}
|
|
104
|
+
|
|
105
|
+
// Ten letter keys in row 1 of QWERTY — easier to spell out than to
|
|
106
|
+
// build at runtime from a string, especially since the symbols rows
|
|
107
|
+
// use literal char arrays anyway.
|
|
108
|
+
constexpr RowDef kAlphaRows[kRowCount] = {
|
|
109
|
+
{10, 5, 0, 0, {
|
|
110
|
+
KEY_L("q", 'q'), KEY_L("w", 'w'), KEY_L("e", 'e'), KEY_L("r", 'r'), KEY_L("t", 't'),
|
|
111
|
+
KEY_L("y", 'y'), KEY_L("u", 'u'), KEY_L("i", 'i'), KEY_L("o", 'o'), KEY_L("p", 'p'),
|
|
112
|
+
}},
|
|
113
|
+
{9, 5, 18, 18, {
|
|
114
|
+
KEY_L("a", 'a'), KEY_L("s", 's'), KEY_L("d", 'd'), KEY_L("f", 'f'), KEY_L("g", 'g'),
|
|
115
|
+
KEY_L("h", 'h'), KEY_L("j", 'j'), KEY_L("k", 'k'), KEY_L("l", 'l'), {nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
116
|
+
}},
|
|
117
|
+
{9, 5, 0, 0, {
|
|
118
|
+
KEY_U_SMALL("shift", kCodeShift),
|
|
119
|
+
KEY_L("z", 'z'), KEY_L("x", 'x'), KEY_L("c", 'c'), KEY_L("v", 'v'),
|
|
120
|
+
KEY_L("b", 'b'), KEY_L("n", 'n'), KEY_L("m", 'm'),
|
|
121
|
+
KEY_U_SMALL("delete", kCodeBackspace),
|
|
122
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
123
|
+
}},
|
|
124
|
+
{3, 6, 30, 30, {
|
|
125
|
+
KEY_U_SMALL("123", kCodeModeSymbols),
|
|
126
|
+
KEY_L_WIDE("space", kCodeSpace),
|
|
127
|
+
KEY_P_SMALL("return", kCodeReturn),
|
|
128
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
129
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
130
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
131
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
132
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
133
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
134
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
135
|
+
}},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
constexpr RowDef kSymbolsRows[kRowCount] = {
|
|
139
|
+
{10, 5, 0, 0, {
|
|
140
|
+
KEY_L("1", '1'), KEY_L("2", '2'), KEY_L("3", '3'), KEY_L("4", '4'), KEY_L("5", '5'),
|
|
141
|
+
KEY_L("6", '6'), KEY_L("7", '7'), KEY_L("8", '8'), KEY_L("9", '9'), KEY_L("0", '0'),
|
|
142
|
+
}},
|
|
143
|
+
{10, 5, 0, 0, {
|
|
144
|
+
KEY_L("-", '-'), KEY_L("/", '/'), KEY_L(":", ':'), KEY_L(";", ';'), KEY_L("(", '('),
|
|
145
|
+
KEY_L(")", ')'), KEY_L("$", '$'), KEY_L("&", '&'), KEY_L("@", '@'), KEY_L("\"", '"'),
|
|
146
|
+
}},
|
|
147
|
+
{7, 5, 0, 0, {
|
|
148
|
+
KEY_U_SMALL("#+=", kCodeModeMoreSymbols),
|
|
149
|
+
KEY_L(".", '.'), KEY_L(",", ','), KEY_L("?", '?'), KEY_L("!", '!'), KEY_L("'", '\''),
|
|
150
|
+
KEY_U_SMALL("delete", kCodeBackspace),
|
|
151
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
152
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
153
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
154
|
+
}},
|
|
155
|
+
{3, 6, 30, 30, {
|
|
156
|
+
KEY_U_SMALL("ABC", kCodeModeAlpha),
|
|
157
|
+
KEY_L_WIDE("space", kCodeSpace),
|
|
158
|
+
KEY_P_SMALL("return", kCodeReturn),
|
|
159
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
160
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
161
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
162
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
163
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
164
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
165
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
166
|
+
}},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
constexpr RowDef kMoreSymbolsRows[kRowCount] = {
|
|
170
|
+
{10, 5, 0, 0, {
|
|
171
|
+
KEY_L("[", '['), KEY_L("]", ']'), KEY_L("{", '{'), KEY_L("}", '}'), KEY_L("#", '#'),
|
|
172
|
+
KEY_L("%", '%'), KEY_L("^", '^'), KEY_L("*", '*'), KEY_L("+", '+'), KEY_L("=", '='),
|
|
173
|
+
}},
|
|
174
|
+
{7, 5, 0, 0, {
|
|
175
|
+
KEY_L("_", '_'), KEY_L("\\", '\\'), KEY_L("|", '|'), KEY_L("~", '~'),
|
|
176
|
+
KEY_L("<", '<'), KEY_L(">", '>'), KEY_L("`", '`'),
|
|
177
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
178
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
179
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
180
|
+
}},
|
|
181
|
+
{7, 5, 0, 0, {
|
|
182
|
+
KEY_U_SMALL("123", kCodeModeSymbols),
|
|
183
|
+
KEY_L(".", '.'), KEY_L(",", ','), KEY_L("?", '?'), KEY_L("!", '!'), KEY_L("'", '\''),
|
|
184
|
+
KEY_U_SMALL("delete", kCodeBackspace),
|
|
185
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
186
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
187
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
188
|
+
}},
|
|
189
|
+
{3, 6, 30, 30, {
|
|
190
|
+
KEY_U_SMALL("ABC", kCodeModeAlpha),
|
|
191
|
+
KEY_L_WIDE("space", kCodeSpace),
|
|
192
|
+
KEY_P_SMALL("return", kCodeReturn),
|
|
193
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
194
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
195
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
196
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
197
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
198
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
199
|
+
{nullptr,0,KeyKind::Light,LabelKind::Normal,0,0},
|
|
200
|
+
}},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
#undef KEY_L
|
|
204
|
+
#undef KEY_U_SMALL
|
|
205
|
+
#undef KEY_P_SMALL
|
|
206
|
+
#undef KEY_L_WIDE
|
|
207
|
+
|
|
208
|
+
enum class Mode { Alpha, Symbols, MoreSymbols };
|
|
209
|
+
|
|
210
|
+
struct KeyboardState {
|
|
211
|
+
int rootNode = -1;
|
|
212
|
+
int rowNodes[kRowCount] = {-1, -1, -1, -1};
|
|
213
|
+
int keyNodes[kSlotCount];
|
|
214
|
+
int labelNodes[kSlotCount];
|
|
215
|
+
int keyCodes[kSlotCount];
|
|
216
|
+
bool visible = false;
|
|
217
|
+
bool shiftHeld = false;
|
|
218
|
+
Mode mode = Mode::Alpha;
|
|
219
|
+
int boundDocumentRoot = -1;
|
|
220
|
+
bool listenerInstalled = false;
|
|
221
|
+
// When the keyboard shows we shrink the app's content node so it
|
|
222
|
+
// can scroll behind the keys rather than getting overlapped. These
|
|
223
|
+
// fields remember what we changed so we can restore on hide.
|
|
224
|
+
//
|
|
225
|
+
// Each touched property needs BOTH halves remembered, because setStyle
|
|
226
|
+
// writes two places: the computed `style.*` field, and the node's
|
|
227
|
+
// inline-override record. `Tree::resetStyleForClassRecompute` rebuilds
|
|
228
|
+
// computed style out of class rules plus that record, so a property the
|
|
229
|
+
// keyboard recorded and never un-recorded comes back at the next class
|
|
230
|
+
// recompute -- long after the keyboard is gone. Hide therefore restores
|
|
231
|
+
// the computed value AND puts the record back as it was: re-recording
|
|
232
|
+
// the app's own inline value, or removing the entry entirely when the
|
|
233
|
+
// app never authored one.
|
|
234
|
+
struct SavedStyle {
|
|
235
|
+
Property property = Property::Height;
|
|
236
|
+
int computed = 0;
|
|
237
|
+
int inlineValue = 0;
|
|
238
|
+
bool hadInline = false;
|
|
239
|
+
};
|
|
240
|
+
static constexpr int kMaxSavedStyles = 6;
|
|
241
|
+
int resizedNode = -1;
|
|
242
|
+
SavedStyle savedStyles[kMaxSavedStyles];
|
|
243
|
+
int savedStyleCount = 0;
|
|
244
|
+
bool resizeApplied = false;
|
|
245
|
+
|
|
246
|
+
KeyboardState()
|
|
247
|
+
{
|
|
248
|
+
for (int i = 0; i < kSlotCount; i++) {
|
|
249
|
+
keyNodes[i] = -1;
|
|
250
|
+
labelNodes[i] = -1;
|
|
251
|
+
keyCodes[i] = 0;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
KeyboardState gState;
|
|
257
|
+
|
|
258
|
+
const RowDef *rowsForMode(Mode mode)
|
|
259
|
+
{
|
|
260
|
+
switch (mode) {
|
|
261
|
+
case Mode::Symbols: return kSymbolsRows;
|
|
262
|
+
case Mode::MoreSymbols: return kMoreSymbolsRows;
|
|
263
|
+
case Mode::Alpha: default: return kAlphaRows;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Physical-pixel zone reserved at the bottom of the panel for a
|
|
268
|
+
// platform overlay (geaos home button). 0 on targets without one.
|
|
269
|
+
int bottomInset() { return gea::embedded::ui::safeAreaInsetBottom(); }
|
|
270
|
+
|
|
271
|
+
// Tall portrait panels (height >= 1.5x width — phones like the geaos
|
|
272
|
+
// Redmi 6A at 720x1440) have room to spare, so the keyboard switches to
|
|
273
|
+
// a "full size" layout with 1.5x taller keys and proportionally larger
|
|
274
|
+
// labels. Squarer panels (ESP32 ~410x502) keep the compact default
|
|
275
|
+
// untouched.
|
|
276
|
+
bool fullSizeKeyboard()
|
|
277
|
+
{
|
|
278
|
+
Tree &tree = Tree::instance();
|
|
279
|
+
const int vw = tree.mountedWidth() > 0 ? tree.mountedWidth() : 410;
|
|
280
|
+
const int vh = tree.mountedHeight() > 0 ? tree.mountedHeight() : 502;
|
|
281
|
+
return vh * 2 >= vw * 3; // vh / vw >= 1.5
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
struct KbMetrics {
|
|
285
|
+
int keyHeight;
|
|
286
|
+
int rootGap;
|
|
287
|
+
int padTop;
|
|
288
|
+
int padBottom;
|
|
289
|
+
int padLeft;
|
|
290
|
+
int padRight;
|
|
291
|
+
int fontNormal;
|
|
292
|
+
int fontSmall;
|
|
293
|
+
int fontWide;
|
|
294
|
+
int borderRadius;
|
|
295
|
+
int height; // total keyboard root height
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
KbMetrics kbMetrics()
|
|
299
|
+
{
|
|
300
|
+
if (!fullSizeKeyboard()) {
|
|
301
|
+
// Unchanged compact default — keeps the ESP32 keyboard identical.
|
|
302
|
+
return {38, 5, 8, 8, 12, 12, 19, 15, 17, 9, kKeyboardHeight};
|
|
303
|
+
}
|
|
304
|
+
// 1.5x taller keys. Height is computed from the parts so the
|
|
305
|
+
// background exactly wraps the four rows + gaps + padding.
|
|
306
|
+
const int keyH = 57; // 38 * 1.5
|
|
307
|
+
const int rootGap = 8; // 5 * 1.5
|
|
308
|
+
const int padTop = 12;
|
|
309
|
+
const int padBottom = 12;
|
|
310
|
+
const int height = padTop + kRowCount * keyH + (kRowCount - 1) * rootGap + padBottom;
|
|
311
|
+
return {keyH, rootGap, padTop, padBottom, 16, 16, 28, 22, 25, 13, height};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Total height the keyboard occupies plus the reserved bottom overlay
|
|
315
|
+
// zone — what both the mount position and the app-resize math key off.
|
|
316
|
+
int keyboardOccupiedHeight() { return kbMetrics().height + bottomInset(); }
|
|
317
|
+
|
|
318
|
+
// `setStyle(Property::BackgroundColor, X)` expects X to be a RAW RGB565
|
|
319
|
+
// value — the framework's renderer byte-swaps once on the way to the
|
|
320
|
+
// display. Using `pixel::fromRgb888` here would double-swap and land
|
|
321
|
+
// the bytes in the wrong order on the wire (the earlier "purple
|
|
322
|
+
// keyboard on purple background" symptom). Use `rgb565FromRgb888`
|
|
323
|
+
// which returns the plain RGB565 value the framework expects.
|
|
324
|
+
std::uint16_t kbBg() { return gea::framework::graphics::pixel::rgb565FromRgb888(0xd1, 0xd3, 0xda); }
|
|
325
|
+
std::uint16_t keyLightBg() { return gea::framework::graphics::pixel::rgb565FromRgb888(0xf2, 0xf2, 0xf7); }
|
|
326
|
+
std::uint16_t keyUtilityBg() { return gea::framework::graphics::pixel::rgb565FromRgb888(0x6f, 0x73, 0x7d); }
|
|
327
|
+
std::uint16_t keyPrimaryBg() { return gea::framework::graphics::pixel::rgb565FromRgb888(0x0a, 0x84, 0xff); }
|
|
328
|
+
std::uint16_t keyShiftActiveBg() { return gea::framework::graphics::pixel::rgb565FromRgb888(0xff, 0xff, 0xff); }
|
|
329
|
+
std::uint16_t labelDark() { return gea::framework::graphics::pixel::rgb565FromRgb888(0x11, 0x11, 0x16); }
|
|
330
|
+
std::uint16_t labelLight() { return gea::framework::graphics::pixel::rgb565FromRgb888(0xff, 0xff, 0xff); }
|
|
331
|
+
|
|
332
|
+
void applyKeyStyle(Tree &tree, int node, KeyKind kind, bool shiftActiveKey, const KbMetrics &m)
|
|
333
|
+
{
|
|
334
|
+
tree.setStyle(node, Property::Height, m.keyHeight);
|
|
335
|
+
tree.setStyle(node, Property::AlignItems, 1);
|
|
336
|
+
tree.setStyle(node, Property::JustifyContent, 1);
|
|
337
|
+
tree.setStyle(node, Property::HasBackground, 1);
|
|
338
|
+
tree.setStyle(node, Property::BorderRadiusTopLeft, m.borderRadius);
|
|
339
|
+
tree.setStyle(node, Property::BorderRadiusTopRight, m.borderRadius);
|
|
340
|
+
tree.setStyle(node, Property::BorderRadiusBottomRight, m.borderRadius);
|
|
341
|
+
tree.setStyle(node, Property::BorderRadiusBottomLeft, m.borderRadius);
|
|
342
|
+
std::uint16_t bg;
|
|
343
|
+
std::uint16_t activeBg;
|
|
344
|
+
switch (kind) {
|
|
345
|
+
case KeyKind::Primary:
|
|
346
|
+
bg = keyPrimaryBg();
|
|
347
|
+
// Slightly darker iOS blue for the press feedback. The framework's
|
|
348
|
+
// InputController::pointerDown lightens bg-having nodes by default
|
|
349
|
+
// (lightenRgb565), which would turn the already-bright blue near
|
|
350
|
+
// white — explicitly setting active_bg makes the press obviously
|
|
351
|
+
// "darker, not lighter".
|
|
352
|
+
activeBg = gea::framework::graphics::pixel::rgb565FromRgb888(0x06, 0x6a, 0xd6);
|
|
353
|
+
break;
|
|
354
|
+
case KeyKind::Utility:
|
|
355
|
+
bg = shiftActiveKey ? keyShiftActiveBg() : keyUtilityBg();
|
|
356
|
+
activeBg = gea::framework::graphics::pixel::rgb565FromRgb888(0x55, 0x59, 0x63);
|
|
357
|
+
break;
|
|
358
|
+
case KeyKind::Light:
|
|
359
|
+
default:
|
|
360
|
+
bg = keyLightBg();
|
|
361
|
+
// Light keys go slightly darker to a visible iOS-press grey rather
|
|
362
|
+
// than the framework's default "lighten" which would push #f2f2f7
|
|
363
|
+
// past pure white and look like nothing happened.
|
|
364
|
+
activeBg = gea::framework::graphics::pixel::rgb565FromRgb888(0xc7, 0xc7, 0xcc);
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
tree.setStyle(node, Property::BackgroundColor, static_cast<int>(bg));
|
|
368
|
+
tree.setStyle(node, Property::ActiveBackgroundColor, static_cast<int>(activeBg));
|
|
369
|
+
// HasActiveBackground = 1 tells the framework's findActiveTouchNodeId
|
|
370
|
+
// to surface THIS node (not an ancestor) as the press-feedback target.
|
|
371
|
+
// Without it, pointerDown's auto-lighten doesn't trigger and the
|
|
372
|
+
// keys look static during the tap.
|
|
373
|
+
tree.setStyle(node, Property::HasActiveBackground, 1);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
void applyLabelStyle(Tree &tree, int node, LabelKind kind, KeyKind keyKind, bool shiftActiveKey, const KbMetrics &m)
|
|
377
|
+
{
|
|
378
|
+
int fontSize = m.fontNormal;
|
|
379
|
+
if (kind == LabelKind::Small) fontSize = m.fontSmall;
|
|
380
|
+
else if (kind == LabelKind::Wide) fontSize = m.fontWide;
|
|
381
|
+
tree.setStyle(node, Property::FontSize, fontSize);
|
|
382
|
+
std::uint16_t color;
|
|
383
|
+
if (keyKind == KeyKind::Light || (keyKind == KeyKind::Utility && shiftActiveKey)) color = labelDark();
|
|
384
|
+
else color = labelLight();
|
|
385
|
+
tree.setStyle(node, Property::Color, static_cast<int>(color));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Forward decl for the press listener so applyMode can wire it.
|
|
389
|
+
void onKeyboardPress(gea::framework::events::PointerEvent &event);
|
|
390
|
+
|
|
391
|
+
void mountIfNeeded()
|
|
392
|
+
{
|
|
393
|
+
Tree &tree = Tree::instance();
|
|
394
|
+
if (gState.rootNode >= 0) return;
|
|
395
|
+
if (tree.mountedRoot() < 0) return;
|
|
396
|
+
|
|
397
|
+
// Canvas-rooted apps (full-screen map/game surfaces): a canvas is a
|
|
398
|
+
// layout LEAF, so the keyboard can't lay out as its child. Wrap the
|
|
399
|
+
// canvas in a plain view (which doesn't disturb the display-backed
|
|
400
|
+
// fast path while the keyboard is hidden) and remount.
|
|
401
|
+
if (tree.node(tree.mountedRoot()).type == NodeType::Canvas) {
|
|
402
|
+
const int wrapper = tree.createView();
|
|
403
|
+
if (wrapper < 0) return;
|
|
404
|
+
const int canvasId = tree.mountedRoot();
|
|
405
|
+
const int w = tree.mountedWidth();
|
|
406
|
+
const int h = tree.mountedHeight();
|
|
407
|
+
tree.setStyle(wrapper, Property::Width, w);
|
|
408
|
+
tree.setStyle(wrapper, Property::Height, h);
|
|
409
|
+
tree.setParent(canvasId, wrapper);
|
|
410
|
+
tree.mount(wrapper, w, h);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
const int kbRoot = tree.createView();
|
|
414
|
+
if (kbRoot < 0) return;
|
|
415
|
+
gState.rootNode = kbRoot;
|
|
416
|
+
tree.setParent(kbRoot, tree.mountedRoot());
|
|
417
|
+
|
|
418
|
+
const int viewportW = tree.mountedWidth() > 0 ? tree.mountedWidth() : 410;
|
|
419
|
+
const int viewportH = tree.mountedHeight() > 0 ? tree.mountedHeight() : 502;
|
|
420
|
+
// Absolute pos_offsets are measured FROM the parent's padding box
|
|
421
|
+
// (positionAbsoluteChild adds parent.padding[side] before the
|
|
422
|
+
// offset). To land the keyboard at exactly (0, viewportH - kbH) in
|
|
423
|
+
// display coords regardless of mountedRoot's CSS padding, subtract
|
|
424
|
+
// the parent's padding from our offsets — negative Left/Top
|
|
425
|
+
// cancels the inset.
|
|
426
|
+
const Node &parent = tree.node(tree.mountedRoot());
|
|
427
|
+
const int padTop = parent.style.padding[0];
|
|
428
|
+
const int padLeft = parent.style.padding[3];
|
|
429
|
+
|
|
430
|
+
const KbMetrics m = kbMetrics();
|
|
431
|
+
// Float the keyboard above any reserved bottom overlay (home button)
|
|
432
|
+
// instead of letting its lower rows hide behind it.
|
|
433
|
+
tree.setStyle(kbRoot, Property::Position, 1);
|
|
434
|
+
tree.setStyle(kbRoot, Property::Left, -padLeft);
|
|
435
|
+
tree.setStyle(kbRoot, Property::Top, viewportH - m.height - bottomInset() - padTop);
|
|
436
|
+
tree.setStyle(kbRoot, Property::Width, viewportW);
|
|
437
|
+
tree.setStyle(kbRoot, Property::Height, m.height);
|
|
438
|
+
tree.setStyle(kbRoot, Property::ZIndex, 32000);
|
|
439
|
+
tree.setStyle(kbRoot, Property::HasBackground, 1);
|
|
440
|
+
tree.setStyle(kbRoot, Property::BackgroundColor, static_cast<int>(kbBg()));
|
|
441
|
+
tree.setStyle(kbRoot, Property::PaddingTop, m.padTop);
|
|
442
|
+
tree.setStyle(kbRoot, Property::PaddingBottom, m.padBottom);
|
|
443
|
+
tree.setStyle(kbRoot, Property::PaddingLeft, m.padLeft);
|
|
444
|
+
tree.setStyle(kbRoot, Property::PaddingRight, m.padRight);
|
|
445
|
+
tree.setStyle(kbRoot, Property::Gap, m.rootGap);
|
|
446
|
+
tree.setStyle(kbRoot, Property::FlexDirection, 0); // column
|
|
447
|
+
tree.setStyle(kbRoot, Property::Display, 1); // hidden until shown
|
|
448
|
+
|
|
449
|
+
for (int row = 0; row < kRowCount; row++) {
|
|
450
|
+
const int rowNode = tree.createView();
|
|
451
|
+
if (rowNode < 0) return;
|
|
452
|
+
gState.rowNodes[row] = rowNode;
|
|
453
|
+
tree.setParent(rowNode, kbRoot);
|
|
454
|
+
tree.setStyle(rowNode, Property::FlexDirection, 1); // row
|
|
455
|
+
tree.setStyle(rowNode, Property::AlignItems, 1); // center (cross-axis)
|
|
456
|
+
tree.setStyle(rowNode, Property::JustifyContent, 1); // center (main-axis)
|
|
457
|
+
tree.setStyle(rowNode, Property::Height, m.keyHeight);
|
|
458
|
+
// Rows stretch the full keyboard width so they share the leftover
|
|
459
|
+
// horizontal space between fixed-width keys (Shift, delete) and
|
|
460
|
+
// flex:1 letters. Without this they shrink to content width and
|
|
461
|
+
// the row sits left-justified.
|
|
462
|
+
tree.setStyle(rowNode, Property::Width, viewportW - 24);
|
|
463
|
+
for (int col = 0; col < kColCount; col++) {
|
|
464
|
+
const int slot = row * kColCount + col;
|
|
465
|
+
const int keyNode = tree.createView();
|
|
466
|
+
if (keyNode < 0) return;
|
|
467
|
+
gState.keyNodes[slot] = keyNode;
|
|
468
|
+
tree.setParent(keyNode, rowNode);
|
|
469
|
+
tree.setPressId(keyNode, kPressIdBase + slot);
|
|
470
|
+
|
|
471
|
+
const int labelNode = tree.createText();
|
|
472
|
+
if (labelNode < 0) return;
|
|
473
|
+
gState.labelNodes[slot] = labelNode;
|
|
474
|
+
tree.setParent(labelNode, keyNode);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Install the tap listener on body once, the first time the
|
|
479
|
+
// keyboard mounts. Subsequent app switches (Tree::clear) will reset
|
|
480
|
+
// listenerInstalled and re-install via the same path.
|
|
481
|
+
if (!gState.listenerInstalled) {
|
|
482
|
+
tree.setEventListener(tree.mountedRoot(), "click", onKeyboardPress);
|
|
483
|
+
gState.listenerInstalled = true;
|
|
484
|
+
gState.boundDocumentRoot = tree.mountedRoot();
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
void applyMode()
|
|
489
|
+
{
|
|
490
|
+
Tree &tree = Tree::instance();
|
|
491
|
+
if (gState.rootNode < 0) return;
|
|
492
|
+
const KbMetrics m = kbMetrics();
|
|
493
|
+
const RowDef *rows = rowsForMode(gState.mode);
|
|
494
|
+
for (int row = 0; row < kRowCount; row++) {
|
|
495
|
+
const RowDef &rdef = rows[row];
|
|
496
|
+
const int rowNode = gState.rowNodes[row];
|
|
497
|
+
if (rowNode < 0) continue;
|
|
498
|
+
tree.setStyle(rowNode, Property::Gap, rdef.gap);
|
|
499
|
+
tree.setStyle(rowNode, Property::PaddingLeft, rdef.paddingLeft);
|
|
500
|
+
tree.setStyle(rowNode, Property::PaddingRight, rdef.paddingRight);
|
|
501
|
+
|
|
502
|
+
for (int col = 0; col < kColCount; col++) {
|
|
503
|
+
const int slot = row * kColCount + col;
|
|
504
|
+
const int keyNode = gState.keyNodes[slot];
|
|
505
|
+
const int labelNode = gState.labelNodes[slot];
|
|
506
|
+
if (keyNode < 0 || labelNode < 0) continue;
|
|
507
|
+
|
|
508
|
+
if (col >= rdef.count || rdef.keys[col].label == nullptr) {
|
|
509
|
+
// Hide unused slot.
|
|
510
|
+
gState.keyCodes[slot] = 0;
|
|
511
|
+
tree.setStyle(keyNode, Property::Display, 1);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
const KeyDef &kdef = rdef.keys[col];
|
|
516
|
+
gState.keyCodes[slot] = kdef.code;
|
|
517
|
+
|
|
518
|
+
tree.setStyle(keyNode, Property::Display, 0);
|
|
519
|
+
tree.setStyle(keyNode, Property::Width, kdef.width);
|
|
520
|
+
tree.setStyle(keyNode, Property::Flex, kdef.flex);
|
|
521
|
+
const bool shiftActive = kdef.code == kCodeShift && gState.shiftHeld;
|
|
522
|
+
applyKeyStyle(tree, keyNode, kdef.kind, shiftActive, m);
|
|
523
|
+
applyLabelStyle(tree, labelNode, kdef.labelKind, kdef.kind, shiftActive, m);
|
|
524
|
+
|
|
525
|
+
// Capitalize alpha keys when shift is held — matches what
|
|
526
|
+
// the user expects to type and what the press handler
|
|
527
|
+
// will actually emit.
|
|
528
|
+
if (gState.mode == Mode::Alpha && gState.shiftHeld && kdef.code >= 'a' && kdef.code <= 'z') {
|
|
529
|
+
char upper[2] = {static_cast<char>(kdef.code - 'a' + 'A'), '\0'};
|
|
530
|
+
tree.setText(labelNode, upper);
|
|
531
|
+
} else {
|
|
532
|
+
tree.setText(labelNode, kdef.label);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
void applyKeyToActiveInput(int code)
|
|
539
|
+
{
|
|
540
|
+
Tree &tree = Tree::instance();
|
|
541
|
+
const int activeId = tree.activeInputId();
|
|
542
|
+
if (activeId < 0) return;
|
|
543
|
+
|
|
544
|
+
if (code == kCodeShift) {
|
|
545
|
+
gState.shiftHeld = !gState.shiftHeld;
|
|
546
|
+
applyMode();
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
if (code == kCodeModeAlpha) {
|
|
550
|
+
gState.mode = Mode::Alpha;
|
|
551
|
+
gState.shiftHeld = false;
|
|
552
|
+
applyMode();
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
if (code == kCodeModeSymbols) {
|
|
556
|
+
gState.mode = Mode::Symbols;
|
|
557
|
+
applyMode();
|
|
558
|
+
return;
|
|
559
|
+
}
|
|
560
|
+
if (code == kCodeModeMoreSymbols) {
|
|
561
|
+
gState.mode = Mode::MoreSymbols;
|
|
562
|
+
applyMode();
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const char *currentValue = tree.getAttribute(activeId, "value");
|
|
567
|
+
std::string next = currentValue ? std::string(currentValue) : std::string();
|
|
568
|
+
|
|
569
|
+
// Helper: marking commands dirty + setting displayListDirty isn't
|
|
570
|
+
// enough — the framework's DirtyRegions tracker computes the per-
|
|
571
|
+
// frame flush rectangles from each node's render.dirty bits, and
|
|
572
|
+
// without them the new DrawText command is recorded but never sent
|
|
573
|
+
// to the panel. Setting both render.dirty AND non_scroll_dirty
|
|
574
|
+
// matches what Tree::setText does for plain Text nodes.
|
|
575
|
+
auto markInputDirty = [&](int nodeId) {
|
|
576
|
+
if (nodeId < 0 || nodeId >= tree.nodeCount()) return;
|
|
577
|
+
tree.markNodeDisplayCommandsDirty(nodeId);
|
|
578
|
+
tree.setDisplayListRebuildRequired(true);
|
|
579
|
+
Node &nn = tree.node(nodeId);
|
|
580
|
+
nn.render.dirty = 1;
|
|
581
|
+
nn.render.layout_dirty = 1;
|
|
582
|
+
nn.render.non_scroll_dirty = 1;
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
if (code == kCodeBackspace) {
|
|
586
|
+
if (!next.empty()) {
|
|
587
|
+
next.pop_back();
|
|
588
|
+
tree.setAttribute(activeId, "value", next.c_str());
|
|
589
|
+
markInputDirty(activeId);
|
|
590
|
+
gea::framework::events::PointerEvent ev{};
|
|
591
|
+
ev.type = gea::framework::events::PointerEventType::Input;
|
|
592
|
+
ev.targetId = activeId;
|
|
593
|
+
tree.dispatchEvent(ev);
|
|
594
|
+
}
|
|
595
|
+
gea::framework::events::PointerEvent kd{};
|
|
596
|
+
kd.type = gea::framework::events::PointerEventType::KeyDown;
|
|
597
|
+
kd.targetId = activeId;
|
|
598
|
+
kd.keyCode = kCodeBackspace;
|
|
599
|
+
tree.dispatchEvent(kd);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
if (code == kCodeReturn) {
|
|
603
|
+
gea::framework::events::PointerEvent kd{};
|
|
604
|
+
kd.type = gea::framework::events::PointerEventType::KeyDown;
|
|
605
|
+
kd.targetId = activeId;
|
|
606
|
+
kd.keyCode = kCodeReturn;
|
|
607
|
+
tree.dispatchEvent(kd);
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// Printable character (space + ASCII).
|
|
612
|
+
char c = static_cast<char>(code);
|
|
613
|
+
if (gState.mode == Mode::Alpha && gState.shiftHeld && c >= 'a' && c <= 'z') {
|
|
614
|
+
c = static_cast<char>(c - 'a' + 'A');
|
|
615
|
+
gState.shiftHeld = false; // single-shot shift
|
|
616
|
+
applyMode();
|
|
617
|
+
}
|
|
618
|
+
next.push_back(c);
|
|
619
|
+
tree.setAttribute(activeId, "value", next.c_str());
|
|
620
|
+
markInputDirty(activeId);
|
|
621
|
+
|
|
622
|
+
gea::framework::events::PointerEvent ev{};
|
|
623
|
+
ev.type = gea::framework::events::PointerEventType::Input;
|
|
624
|
+
ev.targetId = activeId;
|
|
625
|
+
tree.dispatchEvent(ev);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Find the last non-keyboard child of mountedRoot — that's the
|
|
629
|
+
// scrollable content area in conventional app layouts (header / status
|
|
630
|
+
// / compose row above, the long list below). Resizing this single
|
|
631
|
+
// child to fit above the keyboard, with overflow=2 (scroll), lets the
|
|
632
|
+
// user scroll within the reduced area while keeping the keyboard
|
|
633
|
+
// itself positioned absolutely outside the scroll container's clip.
|
|
634
|
+
int findScrollableChild()
|
|
635
|
+
{
|
|
636
|
+
Tree &tree = Tree::instance();
|
|
637
|
+
const int root = tree.mountedRoot();
|
|
638
|
+
if (root < 0) return -1;
|
|
639
|
+
int last = -1;
|
|
640
|
+
for (int child = tree.node(root).first_child;
|
|
641
|
+
child >= 0 && child < tree.nodeCount();
|
|
642
|
+
child = tree.node(child).next_sibling) {
|
|
643
|
+
if (child != gState.rootNode) last = child;
|
|
644
|
+
}
|
|
645
|
+
return last;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// The node's own inline-override entry for `property`, when the app authored
|
|
649
|
+
// one. NodeStyleOverrideStore has no keyed lookup; the store holds a handful of
|
|
650
|
+
// entries, so a scan is the shipped access shape.
|
|
651
|
+
bool inlineStyleEntry(int node, Property property, int &valueOut)
|
|
652
|
+
{
|
|
653
|
+
const NodeRareData *rd = rareDataFor(node);
|
|
654
|
+
if (!rd) return false;
|
|
655
|
+
const NodeStyleOverrideStore &store = rd->inlineStyles;
|
|
656
|
+
for (std::size_t i = 0; i < store.size(); i++) {
|
|
657
|
+
const NodeStyleOverride &entry = store.at(i);
|
|
658
|
+
if (entry.property == property) {
|
|
659
|
+
valueOut = entry.value;
|
|
660
|
+
return true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// Drop the node's inline entry for `property`, leaving the computed field
|
|
667
|
+
// alone -- callers set that first, through setStyle. This is the half a raw
|
|
668
|
+
// `style.*` write cannot undo, and the reason a dismissed keyboard used to
|
|
669
|
+
// leave the app node pinned `position: absolute` for good: the record still
|
|
670
|
+
// said `absolute`, so the next class recompute put it straight back.
|
|
671
|
+
void clearInlineStyleEntry(int node, Property property)
|
|
672
|
+
{
|
|
673
|
+
if (NodeRareData *rd = rareDataFor(node)) rd->inlineStyles.remove(property);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// Set a style through setStyle -- so the computed field, the inline record and
|
|
677
|
+
// the dirty flags all move together -- remembering what each half held first
|
|
678
|
+
// so restoreAppResize can be an exact inverse. `previousComputed` is read by
|
|
679
|
+
// the caller because the computed style has no generic per-property reader.
|
|
680
|
+
void pinStyle(Tree &tree, int node, Property property, int previousComputed, int value)
|
|
681
|
+
{
|
|
682
|
+
if (gState.savedStyleCount < KeyboardState::kMaxSavedStyles) {
|
|
683
|
+
KeyboardState::SavedStyle &saved = gState.savedStyles[gState.savedStyleCount++];
|
|
684
|
+
saved.property = property;
|
|
685
|
+
saved.computed = previousComputed;
|
|
686
|
+
saved.hadInline = inlineStyleEntry(node, property, saved.inlineValue);
|
|
687
|
+
}
|
|
688
|
+
tree.setStyle(node, property, value);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
void applyAppResize()
|
|
692
|
+
{
|
|
693
|
+
if (gState.resizeApplied) return;
|
|
694
|
+
Tree &tree = Tree::instance();
|
|
695
|
+
const int target = findScrollableChild();
|
|
696
|
+
if (target < 0) return;
|
|
697
|
+
const Node &n = tree.node(target);
|
|
698
|
+
gState.resizedNode = target;
|
|
699
|
+
gState.savedStyleCount = 0;
|
|
700
|
+
// Snapshot every computed value we are about to overwrite before the
|
|
701
|
+
// first setStyle lands, so none of them is read back post-mutation.
|
|
702
|
+
const int prevHeight = n.style.height;
|
|
703
|
+
const int prevFlex = n.style.flex;
|
|
704
|
+
const int prevOverflowY = n.style.overflow_y;
|
|
705
|
+
const int prevPosition = n.style.position;
|
|
706
|
+
const int prevTop = n.style.pos_offsets[0];
|
|
707
|
+
const int prevLeft = n.style.pos_offsets[3];
|
|
708
|
+
const int viewportH = tree.mountedHeight();
|
|
709
|
+
// Available vertical space between the top of this node (set by
|
|
710
|
+
// previous siblings' heights during the most recent layout pass)
|
|
711
|
+
// and the keyboard's top edge — which now also clears the reserved
|
|
712
|
+
// bottom overlay zone. Negative falls back to 0 so we don't pass a
|
|
713
|
+
// junk height that explodes layout.
|
|
714
|
+
int newHeight = viewportH - keyboardOccupiedHeight() - n.layout.y;
|
|
715
|
+
if (newHeight < 0) newHeight = 0;
|
|
716
|
+
// Pin the node absolutely at its CURRENT box before shrinking it: the
|
|
717
|
+
// height math above assumes layout.y stays put, but a centering parent
|
|
718
|
+
// (weather: the root vertically centers a fixed-height shell) re-centers
|
|
719
|
+
// the shrunken box — the whole app slid down 72px, stayed overlapped by
|
|
720
|
+
// the keys, and the vacated rows (which nothing paints) kept a stale
|
|
721
|
+
// band of the old screen. Absolute takes it out of the parent's flow so
|
|
722
|
+
// it cannot move; restore puts the original position styles back.
|
|
723
|
+
const Node &parentNode = tree.node(n.parent >= 0 ? n.parent : target);
|
|
724
|
+
const int pinTop = n.layout.y - parentNode.layout.y - parentNode.style.padding[0];
|
|
725
|
+
const int pinLeft = n.layout.x - parentNode.layout.x - parentNode.style.padding[3];
|
|
726
|
+
pinStyle(tree, target, Property::Position, prevPosition, 1);
|
|
727
|
+
pinStyle(tree, target, Property::Top, prevTop, pinTop);
|
|
728
|
+
pinStyle(tree, target, Property::Left, prevLeft, pinLeft);
|
|
729
|
+
pinStyle(tree, target, Property::Height, prevHeight, newHeight);
|
|
730
|
+
pinStyle(tree, target, Property::Flex, prevFlex, 0);
|
|
731
|
+
pinStyle(tree, target, Property::OverflowY, prevOverflowY, 2);
|
|
732
|
+
gState.resizeApplied = true;
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
void restoreAppResize()
|
|
736
|
+
{
|
|
737
|
+
if (!gState.resizeApplied) return;
|
|
738
|
+
const int target = gState.resizedNode;
|
|
739
|
+
if (target < 0) {
|
|
740
|
+
gState.resizeApplied = false;
|
|
741
|
+
return;
|
|
742
|
+
}
|
|
743
|
+
Tree &tree = Tree::instance();
|
|
744
|
+
if (target < tree.nodeCount()) {
|
|
745
|
+
// Reverse order, so the pin comes off last exactly as it went on first.
|
|
746
|
+
for (int i = gState.savedStyleCount - 1; i >= 0; i--) {
|
|
747
|
+
const KeyboardState::SavedStyle &saved = gState.savedStyles[i];
|
|
748
|
+
// setStyle puts the computed field back and marks the node dirty
|
|
749
|
+
// for this frame; it also re-records the value inline, which is
|
|
750
|
+
// what we want only when the app had authored one there. When it
|
|
751
|
+
// had not, drop the entry -- otherwise the record keeps saying
|
|
752
|
+
// what the keyboard said and a later class recompute restores the
|
|
753
|
+
// keyboard's geometry to a node it no longer covers.
|
|
754
|
+
tree.setStyle(target, saved.property,
|
|
755
|
+
saved.hadInline ? saved.inlineValue : saved.computed);
|
|
756
|
+
if (!saved.hadInline) clearInlineStyleEntry(target, saved.property);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
gState.resizedNode = -1;
|
|
760
|
+
gState.savedStyleCount = 0;
|
|
761
|
+
gState.resizeApplied = false;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
void onKeyboardPress(gea::framework::events::PointerEvent &event)
|
|
765
|
+
{
|
|
766
|
+
// `event.pressId` is set during dispatch from the FIRST ancestor
|
|
767
|
+
// in the bubble chain that has a non-negative pressId, OR (as
|
|
768
|
+
// fallback) the original target's pressId. Hit-tests on a key
|
|
769
|
+
// often land on the key's text-label child — that label has no
|
|
770
|
+
// pressId, so the fallback misses our reserved range. Walk up
|
|
771
|
+
// from event.targetId ourselves looking for the key node.
|
|
772
|
+
Tree &tree = Tree::instance();
|
|
773
|
+
int keyPressId = -1;
|
|
774
|
+
for (int n = event.targetId;
|
|
775
|
+
n >= 0 && n < tree.nodeCount();
|
|
776
|
+
n = tree.node(n).parent) {
|
|
777
|
+
const int pid = tree.pressId(n);
|
|
778
|
+
if (pid >= kPressIdBase && pid < kPressIdBase + kSlotCount) {
|
|
779
|
+
keyPressId = pid;
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
if (keyPressId < 0) return; // not a keyboard tap
|
|
784
|
+
|
|
785
|
+
event.preventDefault();
|
|
786
|
+
event.stopPropagation();
|
|
787
|
+
const int slot = keyPressId - kPressIdBase;
|
|
788
|
+
const int code = gState.keyCodes[slot];
|
|
789
|
+
if (code == 0) return;
|
|
790
|
+
applyKeyToActiveInput(code);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
} // namespace
|
|
794
|
+
|
|
795
|
+
VirtualKeyboard &VirtualKeyboard::instance()
|
|
796
|
+
{
|
|
797
|
+
static VirtualKeyboard kb;
|
|
798
|
+
return kb;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
bool VirtualKeyboard::active() const { return gState.visible; }
|
|
802
|
+
|
|
803
|
+
bool VirtualKeyboard::containsNode(int nodeId) const
|
|
804
|
+
{
|
|
805
|
+
if (gState.rootNode < 0) return false;
|
|
806
|
+
Tree &tree = Tree::instance();
|
|
807
|
+
for (int n = nodeId; n >= 0 && n < tree.nodeCount(); n = tree.node(n).parent) {
|
|
808
|
+
if (n == gState.rootNode) return true;
|
|
809
|
+
}
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
void VirtualKeyboard::reset()
|
|
814
|
+
{
|
|
815
|
+
// Called from Tree::clear() to drop any stale node ids before the
|
|
816
|
+
// next app's tree gets mounted. The nodes themselves are gone (the
|
|
817
|
+
// whole tree was wiped); we just have to clear our local handles so
|
|
818
|
+
// the next mount creates fresh ones.
|
|
819
|
+
gState.rootNode = -1;
|
|
820
|
+
for (int i = 0; i < kRowCount; i++) gState.rowNodes[i] = -1;
|
|
821
|
+
for (int i = 0; i < kSlotCount; i++) {
|
|
822
|
+
gState.keyNodes[i] = -1;
|
|
823
|
+
gState.labelNodes[i] = -1;
|
|
824
|
+
gState.keyCodes[i] = 0;
|
|
825
|
+
}
|
|
826
|
+
gState.visible = false;
|
|
827
|
+
gState.shiftHeld = false;
|
|
828
|
+
gState.mode = Mode::Alpha;
|
|
829
|
+
gState.listenerInstalled = false;
|
|
830
|
+
gState.boundDocumentRoot = -1;
|
|
831
|
+
gState.resizedNode = -1;
|
|
832
|
+
gState.savedStyleCount = 0;
|
|
833
|
+
gState.resizeApplied = false;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
int VirtualKeyboard::debugRootNode() const
|
|
837
|
+
{
|
|
838
|
+
return gState.rootNode;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
void VirtualKeyboard::sync()
|
|
842
|
+
{
|
|
843
|
+
Tree &tree = Tree::instance();
|
|
844
|
+
const int activeId = tree.activeInputId();
|
|
845
|
+
const bool shouldBeVisible = activeId >= 0;
|
|
846
|
+
|
|
847
|
+
if (shouldBeVisible) {
|
|
848
|
+
mountIfNeeded();
|
|
849
|
+
if (gState.rootNode < 0) return;
|
|
850
|
+
if (!gState.visible) {
|
|
851
|
+
gState.visible = true;
|
|
852
|
+
tree.setStyle(gState.rootNode, Property::Display, 0);
|
|
853
|
+
applyMode();
|
|
854
|
+
// Shrink the app's content area so the rows it holds can
|
|
855
|
+
// scroll above the keyboard rather than being permanently
|
|
856
|
+
// hidden behind it. mountIfNeeded() reparents the keyboard
|
|
857
|
+
// to body, so the app content is the OTHER child — found
|
|
858
|
+
// dynamically because we don't want to assume a fixed
|
|
859
|
+
// tree shape across apps.
|
|
860
|
+
applyAppResize();
|
|
861
|
+
tree.setDisplayListRebuildRequired(true);
|
|
862
|
+
// The resize relayout moves the whole app (a centered fixed-height
|
|
863
|
+
// shell re-centers in the shrunken box); per-node dirty rects have
|
|
864
|
+
// been observed to miss the vacated rows, leaving a stale band of
|
|
865
|
+
// the pre-keyboard screen (weather: duplicated header). Show/hide
|
|
866
|
+
// is a screen-scale change — repaint everything.
|
|
867
|
+
if (auto *canvas = gea::platform::display::Display::canvas())
|
|
868
|
+
canvas->markDirty(0, 0, canvas->width() - 1, canvas->height() - 1);
|
|
869
|
+
}
|
|
870
|
+
} else {
|
|
871
|
+
if (gState.visible && gState.rootNode >= 0) {
|
|
872
|
+
gState.visible = false;
|
|
873
|
+
tree.setStyle(gState.rootNode, Property::Display, 1);
|
|
874
|
+
restoreAppResize();
|
|
875
|
+
tree.setDisplayListRebuildRequired(true);
|
|
876
|
+
// The keyboard's rows may extend below everything the app paints
|
|
877
|
+
// (weather: a centered fixed-height shell leaves the bottom rows
|
|
878
|
+
// ownerless), so hiding must clear the framebuffer back to the
|
|
879
|
+
// mount-time base or the keys linger as stale pixels. Then repaint
|
|
880
|
+
// everything.
|
|
881
|
+
gea::platform::display::Display::clearNoFlush();
|
|
882
|
+
if (auto *canvas = gea::platform::display::Display::canvas())
|
|
883
|
+
canvas->markDirty(0, 0, canvas->width() - 1, canvas->height() - 1);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
} // namespace gea::embedded::ui
|
|
889
|
+
|
|
890
|
+
#else
|
|
891
|
+
|
|
892
|
+
namespace gea::embedded::ui {
|
|
893
|
+
|
|
894
|
+
VirtualKeyboard &VirtualKeyboard::instance()
|
|
895
|
+
{
|
|
896
|
+
static VirtualKeyboard kb;
|
|
897
|
+
return kb;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
bool VirtualKeyboard::active() const { return false; }
|
|
901
|
+
bool VirtualKeyboard::containsNode(int) const { return false; }
|
|
902
|
+
int VirtualKeyboard::debugRootNode() const { return -1; }
|
|
903
|
+
void VirtualKeyboard::reset() {}
|
|
904
|
+
void VirtualKeyboard::sync() {}
|
|
905
|
+
|
|
906
|
+
} // namespace gea::embedded::ui
|
|
907
|
+
|
|
908
|
+
#endif
|