Files
breeze/tests/practice_results_apps_behavior.zi
waozi 017d3565d3 Build on Ziran 0.5.0 and Kryon's namespaced widgets, with the Tao picture page
Pin only pushed commits, with no local overrides: Ziran v0.5.0
(f9f92b46), Kryon b45cc524 (one lock entry, ref master, shared with the
Css and Plot master edges), Apps 352901e, Entity b30dd4a and practices
893e5b6f, whose sharpened banners and regenerated Lumi guide clips the
narration check now matches.

The Library opens each Tao Te Ching chapter on its own picture page: the
chapter art and its title, centered together; the text pages follow.
The reader keeps the picture page across reflow, and a chapter start or
a Contents pick opens it. The 81 approved chapter pictures are included.

Breeze now uses Kryon's namespaced widgets (Text.Draw/Text.Props,
Button, Image, Modal.ActionModal, Layout, TabBar, LoadingScreen,
LoadingIndicator, Shape.Circle) instead of the removed Kryon/Widgets
facades. Hosted apps import std/text explicitly, since a short "text"
import now names Kryon's widget. AGENTS.md and the Text/Button API checks
describe the namespaced forms; two unused test doubles are removed.

Build fixes for the new toolchain: the bundle runtime carries Ziran's
instruction engine (no BOOTSTRAP=1) and takes the pinned host zi2c for
cross builds; the Apps controller's lock context has the manifest's
module roots; the app codec generator lists Kryon's raw modules only;
the package scripts read ZX revision 28 bundle assets. The Apps
controller digest matches the Apps 352901e build.

Also included: the stopped lanes' work in this tree (Radio download,
Photos install, Lists, Lumi, Habits shop rewards, astral exercise
selection, appearance and download recovery) and the raylib-free desktop
lane's host modules (app_trace, host_input, host_window, host_clock),
inactive unless DESKTOP_HOST is defined.

Not included: the crash-recovery lane's picture-window and storage
crash-safety changes, which that lane commits itself.

Local tests: zi-check (510 modules), native and Android source checks,
hosted app checks, build-laws, clean-text-api-check, button-api-check,
library-reader-test, library-ui-test, storage-crash-zi-test and
native-image-decode-test pass. The bundled Arcade is still ZX revision 26
and waits for an Arcade build on these pins.
2026-11-16 14:20:12 -03:00

201 lines
8.0 KiB
Ziran

