Commit Graph

19 Commits

Author SHA1 Message Date
evan f7c5cc09ba feat(ui)!: move the widget tree into C++
A node was a Lua table of ~625 bytes, of which 21 keys pushed it over a
power-of-two hash boundary and eight were style copies inheritance had
splattered down from its parent. A 400 node screen cost ~250 KB and could not
coexist with wifi's buffers.

The tree now lives in src/ui/layout.h as a 16 byte struct in a flat arena, and
splits by lifetime: Node holds what hit testing and repainting need forever,
Spec holds what only measure/place read and is dropped when layout ends. Style
is sparse and resolved by walking parents, so a node naming no colours costs
nothing. Re-layout rebuilds from Lua rather than retaining the inputs.

    401 nodes:  8218 B steady, 21050 B peak
           Lua: ~250000 B steady

sdcard/lib/ui.lua stays the toolkit and keeps every constructor signature, but
returns integer handles: 627 lines to 374. Composition, the palette and custom
painters are still Lua on the SD card; only primitives now need a reflash.

BREAKING CHANGE: ui constructors return handles, not tables. Use
ui.setText(id, text) and keep per-node app data in a table keyed by id.
2026-08-02 18:48:48 -04:00
evan 932d41aeeb revert(ui): remove scrollable box
Keep raw touch-move events for direct gesture consumers such as Paint. Toolkit screens remain frame-sized to avoid redraw and heap costs.
2026-08-02 17:44:39 -04:00
evan 7c0928d84e feat(ui): add drag gestures and a scrollable box
The firmware now fires on_touch_move with a 2px noise threshold; gesture
intent is the toolkit's 8px slop, since a painting app's stroke starts at
the first real pixel. Past the slop, Screen:move hands the drag to the
nearest scroll ancestor and cancels the widget under the finger.

ui.scroll leans on the app viewport for clipping, so it must reach both
panel edges. Paint and Scroll demo both halves of the gesture split.
2026-08-02 16:59:42 -04:00
evan b51d9c3c4a fix(ui): stabilize partial press redraws 2026-08-02 16:18:11 -04:00
evan 6b6280b72a feat(ui): add reusable on-screen keyboard 2026-08-02 16:07:10 -04:00
evan b2f58118e1 revert(gui): return text rendering to built-in Font 1
Remove OpenFontRender, embedded Meslo assets, custom-font APIs, and their runtime allocation overhead. Keep the taller status layout and compact card grid, with used RAM, aligned faded WiFi bars, and tighter telemetry rows.
2026-08-02 15:26:40 -04:00
evan 1cb52997a9 feat(gui): render user-selectable TTF fonts
Embed a Latin-1 Meslo LG S default and use OpenFontRender for anti-aliased text with an explicit pixel size on each draw and measurement call. Apps may replace the one retained face with an SD-backed TTF and restore Meslo with nil. Refresh UI sizing, status telemetry, Settings typography, tests, documentation, and font license notices.
2026-08-02 14:54:49 -04:00
evan 497fab35d9 feat(ui): enlarge the status bar and card grids
Use a two-row 44px status bar with a full-height back button, centered app name, WiFi beside the clock, and free/total RAM below. Expand grids to three portrait and four landscape columns with consistent card text and left-to-right partial rows.
2026-08-02 13:45:00 -04:00
evan b5146b8642 refactor(lua): give the status bar its own dirty tracking and split settings out of sys
The bar repainted itself whole every second. It now compares each field against what
it last painted, adds seconds and a memory percentage, and keys the cache on
gui.getRotation() and ui.themeName so rotation and theme changes still repaint it.
Invalidation lives entirely in Lua; the firmware's push flag and gfx/statusbar.h are gone.

Bindings follow getName/setName/isName, persisted preferences move from sys to a settings
table, and gui.setRotation takes degrees like settings does. A bar that dies mid-run now
keeps its rows reserved rather than silently resizing the running app.
2026-08-02 10:49:01 -04:00
evan 6bbe192081 fix(ui): draw button labels without an opaque text background
gui.drawText painted a flat rectangle behind every glyph, so a label on a
gradient card sat in a patch matching only the one gradient row its colour
came from. Omitting the background colour now draws transparent glyphs, and
buttons pass none: the face is repainted above them on every change, so the
label has nothing to erase.
2026-08-01 22:58:19 -04:00
evan 114c8c5f72 feat(ui): add persistent status bar and card grid launcher
The bar is host-owned chrome: the firmware clips apps into a viewport below
it, so no app can paint over it, while /lib/statusbar.lua owns the height,
repaint interval and painting. gui.fullscreen() lets touch calibration take
the physical panel back.

Launcher and settings become grids of square cards (3 across landscape, 2
portrait) via the new gui.setTextSize, ui.label and ui.cardSide. The one
function on the `app` table moves to sys.setTickInterval, alongside the new
sys.appName the bar needs.
2026-08-01 22:50:19 -04:00
evan fea0e9c291 fix(settings): reduce keyboard memory usage 2026-08-01 21:43:17 -04:00
evan e530331613 feat(ui): dim the content behind a dialog
The panel has no alpha and there is no framebuffer to blend against -- 307KB against
276KB free -- so a scrim cannot be composited. It can be computed instead: the palette
is re-derived from seeds mixed toward black, and the content behind a dialog is
repainted in those colors, which is the result a black scrim would have produced. The
tree was already the source of truth, so dimming is a palette swap rather than a
readback. A node marked dimmed carries it to everything it contains, and ui.confirm
opts its card back out.

