@geastack/engine 0.1.23 → 0.1.24
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/package.json +1 -1
- package/rasterized_font.cpp +7 -6
- package/ui/input.cpp +15 -3
- package/ui/input_render.cpp +89 -32
- package/ui/virtual_keyboard.cpp +5 -0
package/package.json
CHANGED
package/rasterized_font.cpp
CHANGED
|
@@ -128,7 +128,12 @@ constexpr int kRuntimeAsciiCount = kRuntimeAsciiLast - kRuntimeAsciiFirst + 1;
|
|
|
128
128
|
constexpr int kRuntimeExtraCodepoints[] = {0x00b0,0x00b5,0x00d7,0x2013,0x2014,0x2018,0x2019,0x201c,0x201d,0x2022,0x2026,0x2190,0x2191,0x2192,0x2193,0x2212};
|
|
129
129
|
constexpr int kRuntimeExtraGlyphs = sizeof(kRuntimeExtraCodepoints)/sizeof(int);
|
|
130
130
|
#else
|
|
131
|
-
|
|
131
|
+
// The degree sign, and the bullet a password input draws for each hidden
|
|
132
|
+
// character (lv_textarea's LV_TEXTAREA_PWD_BULLET_UNICODE): without it every
|
|
133
|
+
// masked character fell back to nothing. Kept short: each entry costs a Glyph
|
|
134
|
+
// in every one of the 64 cache slots, on boards with no PSRAM too.
|
|
135
|
+
constexpr int kRuntimeExtraCodepoints[] = {0x00b0, 0x2022};
|
|
136
|
+
constexpr int kRuntimeExtraGlyphs = sizeof(kRuntimeExtraCodepoints) / sizeof(int);
|
|
132
137
|
#endif
|
|
133
138
|
constexpr int kRuntimeGlyphCapacity = kRuntimeAsciiCount + kRuntimeExtraGlyphs;
|
|
134
139
|
constexpr int kRuntimeFontCacheSlots = 64;
|
|
@@ -173,11 +178,7 @@ struct RuntimeRasterizedFontSlot {
|
|
|
173
178
|
int runtimeCodepointAt(int index)
|
|
174
179
|
{
|
|
175
180
|
if (index >= 0 && index < kRuntimeAsciiCount) return kRuntimeAsciiFirst + index;
|
|
176
|
-
|
|
177
|
-
if (index>=kRuntimeAsciiCount && index<kRuntimeGlyphCapacity) return kRuntimeExtraCodepoints[index-kRuntimeAsciiCount];
|
|
178
|
-
#else
|
|
179
|
-
if (index == kRuntimeAsciiCount) return 0x00b0;
|
|
180
|
-
#endif
|
|
181
|
+
if (index >= kRuntimeAsciiCount && index < kRuntimeGlyphCapacity) return kRuntimeExtraCodepoints[index - kRuntimeAsciiCount];
|
|
181
182
|
return -1;
|
|
182
183
|
}
|
|
183
184
|
|
package/ui/input.cpp
CHANGED
|
@@ -1344,18 +1344,28 @@ void Tree::setActiveInputCaret(int pos)
|
|
|
1344
1344
|
#endif
|
|
1345
1345
|
}
|
|
1346
1346
|
|
|
1347
|
+
namespace {
|
|
1348
|
+
// lv_textarea's pwd_show_time: the last typed characters stay in clear this long.
|
|
1349
|
+
constexpr int kPasswordShowMs = 1500;
|
|
1350
|
+
// pwdRevealUntilMs while the reveal waits for its first frame tick.
|
|
1351
|
+
constexpr int kPasswordRevealPending = -1;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1347
1354
|
void Tree::noteActiveInputTyped(int from, int to)
|
|
1348
1355
|
{
|
|
1349
1356
|
#if GEA_UI_INPUT_NODES
|
|
1350
1357
|
auto &state = treeState();
|
|
1351
|
-
constexpr int kPasswordShowMs = 1500;
|
|
1352
1358
|
if (state.pwdRevealUntilMs != 0 && from == state.pwdRevealTo) {
|
|
1353
1359
|
state.pwdRevealTo = to; // the same burst: keep showing it
|
|
1354
1360
|
} else {
|
|
1355
1361
|
state.pwdRevealFrom = from;
|
|
1356
1362
|
state.pwdRevealTo = to;
|
|
1357
1363
|
}
|
|
1358
|
-
|
|
1364
|
+
// The timer starts at the next frame tick, not at lastFrameMs: a key tap
|
|
1365
|
+
// lands between frames, and once the screen goes idle lastFrameMs can be
|
|
1366
|
+
// seconds old -- lastFrameMs + 1500 was already past, so the very next
|
|
1367
|
+
// tick turned the character into a bullet before it was ever drawn.
|
|
1368
|
+
state.pwdRevealUntilMs = kPasswordRevealPending;
|
|
1359
1369
|
#else
|
|
1360
1370
|
(void)from;
|
|
1361
1371
|
(void)to;
|
|
@@ -1385,7 +1395,9 @@ void Tree::tickInputCaret(int timestampMs)
|
|
|
1385
1395
|
return;
|
|
1386
1396
|
}
|
|
1387
1397
|
// The password characters typed last turn to bullets once their time is up.
|
|
1388
|
-
if (state.pwdRevealUntilMs
|
|
1398
|
+
if (state.pwdRevealUntilMs == kPasswordRevealPending) {
|
|
1399
|
+
state.pwdRevealUntilMs = (timestampMs > 0 ? timestampMs : 1) + kPasswordShowMs;
|
|
1400
|
+
} else if (state.pwdRevealUntilMs != 0 && timestampMs >= state.pwdRevealUntilMs) {
|
|
1389
1401
|
state.pwdRevealUntilMs = 0;
|
|
1390
1402
|
state.pwdRevealFrom = state.pwdRevealTo = 0;
|
|
1391
1403
|
markActiveInputRepaint(state);
|
package/ui/input_render.cpp
CHANGED
|
@@ -107,6 +107,14 @@ const char *inputContentText(int id, gea::framework::graphics::pixel::native_t *
|
|
|
107
107
|
return nullptr;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
+
// How far each input's one line is scrolled left so its caret stays in view
|
|
111
|
+
// (lv_textarea one-line mode scrolls the label the same way).
|
|
112
|
+
std::unordered_map<int, int> &inputScrollX()
|
|
113
|
+
{
|
|
114
|
+
static std::unordered_map<int, int> scroll;
|
|
115
|
+
return scroll;
|
|
116
|
+
}
|
|
117
|
+
|
|
110
118
|
const char *inputMeasureText(int id)
|
|
111
119
|
{
|
|
112
120
|
const char *content = inputContentText(id, nullptr, 0);
|
|
@@ -168,6 +176,51 @@ void InputRenderer::record(int id)
|
|
|
168
176
|
if (contentW < 0) contentW = 0;
|
|
169
177
|
if (contentH < 0) contentH = 0;
|
|
170
178
|
|
|
179
|
+
const auto &style = n.computedStyle();
|
|
180
|
+
const bool focused = tree.activeInputId() == id;
|
|
181
|
+
const char *valueAttr = tree.getAttribute(id, "value");
|
|
182
|
+
const bool hasValue = valueAttr && valueAttr[0];
|
|
183
|
+
// The width of what is shown before the caret (bullets on a password).
|
|
184
|
+
int caretPrefixW = -1;
|
|
185
|
+
if (focused && hasValue) {
|
|
186
|
+
const int caret = tree.activeInputCaret();
|
|
187
|
+
const std::string prefix = isPasswordInput(id) ? passwordDisplay(id, valueAttr, caret) : std::string(valueAttr, caret);
|
|
188
|
+
caretPrefixW = TextRenderer::measureWidth(prefix.c_str(), style.font_id, style.font_size, style.text_transform);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// An input is one line: its text never wraps. When it is wider than the
|
|
192
|
+
// box, the focused input scrolls it so the caret stays inside; an
|
|
193
|
+
// unfocused one shows its start. Either way it is clipped to the box.
|
|
194
|
+
int textW = content ? TextRenderer::measureWidth(content, style.font_id, style.font_size, style.text_transform) : 0;
|
|
195
|
+
int &scroll = inputScrollX()[id];
|
|
196
|
+
const int room = contentW - kInputCaretWidth;
|
|
197
|
+
if (!focused || !hasValue || textW <= room) {
|
|
198
|
+
scroll = 0;
|
|
199
|
+
} else {
|
|
200
|
+
if (caretPrefixW - scroll > room) scroll = caretPrefixW - room;
|
|
201
|
+
if (caretPrefixW < scroll) scroll = caretPrefixW;
|
|
202
|
+
const int maxScroll = textW - room;
|
|
203
|
+
if (scroll > maxScroll) scroll = maxScroll;
|
|
204
|
+
if (scroll < 0) scroll = 0;
|
|
205
|
+
}
|
|
206
|
+
const bool scrolled = focused && hasValue && textW > room;
|
|
207
|
+
|
|
208
|
+
// The clip: the content box widened by the caret's 1 px left offset, the
|
|
209
|
+
// node's full height (the caret overhangs the text by its outset).
|
|
210
|
+
const int clipX = contentX - 1;
|
|
211
|
+
const int clipW = contentW + 1;
|
|
212
|
+
const bool clip = clipW > 0 && h > 0;
|
|
213
|
+
if (clip) {
|
|
214
|
+
if (DisplayCommand *begin = DisplayList::instance().append()) {
|
|
215
|
+
begin->type = DisplayCommandType::PushClip;
|
|
216
|
+
begin->bx = begin->clip.x = static_cast<int16_t>(clipX);
|
|
217
|
+
begin->by = begin->clip.y = static_cast<int16_t>(y);
|
|
218
|
+
begin->bw = begin->clip.w = static_cast<int16_t>(clipW);
|
|
219
|
+
begin->bh = begin->clip.h = static_cast<int16_t>(h);
|
|
220
|
+
begin->clip.nodeId = -1;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
171
224
|
if (content) {
|
|
172
225
|
// Matches TextRenderer::record's scale formula. The denominator is
|
|
173
226
|
// the bitmap font's height (BitmapFont8x16::kHeight = 16). This
|
|
@@ -175,39 +228,39 @@ void InputRenderer::record(int id)
|
|
|
175
228
|
// system rasterizes at font_size directly — but it still needs to
|
|
176
229
|
// be non-zero to keep the bitmap path's math consistent for callers
|
|
177
230
|
// without `font-family` set.
|
|
178
|
-
const float textScale =
|
|
179
|
-
? static_cast<float>(
|
|
231
|
+
const float textScale = style.font_size > 0
|
|
232
|
+
? static_cast<float>(style.font_size) / 16.0f
|
|
180
233
|
: 1.0f;
|
|
181
234
|
|
|
182
235
|
DisplayCommand *cmd = DisplayList::instance().append();
|
|
183
236
|
if (cmd) {
|
|
184
237
|
cmd->type = DisplayCommandType::DrawText;
|
|
185
238
|
cmd->bx = x; cmd->by = y; cmd->bw = w; cmd->bh = h;
|
|
186
|
-
cmd->text.text = content;
|
|
187
239
|
// `getAttribute` returns a pointer to the in-tree attribute slot, so
|
|
188
240
|
// the string is stable until the attribute is overwritten. The
|
|
189
241
|
// DisplayList commands are replayed within the same frame, so this
|
|
190
242
|
// stays valid for the duration of the present.
|
|
191
|
-
cmd->text.
|
|
192
|
-
//
|
|
193
|
-
|
|
194
|
-
//
|
|
243
|
+
cmd->text.text = content;
|
|
244
|
+
// A scrolled line starts left of the box and is as wide as its text.
|
|
245
|
+
cmd->text.x = scrolled ? contentX - scroll : contentX;
|
|
246
|
+
// Vertically center the single-line text within the content area.
|
|
195
247
|
// 16 = BitmapFont8x16::kHeight (default when no font_size set).
|
|
196
|
-
const int fontSize =
|
|
248
|
+
const int fontSize = style.font_size > 0 ? style.font_size : 16;
|
|
197
249
|
const int yCenter = contentY + (contentH - fontSize) / 2;
|
|
198
250
|
cmd->text.y = yCenter > contentY ? yCenter : contentY;
|
|
199
|
-
cmd->text.maxWidth = contentW;
|
|
251
|
+
cmd->text.maxWidth = scrolled ? textW + 1 : contentW;
|
|
200
252
|
cmd->text.color = color;
|
|
201
253
|
cmd->text.scale = textScale;
|
|
202
|
-
cmd->text.align =
|
|
203
|
-
cmd->text.textTransform =
|
|
204
|
-
cmd->text.lineHeight =
|
|
205
|
-
cmd->text.containerWidth = contentW;
|
|
206
|
-
cmd->text.fontId =
|
|
207
|
-
// append() hands back uninitialized scratch — set these explicitly
|
|
208
|
-
//
|
|
209
|
-
|
|
210
|
-
cmd->text.
|
|
254
|
+
cmd->text.align = scrolled ? 0 : style.text_align;
|
|
255
|
+
cmd->text.textTransform = style.text_transform;
|
|
256
|
+
cmd->text.lineHeight = style.line_height;
|
|
257
|
+
cmd->text.containerWidth = scrolled ? textW + 1 : contentW;
|
|
258
|
+
cmd->text.fontId = style.font_id;
|
|
259
|
+
// append() hands back uninitialized scratch — set these explicitly.
|
|
260
|
+
// white-space is always nowrap: wrapping put long text on a second
|
|
261
|
+
// line that spilled out of the box.
|
|
262
|
+
cmd->text.whiteSpace = 1;
|
|
263
|
+
cmd->text.textOverflow = scrolled ? 0 : style.text_overflow;
|
|
211
264
|
cmd->text.maxHeight = 0;
|
|
212
265
|
cmd->text.firstLineIndent = 0;
|
|
213
266
|
}
|
|
@@ -218,27 +271,22 @@ void InputRenderer::record(int id)
|
|
|
218
271
|
// which Tree::activeInputCaretVisible() returns. Showing the caret while
|
|
219
272
|
// unfocused would be misleading on targets where the framework handles
|
|
220
273
|
// the input's visual editing state.
|
|
221
|
-
if (
|
|
222
|
-
// At the caret
|
|
223
|
-
//
|
|
224
|
-
// placeholder shows.
|
|
225
|
-
const char *valueAttr = tree.getAttribute(id, "value");
|
|
226
|
-
const bool hasValue = valueAttr && valueAttr[0];
|
|
274
|
+
if (focused && tree.activeInputCaretVisible()) {
|
|
275
|
+
// At the caret, from the content's left edge, less the scroll; at the
|
|
276
|
+
// start when the placeholder shows.
|
|
227
277
|
int caretX = contentX - 1;
|
|
228
|
-
if (
|
|
229
|
-
const int
|
|
230
|
-
|
|
231
|
-
const int prefixWidth = TextRenderer::measureWidth(prefix.c_str(), n.computedStyle().font_id, n.computedStyle().font_size, n.computedStyle().text_transform);
|
|
232
|
-
caretX += prefixWidth < contentW ? prefixWidth : contentW - kInputCaretWidth;
|
|
278
|
+
if (caretPrefixW >= 0) {
|
|
279
|
+
const int shown = caretPrefixW - scroll;
|
|
280
|
+
caretX += shown < room ? shown : room;
|
|
233
281
|
}
|
|
234
|
-
const int fontSize =
|
|
235
|
-
const int lineHeight = TextRenderer::measureHeight("M",
|
|
282
|
+
const int fontSize = style.font_size > 0 ? style.font_size : 16;
|
|
283
|
+
const int lineHeight = TextRenderer::measureHeight("M", style.font_id, style.font_size, style.text_transform, style.line_height);
|
|
236
284
|
int textY = contentY + (contentH - fontSize) / 2;
|
|
237
285
|
if (textY < contentY) textY = contentY;
|
|
238
286
|
const int caretY = textY - kInputCaretOutset;
|
|
239
287
|
const int caretH = lineHeight + kInputCaretOutset * 2;
|
|
240
288
|
// caret-color, else the text colour (a placeholder's grey is not it).
|
|
241
|
-
gea::framework::graphics::pixel::native_t caretColor =
|
|
289
|
+
gea::framework::graphics::pixel::native_t caretColor = style.text_color ? style.text_color : gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
242
290
|
if (const char *cc = tree.getAttribute(id, "caret-color"); cc && cc[0] == '#' && std::strlen(cc) >= 7) {
|
|
243
291
|
const unsigned long rgb = std::strtoul(cc + 1, nullptr, 16);
|
|
244
292
|
caretColor = gea::framework::graphics::pixel::nativeColor((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
|
|
@@ -255,6 +303,15 @@ void InputRenderer::record(int id)
|
|
|
255
303
|
cmd->fill.color = caretColor;
|
|
256
304
|
}
|
|
257
305
|
}
|
|
306
|
+
|
|
307
|
+
if (clip) {
|
|
308
|
+
if (DisplayCommand *end = DisplayList::instance().append()) {
|
|
309
|
+
end->type = DisplayCommandType::PopClip;
|
|
310
|
+
end->bx = static_cast<int16_t>(clipX); end->by = static_cast<int16_t>(y);
|
|
311
|
+
end->bw = static_cast<int16_t>(clipW); end->bh = static_cast<int16_t>(h);
|
|
312
|
+
end->clip.nodeId = -1;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
258
315
|
}
|
|
259
316
|
|
|
260
317
|
} // namespace gea::embedded::ui
|
package/ui/virtual_keyboard.cpp
CHANGED
|
@@ -1055,6 +1055,11 @@ void onKeyboardPress(gea::framework::events::PointerEvent &event)
|
|
|
1055
1055
|
const int code = gState.keyCodes[slot];
|
|
1056
1056
|
if (code == 0) return;
|
|
1057
1057
|
applyKeyToActiveInput(code);
|
|
1058
|
+
// The keyboard / OK keys (and return on the wide layout) drop focus. A tap
|
|
1059
|
+
// inside the keyboard skips touch_runtime's focus block, which is what
|
|
1060
|
+
// normally calls sync() -- so without this the keys stayed on screen bound
|
|
1061
|
+
// to no input, and every later key did nothing.
|
|
1062
|
+
VirtualKeyboard::instance().sync();
|
|
1058
1063
|
}
|
|
1059
1064
|
|
|
1060
1065
|
} // namespace
|