feat: switch text to UTF-8; add Unicode key events, dead keys & Czech layout; fix numpad navigation; add NumLock support

This commit is contained in:
daniel committed 2026-10-03 10:11:49 +02:00
1 parent 32660ddd1a
commit 2aa6360b3d
101 files changed
+3733 -1639

No files matched your search

+24 -27
View File
@@ -212,11 +212,7 @@ struct TextBox {
// Draw cursor if focused
if (focused) {
// Measure text up to cursor position for proportional fonts
char prefix[256];
for (int i = 0; i < cursor && i < 255; i++) prefix[i] = text[i];
prefix[cursor < 255 ? cursor : 255] = '\0';
int cx = tx + text_width(prefix);
int cx = tx + text_width_n(text, cursor);
draw_vline(fb, cx, ty, fh, cursor_color);
}
}
@@ -230,34 +226,35 @@ struct TextBox {
void handle_key(const montauk::abi::KeyEvent& key) {
if (!focused || !key.pressed) return;
char typed[montauk::utf8::MAX_BYTES];
int typed_len = montauk::utf8::key_utf8(key, typed);
if (key.ascii == '\b' || key.scancode == 0x0E) {
// Backspace
// Backspace: remove the whole character before the cursor
if (cursor > 0) {
for (int i = cursor - 1; i < text_len - 1; i++) {
text[i] = text[i + 1];
}
text_len--;
cursor--;
text[text_len] = '\0';
int start = montauk::utf8::prev_boundary(text, cursor);
int n = cursor - start;
for (int i = start; i <= text_len - n; i++)
text[i] = text[i + n];
text_len -= n;
cursor = start;
}
} else if ((unsigned char)key.ascii >= 32
&& (unsigned char)key.ascii != 127) {
// Printable character
if (text_len < 254) {
for (int i = text_len; i > cursor; i--) {
text[i] = text[i - 1];
}
text[cursor] = key.ascii;
cursor++;
text_len++;
text[text_len] = '\0';
} else if (typed_len > 0) {
// Printable character, inserted as UTF-8
if (text_len + typed_len <= 254) {
for (int i = text_len; i >= cursor; i--)
text[i + typed_len] = text[i];
for (int i = 0; i < typed_len; i++)
text[cursor + i] = typed[i];
cursor += typed_len;
text_len += typed_len;
}
} else if (key.scancode == 0x4B) {
} else if (montauk::nav_scancode(key) == 0x4B) {
// Left arrow
if (cursor > 0) cursor--;
} else if (key.scancode == 0x4D) {
cursor = montauk::utf8::prev_boundary(text, cursor);
} else if (montauk::nav_scancode(key) == 0x4D) {
// Right arrow
if (cursor < text_len) cursor++;
cursor = montauk::utf8::next_boundary(text, text_len, cursor);
}
}
};