// Practices draws a finished practice's results: the bundled package reads
// each Wim Hof round through the host, draws the chart and the mood faces,
// and gives back the mood picked, Discard or Done.
#import "session"
#import "geometry"
#import "kryon/tree"
#import "tree_draw"
#import "tree_input"
#import "input_protocol"
#import "paint_queue"
#import "bundle_host"
#import "byte_text_linux"
#import "hosted_values"
#import "widget_host"
#import "drawing_props"
#import, file "../src/apps/module_host.zi";
#import, file "../src/apps/practice_types.zi";
#import, file "../src/apps/practice_ui_types.zi";
#import, file "../src/apps/app_codec.zi";
#import, file "../src/app/exercise_types.zi";
using ExerciseType;
using HostValueKind;
results_test_frame: PracticeResultsFrame;
results_test_codec: WidgetPracticeResultsFrameCodec;
results_test_round_codec: WidgetPracticeResultRoundCodec;
results_test_writes: s32;
results_test_rounds: s32;
ResultsTestAssets :: (path: string) -> bool {
return path.count == 0
}
ResultsTestCall :: (context: *void, module: *u8, function: *u8,
arguments: *HostValue, count: s32, result: *HostValue) -> s32 {
if TextFromCString(module) != "results_view" {
return WidgetHostCall(context, module, function, arguments, count, result)
}
name := TextFromCString(function)
if name == "ReadPracticeResultsHost" && count == 0 {
result.* = WidgetEncodePracticeResultsFrame(results_test_frame, *results_test_codec)
return 1
}
if name == "WritePracticeResultsHost" && count == 1 && WidgetValidPracticeResultsFrame(arguments[0]) {
results_test_writes += 1
results_test_frame = WidgetDecodePracticeResultsFrame(arguments[0], *results_test_codec)
return 1
}
if name == "ReadPracticeResultRoundHost" && count == 1 {
index := cast(s32)arguments[0].integer
if index < 0 || index >= results_test_frame.round_count { return 0 }
results_test_rounds += 1
result.* = WidgetEncodePracticeResultRound(PracticeResultRound.{.seconds = 60 + index * 15},
*results_test_round_codec)
return 1
}
if name == "ResultsLocaleHost" && count == 1 {
text := "Round %d: %ds"
result.* = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"),
.data = HostTextData(text), .length = cast(usize)text.count}
return 1
}
return 0
}
ResultsTestDraw :: (frame: PracticeResultsFrame, frame_id: u64) -> s32 {
session := SessionOpen()
BeginFrame(session, frame_id, Rectangle.{0.0, 0.0, 411.0, 900.0})
frame.session = session
results_test_frame = frame
results_test_writes = 0
results_test_rounds = 0
WidgetHostBegin(session, ResultsTestAssets)
AppsUiBegin(ResultsTestCall, null)
drawn := PracticeRun(PracticeMessage.{.action = PRACTICE_RESULTS_VIEW})
AppsUiEnd()
WidgetHostEnd()
painted := PendingPaintCount(session)
unused EndFrame(session)
unused SessionClose(session)
if !drawn.succeeded { return 1 }
if results_test_writes != 1 { return 2 }
if painted == 0 { return 3 }
return 0
}
// Draws the results with `mood` picked (0 for none) and, when `tap` is 0 or
// more, taps that face's button on a second frame. Returns 0 when all five
// faces and their labels are there and the tap asks for its mood.
ResultsTestMood :: (mood: s32, tap: s32) -> s32 {
session := SessionOpen()
frame := PracticeResultsFrame.{.scale = 1.0, .view_width = 360, .view_height = 800,
.canvas_color = Color.{.r = 245, .g = 248, .b = 246, .a = 255},
.surface_color = Color.{.r = 255, .g = 255, .b = 255, .a = 255},
.border_color = Color.{.r = 210, .g = 215, .b = 212, .a = 255},
.link_color = Color.{.r = 60, .g = 120, .b = 200, .a = 255},
.text_color = Color.{.r = 30, .g = 30, .b = 30, .a = 255}, .center_x = 180,
.activity = EXERCISE_PATTERNS, .name = "Breathing Patterns", .saved = true, .mood = mood,
.primary = 300, .secondary = 12, .detail = "Box"}
results_test_frame = frame
clicked: Rectangle
for pass: cast(s32)0..1 {
if pass == 1 && tap < 0 { break }
if pass == 1 {
unused TreePointerUpdate(session, PointerFrame.{.x = clicked.x + clicked.width / 2.0,
.y = clicked.y + clicked.height / 2.0, .down = true, .pressed = true})
unused TreePointerUpdate(session, PointerFrame.{.x = clicked.x + clicked.width / 2.0,
.y = clicked.y + clicked.height / 2.0, .released = true})
}
// One screen key across both frames, as in the app: a new key is a
// new screen, which drops the tap.
BeginFrame(session, cast(u64)200, Rectangle.{0.0, 0.0, 360.0, 800.0})
results_test_frame.session = session
WidgetHostBegin(session, ResultsTestAssets)
AppsUiBegin(ResultsTestCall, null)
drawn := PracticeRun(PracticeMessage.{.action = PRACTICE_RESULTS_VIEW})
AppsUiEnd()
WidgetHostEnd()
unused EndFrame(session)
if !drawn.succeeded {
unused SessionClose(session)
return 1
}
if pass == 0 {
buttons: s32 = 0
labels: s32 = 0
for index: cast(s32)0..TreeCount(session) - 1 {
node := TreeNodeAt(session, index)
if node.focus_id >= 24800 && node.focus_id <= 24804 {
buttons += 1
if node.focus_id == 24800 + tap {
clicked = node.bounds
}
}
if node.semantic_label == "Round %d: %ds" && node.bounds.height <= 20.0 && node.bounds.width > 0.0 && node.bounds.width < 80.0 {
labels += 1
}
}
if buttons != 5 {
unused SessionClose(session)
return 2
}
if labels < 5 {
unused SessionClose(session)
return 3
}
}
}
unused SessionClose(session)
if tap >= 0 && (results_test_frame.action != PRACTICE_RESULTS_MOOD || results_test_frame.value != tap + 1) {
return 4
}
return 0
}
// Draws the picker with no mood and each mood picked, then taps three faces.
CheckPracticeResultsMood :: () -> s32 {
for mood: cast(s32)0..5 {
failed := ResultsTestMood(mood, -1)
if failed != 0 { return 10 * (mood + 1) + failed }
}
for tap: cast(s32)0..4 {
failed := ResultsTestMood(ifx tap == 2 then 0 else 3, tap)
if failed != 0 { return 100 + 10 * tap + failed }
}
return 0
}
// Draws four Wim Hof rounds, one round, and a breathing pattern's time;
// returns 0 when each went through the host and asked for nothing.
CheckPracticeResults :: () -> s32 {
frame := PracticeResultsFrame.{.scale = 1.0, .view_width = 411, .view_height = 900,
.canvas_color = Color.{.r = 245, .g = 248, .b = 246, .a = 255},
.surface_color = Color.{.r = 255, .g = 255, .b = 255, .a = 255},
.border_color = Color.{.r = 210, .g = 215, .b = 212, .a = 255},
.link_color = Color.{.r = 60, .g = 120, .b = 200, .a = 255},
.text_color = Color.{.r = 30, .g = 30, .b = 30, .a = 255}, .center_x = 205,
.activity = EXERCISE_WIM_HOF, .name = "Wim Hof Breathing", .saved = true, .mood = 4,
.round_count = 4}
rounds := ResultsTestDraw(frame, cast(u64)1)
if rounds != 0 { return rounds }
if results_test_rounds != 4 || results_test_frame.action != PRACTICE_RESULTS_NONE { return 4 }
frame.round_count = 1
one := ResultsTestDraw(frame, cast(u64)2)
if one != 0 { return 4 + one }
frame.activity = EXERCISE_PATTERNS
frame.name = "Breathing Patterns"
frame.round_count = 0
frame.primary = 300
frame.secondary = 12
frame.detail = "Box"
frame.saved = false
pattern := ResultsTestDraw(frame, cast(u64)3)
if pattern != 0 { return 8 + pattern }
if results_test_frame.action != PRACTICE_RESULTS_NONE { return 12 }
mood := CheckPracticeResultsMood()
if mood != 0 { return 20 + mood }
return 0
}