mirror of
https://github.com/ALLFATHER-BV/wadamesh.git
synced 2026-11-11 19:57:40 +00:00
- the canvas is sized from the space below the bar at about one CSS pixel per canvas pixel, whole device pixels where possible (crisp): iPhone 14 390x616, Pixel 7 360x692, iPad 540x686; landscape by height and the window's aspect (664x358, 734x330, 720x506). A computer keeps the framed 800x480. Same large-screen layouts, which size themselves from the display. - a turn restarts the UI in the other layout only when the aspect flips and the width changes (a keyboard is no turn), never while typing - the phone keyboard: no focus ring or tab hotkey letters for it (CAP_NATIVE_KEYBOARD in the nav-keys block), keeps up while tapping the UI mid-edit; IME composition followed live - the page: slim one-row bar (slimmer on its side), safe areas, link help as an overlay, home-screen icons (icons/app-icon.svg + render.mjs, maskable) - tests: web/build.sh mobiletest (iPhone 14, Pixel 7, iPad): fill > 90 %, UTF-8 + emoji through the hidden field, IME composition, send, turn and back with the message kept, chooser, manifest. Labels found by text (wadamesh.findText) so taps work at any size; the UTF-8 storage check searches bytes. webtest's phone step checks the portrait canvas. - WEB_BUILD.md "Phones and tablets"; the stray docs/tmp shots removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
5.5 KiB
C++
124 lines
5.5 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// LVGL-side input helpers of the web board (WebInput.h): text fields for the phone's
|
|
// keyboard (below), and mouse wheel / trackpad scrolling (webWheel). A panel has no
|
|
// wheel, so the UI never asks for one: this scrolls the LVGL object under the pointer the way a finger drag would, without a press (nothing gets clicked or
|
|
// long-pressed). It finds the topmost object under the pointer (system layer, top
|
|
// layer, then the screen, as LVGL's own pointer search does) and walks up to the first
|
|
// ancestor that can still scroll that way, so a list inside a page scrolls before the
|
|
// page does. Vertical only: the UI's horizontal scrollers are tab strips that snap.
|
|
// Runs on the UI thread between LVGL timer passes (the front ends' event pumps).
|
|
#include "WebInput.h"
|
|
#include <Arduino.h>
|
|
#include <lvgl.h>
|
|
#include <string.h>
|
|
|
|
namespace {
|
|
lv_obj_t* s_scrolled = nullptr; // the object the last wheel step moved
|
|
uint32_t s_last_ms = 0;
|
|
|
|
lv_obj_t* hit(lv_point_t p) {
|
|
if (lv_obj_t* o = lv_indev_search_obj(lv_layer_sys(), &p)) return o;
|
|
if (lv_obj_t* o = lv_indev_search_obj(lv_layer_top(), &p)) return o;
|
|
return lv_indev_search_obj(lv_scr_act(), &p);
|
|
}
|
|
} // namespace
|
|
|
|
void webWheel(int x, int y, int dy) {
|
|
if (dy == 0 || !lv_scr_act()) return;
|
|
for (lv_obj_t* o = hit(lv_point_t{(lv_coord_t)x, (lv_coord_t)y}); o; o = lv_obj_get_parent(o)) {
|
|
if (!lv_obj_has_flag(o, LV_OBJ_FLAG_SCROLLABLE) || !(lv_obj_get_scroll_dir(o) & LV_DIR_VER)) continue;
|
|
// dy > 0: the wheel turned down / two fingers moved up: show what is further down
|
|
const lv_coord_t room = dy > 0 ? lv_obj_get_scroll_bottom(o) : lv_obj_get_scroll_top(o);
|
|
if (room <= 0) continue; // this one is at its end: chain to the parent
|
|
const lv_coord_t step = (lv_coord_t)(dy > 0 ? LV_MIN(dy, room) : -LV_MIN(-dy, room));
|
|
if (s_scrolled && s_scrolled != o && lv_obj_is_valid(s_scrolled)) lv_event_send(s_scrolled, LV_EVENT_SCROLL_END, nullptr);
|
|
if (s_scrolled != o) lv_event_send(o, LV_EVENT_SCROLL_BEGIN, nullptr);
|
|
lv_obj_scroll_by(o, 0, -step, LV_ANIM_OFF);
|
|
s_scrolled = o;
|
|
s_last_ms = millis();
|
|
return;
|
|
}
|
|
}
|
|
|
|
// From the board loop: a wheel that has stopped ends the scroll (lists that load more
|
|
// at their end, or tidy up, listen for SCROLL_END as they do after a drag).
|
|
void webWheelTick() {
|
|
if (!s_scrolled || millis() - s_last_ms < 150) return;
|
|
if (lv_obj_is_valid(s_scrolled)) lv_event_send(s_scrolled, LV_EVENT_SCROLL_END, nullptr);
|
|
s_scrolled = nullptr;
|
|
}
|
|
|
|
// ---- text fields, for the phone's own keyboard (web/shell/app.js) -----------------------
|
|
bool webTextareaAt(int x, int y) {
|
|
if (!lv_scr_act()) return false;
|
|
for (lv_obj_t* o = hit(lv_point_t{(lv_coord_t)x, (lv_coord_t)y}); o; o = lv_obj_get_parent(o))
|
|
if (lv_obj_check_type(o, &lv_textarea_class)) return true;
|
|
return false;
|
|
}
|
|
namespace {
|
|
lv_obj_t* findKeyboard(lv_obj_t* o, int depth) {
|
|
if (!o || depth > 12) return nullptr;
|
|
if (lv_obj_check_type(o, &lv_keyboard_class)) return o;
|
|
const uint32_t n = lv_obj_get_child_cnt(o);
|
|
for (uint32_t i = 0; i < n; ++i)
|
|
if (lv_obj_t* k = findKeyboard(lv_obj_get_child(o, i), depth + 1)) return k;
|
|
return nullptr;
|
|
}
|
|
lv_obj_t* s_kb = nullptr;
|
|
uint32_t s_kb_look_ms = 0;
|
|
} // namespace
|
|
// The UI keeps one keyboard object and binds it to the field being edited (showKb), also
|
|
// while an external keyboard types and the keys stay hidden; unbinding ends the edit.
|
|
bool webEditing() {
|
|
if (s_kb && !lv_obj_is_valid(s_kb)) s_kb = nullptr;
|
|
if (!s_kb && millis() - s_kb_look_ms > 1000) {
|
|
s_kb_look_ms = millis();
|
|
s_kb = findKeyboard(lv_layer_top(), 0);
|
|
if (!s_kb) s_kb = findKeyboard(lv_layer_sys(), 0);
|
|
if (!s_kb) s_kb = findKeyboard(lv_scr_act(), 0);
|
|
}
|
|
return s_kb && lv_keyboard_get_textarea(s_kb) != nullptr;
|
|
}
|
|
bool webOskShown() {
|
|
webEditing(); // finds the keyboard object
|
|
return s_kb && !lv_obj_has_flag(s_kb, LV_OBJ_FLAG_HIDDEN);
|
|
}
|
|
|
|
// ---- tests: find a label by its text (web/shell/app.js wadamesh.findText) -------------------
|
|
// The phone tests run at whatever size the phone gets, so they tap things by name instead of
|
|
// by fixed coordinates. Exact match first, then a label that contains the text; only labels
|
|
// that are visible on screen. Returns the middle as (x << 16) | y, or -1.
|
|
namespace {
|
|
lv_obj_t* findLabel(lv_obj_t* o, const char* text, bool exact, int depth) {
|
|
if (!o || depth > 40 || lv_obj_has_flag(o, LV_OBJ_FLAG_HIDDEN)) return nullptr;
|
|
if (lv_obj_check_type(o, &lv_label_class) && lv_obj_is_visible(o)) {
|
|
const char* t = lv_label_get_text(o);
|
|
if (t && (exact ? strcmp(t, text) == 0 : strstr(t, text) != nullptr)) return o;
|
|
}
|
|
const uint32_t n = lv_obj_get_child_cnt(o);
|
|
for (uint32_t i = 0; i < n; ++i)
|
|
if (lv_obj_t* f = findLabel(lv_obj_get_child(o, i), text, exact, depth + 1)) return f;
|
|
return nullptr;
|
|
}
|
|
} // namespace
|
|
int webFindText(const char* text) {
|
|
if (!text || !*text || !lv_scr_act()) return -1;
|
|
lv_obj_t* roots[3] = {lv_layer_sys(), lv_layer_top(), lv_scr_act()};
|
|
for (int pass = 0; pass < 2; ++pass)
|
|
for (lv_obj_t* r : roots)
|
|
if (lv_obj_t* o = findLabel(r, text, pass == 0, 0)) {
|
|
lv_area_t a;
|
|
lv_obj_get_coords(o, &a);
|
|
const int x = LV_CLAMP(0, (a.x1 + a.x2) / 2, 0x7fff), y = LV_CLAMP(0, (a.y1 + a.y2) / 2, 0xffff);
|
|
return (x << 16) | y;
|
|
}
|
|
return -1;
|
|
}
|
|
// Tests: the text of the field the UI's keyboard is bound to ("" when none).
|
|
const char* webEditText() {
|
|
if (!webEditing()) return "";
|
|
lv_obj_t* ta = lv_keyboard_get_textarea(s_kb);
|
|
const char* t = ta ? lv_textarea_get_text(ta) : nullptr;
|
|
return t ? t : "";
|
|
}
|