Reimplement the archived UI widget stack on the new element-tree system
The old widget system (archive/dusk/ui/) depended on infrastructure this rewrite deleted -- a static X-macro element list, a 9-slice UI_FRAME, and a global gamepad/keyboard focus stack -- so everything below is rebuilt on top of the new native uielement_t pool + parent/child tree instead, gamepad/keyboard-only (no mouse support exists in the input system). New JS widgets (assets/scripts/), all pure composites of Label/Rectangle following the Button.js pattern: Checkbox, Tab, Slider, Dropdown. Slider/ Dropdown expose a directionInput(dx, dy) hook so a menu can hand them LEFT/RIGHT before falling back to cursor movement. New Menu.js replaces the old global uifocus_t stack: a small push/pop stack of Menu instances where only the topmost consumes CANCEL/ACCEPT/ direction input each tick (needed for nested modals -- a Settings sub-page menu plus a "discard changes?" Confirm can be open at once). Held-direction repeat timing matches the old 0.5s delay / 0.1s repeat. New overlay composites (added via a new UI.addOverlay()/UI.removeOverlay(), always drawn/updated after normal roots): FpsCounter, ConsoleOverlay (one Label per console history line, driven directly rather than via add() since History (16) exceeds the 8-children-per-element cap), Crop (letterbox/pillarbox bars), and Fullbox (a reusable tweened full-screen fade covering both the old fullbox and transition effects -- reuses shared instances rather than allocate-and-dispose, since disposing an element from inside its own render() callback risks the same JerryScript refcount corruption hit earlier in this rewrite). New Confirm.js (Yes/No dialog) and Settings.js (+ SettingsGeneral/ SettingsInput sub-pages) built on Menu. Display/Audio settings pages are intentionally not ported -- neither had a real backing engine system even in the old code. Frame is a flat Rectangle for now, not real 9-slice (a genuinely bigger native lift, deliberately deferred). Small native binding additions needed by the above, each with its own unit test: Time.renderDelta, Console.lineCount/getLine/visible/ consumeDirty, a new Screen module, a new Locale module, Input.deadzone, a new Save module, and Label.color (was missing entirely). Also fixes a real gap from the UI.addOverlay() work: uiElementDispose() wasn't removing disposed elements from the new overlay root array, which would have left dangling ids behind. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -173,6 +173,96 @@ static void test_uielement_render_children_explicit_opt_in(void **state) {
|
||||
);
|
||||
}
|
||||
|
||||
static void test_uielement_update_no_override_is_noop_when_childless(
|
||||
void **state
|
||||
) {
|
||||
// No override, no children -- update() should just do nothing, safely.
|
||||
exec("new UIElement().update();");
|
||||
}
|
||||
|
||||
static void test_uielement_update_dispatches_to_js_override(void **state) {
|
||||
exec(
|
||||
"class Foo extends UIElement {"
|
||||
" update() { this.updated = true; }"
|
||||
"}"
|
||||
"var foo = new Foo();"
|
||||
"foo.update();"
|
||||
"if(foo.updated !== true) throw new Error('update() override not called');"
|
||||
);
|
||||
}
|
||||
|
||||
static void test_uielement_no_override_auto_updates_children(void **state) {
|
||||
exec(
|
||||
"class Child extends UIElement {"
|
||||
" update() { this.updated = true; }"
|
||||
"}"
|
||||
"var parent = new UIElement();"
|
||||
"var child = new Child();"
|
||||
"parent.add(child);"
|
||||
"parent.update();"
|
||||
"if(child.updated !== true) throw new Error('child was not auto-updated');"
|
||||
);
|
||||
}
|
||||
|
||||
static void test_uielement_override_does_not_auto_update_children(
|
||||
void **state
|
||||
) {
|
||||
exec(
|
||||
"class Child extends UIElement {"
|
||||
" update() { this.updated = true; }"
|
||||
"}"
|
||||
"class Parent extends UIElement {"
|
||||
" update() { this.overrideCalled = true; }"
|
||||
"}"
|
||||
"var parent = new Parent();"
|
||||
"var child = new Child();"
|
||||
"parent.add(child);"
|
||||
"parent.update();"
|
||||
"if(parent.overrideCalled !== true) throw new Error('override not called');"
|
||||
"if(child.updated === true) {"
|
||||
" throw new Error('child should not auto-update under an override');"
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
static void test_uielement_update_children_explicit_opt_in(void **state) {
|
||||
exec(
|
||||
"class Child extends UIElement {"
|
||||
" update() { this.updated = true; }"
|
||||
"}"
|
||||
"class Parent extends UIElement {"
|
||||
" update() { this.updateChildren(); }"
|
||||
"}"
|
||||
"var parent = new Parent();"
|
||||
"var child = new Child();"
|
||||
"parent.add(child);"
|
||||
"parent.update();"
|
||||
"if(child.updated !== true) throw new Error('updateChildren() did not update child');"
|
||||
);
|
||||
}
|
||||
|
||||
static void test_ui_update_reaches_root_and_children(void **state) {
|
||||
exec(
|
||||
"globalThis.parent = new UIElement();"
|
||||
"globalThis.child = new UIElement();"
|
||||
"class Grandchild extends UIElement {"
|
||||
" update() { this.updated = true; }"
|
||||
"}"
|
||||
"globalThis.grandchild = new Grandchild();"
|
||||
"parent.add(child);"
|
||||
"child.add(grandchild);"
|
||||
"UI.add(parent);"
|
||||
);
|
||||
|
||||
errorCatch(errorPrint(uiUpdate()));
|
||||
|
||||
exec(
|
||||
"if(grandchild.updated !== true) {"
|
||||
" throw new Error('uiUpdate() did not reach a rooted grandchild');"
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
static void test_uielement_add_self_throws(void **state) {
|
||||
execExpectError("var el = new UIElement(); el.add(el);");
|
||||
}
|
||||
@@ -252,6 +342,17 @@ static void test_label_text_default_and_set(void **state) {
|
||||
);
|
||||
}
|
||||
|
||||
static void test_label_color_readback(void **state) {
|
||||
exec(
|
||||
"var label = new Label();"
|
||||
"label.color = { r: 10, g: 20, b: 30, a: 40 };"
|
||||
"if(label.color.r !== 10 || label.color.g !== 20 ||"
|
||||
" label.color.b !== 30 || label.color.a !== 40) {"
|
||||
" throw new Error('color readback wrong');"
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
static void test_rectangle_size_and_color(void **state) {
|
||||
exec(
|
||||
"var rect = new Rectangle();"
|
||||
@@ -332,6 +433,30 @@ int main(void) {
|
||||
test_uielement_render_children_explicit_opt_in,
|
||||
uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_uielement_update_no_override_is_noop_when_childless,
|
||||
uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_uielement_update_dispatches_to_js_override,
|
||||
uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_uielement_no_override_auto_updates_children,
|
||||
uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_uielement_override_does_not_auto_update_children,
|
||||
uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_uielement_update_children_explicit_opt_in,
|
||||
uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_ui_update_reaches_root_and_children,
|
||||
uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_uielement_add_self_throws, uielement_setup, uielement_teardown
|
||||
),
|
||||
@@ -355,6 +480,9 @@ int main(void) {
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_label_text_default_and_set, uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_label_color_readback, uielement_setup, uielement_teardown
|
||||
),
|
||||
cmocka_unit_test_setup_teardown(
|
||||
test_rectangle_size_and_color, uielement_setup, uielement_teardown
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user