Files
breeze/tests/habits_list_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

139 lines
5.7 KiB
Ziran

// The habit list and a habit's page are Habits' own: the bundled package
// draws them from the frame the host gives it and reads each habit and day
// through the host, within the calls the host allows Habits. The host never
// composes the list.
#import "session"
#import "geometry"
#import "kryon/tree"
#import "tree_draw"
#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/habits_types.zi";
#import, file "../src/apps/habits_ui_types.zi";
#import, file "../src/apps/app_codec.zi";
#import, file "../src/habits/habit_types.zi";
using HostValueKind;
list_test_frame: HabitsListFrame;
list_test_codec: WidgetHabitsListFrameCodec;
list_test_row_codec: WidgetHabitsListRowCodec;
list_test_day_codec: WidgetHabitsListDayCodec;
list_test_reads: s32;
list_test_written: bool;
list_test_rows_seen: u32;
list_test_days: s32;
list_test_bad_day: bool;
ListTestAssets :: (path: string) -> bool {
return path.count == 0
}
ListTestCall :: (context: *void, module: *u8, function: *u8,
arguments: *HostValue, count: s32, result: *HostValue) -> s32 {
if TextFromCString(module) != "habit_list_view" {
return WidgetHostCall(context, module, function, arguments, count, result)
}
name := TextFromCString(function)
if name == "ReadHabitsListHost" && count == 0 {
list_test_reads += 1
result.* = WidgetEncodeHabitsListFrame(list_test_frame, *list_test_codec)
return 1
}
if name == "WriteHabitsListHost" && count == 1 && WidgetValidHabitsListFrame(arguments[0]) {
list_test_written = true
list_test_frame = WidgetDecodeHabitsListFrame(arguments[0], *list_test_codec)
return 1
}
if name == "ReadHabitsListRowHost" && count == 1 {
index := cast(s32)arguments[0].integer
if index < 0 || index >= list_test_frame.habit_count { return 0 }
list_test_rows_seen |= cast(u32)1 << cast(u32)index
row := HabitsListRow.{.name = ifx index == 0 then "Meditation" else "Push ups",
.color = Color.{.r = 120, .g = 190, .b = 230, .a = 255}, .icon = ifx index == 0 then 1 else 0,
.deactivated = index == 2, .counting = index == 1, .target = 3,
.streak = 4, .week_done = 2, .week_planned = 5}
result.* = WidgetEncodeHabitsListRow(row, *list_test_row_codec)
return 1
}
if name == "ReadHabitsListDayHost" && count == 2 {
index := cast(s32)arguments[0].integer
day := cast(s32)arguments[1].integer
if index < 0 || index >= list_test_frame.habit_count { return 0 }
// Days are dates up to today.
if day > list_test_frame.today || day < 20260101 {
list_test_bad_day = true
}
list_test_days += 1
state := HabitsListDay.{.day = day, .planned = true, .complete = day % 2 == 0,
.count = ifx index == 1 then 2 else 0}
result.* = WidgetEncodeHabitsListDay(state, *list_test_day_codec)
return 1
}
if name == "HabitsLocaleHost" && count == 1 {
text := "%d / %d habits"
result.* = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"),
.data = HostTextData(text), .length = cast(usize)text.count}
return 1
}
return 0
}
ListTestDraw :: (frame: HabitsListFrame, frame_id: u64) -> s32 {
session := SessionOpen()
bounds := Rectangle.{0.0, 0.0, 400.0, 760.0}
BeginFrame(session, frame_id, bounds)
frame.session = session
list_test_frame = frame
list_test_reads = 0
list_test_written = false
list_test_rows_seen = 0
list_test_days = 0
WidgetHostBegin(session, ListTestAssets)
AppsUiBegin(ListTestCall, null)
drawn := HabitsRun(HabitsMessage.{.action = HABITS_LIST_VIEW})
AppsUiEnd()
WidgetHostEnd()
painted := PendingPaintCount(session)
unused EndFrame(session)
unused SessionClose(session)
if !drawn.succeeded { return 1 }
if list_test_reads != 1 || !list_test_written { return 2 }
if painted == 0 { return 3 }
return 0
}
// Draws the list with an open habit and the inactive habits shown, then the
// habit's calendar; returns 0 when the package drew both through the host.
CheckHabitList :: () -> s32 {
frame := HabitsListFrame.{.scale = 1.0,
.bounds = Rectangle.{16.0, 20.0, 368.0, 700.0}, .font = 16, .small_font = 14,
.text_color = Color.{.r = 230, .g = 230, .b = 240, .a = 255},
.surface_color = Color.{.r = 30, .g = 30, .b = 40, .a = 255},
.accent_color = Color.{.r = 150, .g = 120, .b = 230, .a = 255},
.today = 20261024, .habit_count = 3, .habit_limit = HABIT_MAX, .halves = 3,
.screen_mode = HABITS_SCREEN_OVERVIEW, .view_mode = HABIT_VIEW_WEEKLY,
.selected = 0, .show_deactivated = true, .reveal_selected = true,
.weekly_days = HABIT_WEEKLY_INITIAL_DAYS}
overview := ListTestDraw(frame, cast(u64)1)
if overview != 0 { return overview }
// Every habit was read, and the two active ones' days, within the week.
if list_test_rows_seen != cast(u32)7 || list_test_days < 2 * 4 || list_test_bad_day { return 4 }
if list_test_frame.action != HABITS_LIST_NONE || list_test_frame.reveal_selected { return 5 }
// The open habit's history, statistics and editor are guide anchors.
if list_test_frame.anchor_history.width <= 0.0 || list_test_frame.first_day.width <= 0.0 { return 6 }
frame.screen_mode = HABITS_SCREEN_HISTORY
frame.view_mode = HABIT_VIEW_CALENDAR
frame.selected = 1
page := ListTestDraw(frame, cast(u64)2)
if page != 0 { return 6 + page }
// A counting habit's calendar asks each day of the month up to today.
if list_test_days < 24 || list_test_bad_day { return 10 }
return 0
}