Doing that exposed a latent bug in bordered boxes. They filled a square rect and then
drew a rounded border over it, so the corners the border does not cover showed the
fill. That was invisible while everything behind a card was the same color as the card,
and obvious the moment the background dimmed. Separating the two roles fixes it: bg is
what a node fills, surface is what sits underneath, anti-aliased edges blend into
surface, and a box that paints its own rounded background suppresses the square fill.
2026-08-01 18:54:19 -04:00
evan f7c86ded80 feat(ui): dialogs as ordinary nodes, with capture, border and fill
A dialog is a component the app includes when its state says so, placed absolutely so
it covers the flow instead of joining it, and dismissed by rebuilding without it. No
layer stack, no module state, no lifecycle: "on top" already means "later in the child
list", which the draw walk gives for free, and nothing needs to survive a rebuild
because the tree is derived from state rather than mutated beside it.

The alternative was a ui.push/ui.pop stack of roots. It would have been the only
imperative thing in an otherwise declarative program, and needed rules to reconcile two
ways for something to reach the screen -- the rule that a rebuild must only replace the
base being the one that would eventually be forgotten.

Three primitives were missing and are now here. capture makes a component swallow the
taps its children missed, without which the hit walk falls back to earlier siblings and
a dialog can be tapped through. border draws a box as a rounded rect. fill names a size
a fraction cannot express, since any number >= 1 is read as pixels, so w = 1.0 asked
for one pixel.

The root now measures as "fill" rather than auto. It is placed at the full panel rect
already, so its own children could not resolve a fraction of the one component whose
size is never in doubt.

Settings asks before forgetting a network, which is the first caller.
2026-08-01 18:43:35 -04:00
evan 5a3aabf220 feat(ui): setText on text nodes
Assigning .label repainted nothing until the caller also remembered to invalidate, and
forgetting produced a screen that silently stopped updating with no error to follow.
setText makes the pair atomic and skips the repaint when the text is unchanged, so an
app can push a value on every tick without comparing first.
2026-08-01 18:09:08 -04:00
evan 2cdb7b3702 feat: timezone setting and main-axis justify in the ui toolkit
The launcher clock read UTC and sat next to the title because the toolkit could only
stack children from the start of an axis. justify adds the CSS main-axis modes that
had a caller -- start, end, center, between -- so a header keeps its title left and
its clock right without any app doing arithmetic.

Timezones are stored as POSIX TZ rules rather than offsets, so newlib applies DST
changeovers and os.date() in Lua reports local time with no binding of its own.
/lib/timezones.lua is only the picker list: a zone missing from it still works if its
rule is written into settings, the same split themes already use.

settings_calibration.lua now finds rows by label. Adding the timezone row shifted
every hardcoded y coordinate in it, which is the failure that had been predicted and
would have silently retargeted taps at the wrong control.
2026-08-01 17:03:55 -04:00
evan 36953bb140 fix(gui): anti-aliased rounded rects from one distance field
Corners were drawn by two disagreeing algorithms: a hand-rolled per-row inset for
the gradient fill and TFT_eSPI's Bresenham arc for the border, so they missed each
other by a pixel and left a halo. The inset was also wrong, truncating the sqrt and
ignoring pixel centres, which over-cut the top row by 2px into a visible chamfer.

gui.roundRect now derives fill and border from the same signed distance, blending
edge pixels by coverage, and replaces fillRoundRect, drawRoundRect and
fillRectGradient. The geometry moved to src/gfx/round_rect.h so round_rect_test.cpp
can check the arc on the host, since only the eye ever checked the old one.
2026-08-01 11:04:35 -04:00
evan 0a27062a70 feat(ui): themes derived from three seed colors
Every app re-declared the same black/white/accent triple, so a palette now lives in
/lib/theme.lua and ui.lua derives muted, contrast, gradients and radius from it.
Deriving rather than listing means a new component costs no theme keys, and a theme
cannot pick text that is unreadable on its own accent.

Components take the palette by inheritance, so the three apps name no colors at all;
ui.theme stays for drawing outside the tree. Settings cycles the installed themes and
stores only the name.
2026-08-01 10:04:52 -04:00
evan 4e5796fd51 feat(ui): layout toolkit, Lua launcher and touch press events
Apps describe nesting instead of coordinates: /lib/ui.lua borrows CSS block flow,
the box model and auto sizing, and owns hit testing, press capture and the pressed
repaint. The runtime gains require backed by the SD card, on_touch_down/on_touch_up,
text metrics and rounded gradient fills, so the launcher becomes an ordinary Lua app
and the firmware keeps only a fallback screen for an unreadable card.
2026-07-31 22:27:34 -04:00