Files
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

51 lines
1.6 KiB
Makefile

# Run inside `nix develop`, which provides pio, lua and a compiler.
# LUA is pinned to 5.4 to match the interpreter vendored into the firmware.
LUA ?= lua
CXX ?= c++
CXXFLAGS ?= -std=c++11 -Wall -Wextra
BUILD_DIR := .pio/build/esp32-32e
LUA_TESTS := test/ui_theme.lua test/keyboard.lua test/settings_calibration.lua test/statusbar_dirty.lua test/settings_busy.lua
.PHONY: test test-lua test-cpp test-stubs stubs build upload monitor clean
test: test-cpp test-lua test-stubs
# The stub is only useful if it matches the bindings, and nothing but a check keeps it
# honest -- an editor completing a function the firmware no longer has is worse than no
# completion at all.
test-stubs:
@printf '%-32s ' stubs/slate32.lua; python3 scripts/gen_lua_stubs.py --check && echo ok
stubs:
@python3 scripts/gen_lua_stubs.py
test-lua:
@$(LUA) -e 'assert(_VERSION == "Lua 5.4", "tests need Lua 5.4 to match the firmware, got " .. _VERSION)'
@for t in $(LUA_TESTS); do printf '%-32s ' "$$t"; $(LUA) "$$t" || exit 1; done
test-cpp: $(BUILD_DIR)/round_rect_test $(BUILD_DIR)/ui_layout_test
@printf '%-32s ' test/round_rect_test.cpp; $(BUILD_DIR)/round_rect_test
@printf '%-32s ' test/ui_layout_test.cpp; $(BUILD_DIR)/ui_layout_test
$(BUILD_DIR)/round_rect_test: test/round_rect_test.cpp src/gfx/round_rect.h
@mkdir -p $(@D)
@$(CXX) $(CXXFLAGS) $< -o $@
$(BUILD_DIR)/ui_layout_test: test/ui_layout_test.cpp src/ui/layout.h
@mkdir -p $(@D)
@$(CXX) $(CXXFLAGS) $< -o $@
build:
pio run
upload:
pio run -t upload
monitor:
pio device monitor
clean:
pio run -t clean
rm -f $(BUILD_DIR)/round_rect_test $(BUILD_DIR)/ui_layout_test