// Practices draws its Customize pages: the bundled package lays out // Meditation's settings, a breathing pattern's, Wim Hof's with its preview // and start speed editor, the music and the narration from the frame the host // gives it, reads each track and language through the host, and gives back // the one change asked for. #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/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; settings_test_frame: PracticeSettingsFrame; settings_test_codec: WidgetPracticeSettingsFrameCodec; settings_test_track_codec: WidgetPracticeMusicTrackCodec; settings_test_language_codec: WidgetPracticeNarrationChoiceCodec; settings_test_character_codec: WidgetPracticeCharacterChoiceCodec; settings_test_writes: s32; settings_test_figures: s32; settings_test_characters: s32; settings_test_tracks: s32; settings_test_languages: s32; SettingsTestAssets :: (path: string) -> bool { return path.count == 0 } SettingsTestCall :: (context: *void, module: *u8, function: *u8, arguments: *HostValue, count: s32, result: *HostValue) -> s32 { if TextFromCString(module) == "figure_view" && TextFromCString(function) == "DrawPracticeFigureHost" && count == 1 && WidgetValidPracticeFigureRequest(arguments[0]) { settings_test_figures += 1 return 1 } if TextFromCString(module) != "settings_view" { return WidgetHostCall(context, module, function, arguments, count, result) } name := TextFromCString(function) if name == "ReadPracticeSettingsHost" && count == 0 { result.* = WidgetEncodePracticeSettingsFrame(settings_test_frame, *settings_test_codec) return 1 } if name == "WritePracticeSettingsHost" && count == 1 && WidgetValidPracticeSettingsFrame(arguments[0]) { settings_test_writes += 1 settings_test_frame = WidgetDecodePracticeSettingsFrame(arguments[0], *settings_test_codec) return 1 } if name == "ReadPracticeMusicTrackHost" && count == 1 { index := cast(s32)arguments[0].integer if index < 0 || index >= settings_test_frame.music_count { return 0 } settings_test_tracks += 1 result.* = WidgetEncodePracticeMusicTrack(PracticeMusicTrack.{.label = "Deep Meditation"}, *settings_test_track_codec) return 1 } if name == "ReadPracticeNarrationHost" && count == 1 { index := cast(s32)arguments[0].integer if index < 0 || index >= settings_test_frame.narration_count { return 0 } settings_test_languages += 1 result.* = WidgetEncodePracticeNarrationChoice(PracticeNarrationChoice.{.label = "English", .state = 2, .rank = index}, *settings_test_language_codec) return 1 } if name == "ReadPracticeCharacterHost" && count == 1 { settings_test_characters += 1 result.* = WidgetEncodePracticeCharacterChoice(PracticeCharacterChoice.{.label = "Jade woman"}, *settings_test_character_codec) return 1 } if name == "SettingsLocaleHost" && count == 1 { text := "Customize" result.* = HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"), .data = HostTextData(text), .length = cast(usize)text.count} return 1 } return 0 } SettingsTestDraw :: (frame: PracticeSettingsFrame, frame_id: u64) -> s32 { session := SessionOpen() BeginFrame(session, frame_id, Rectangle.{0.0, 0.0, 411.0, 900.0}) frame.session = session settings_test_frame = frame settings_test_writes = 0 settings_test_figures = 0 settings_test_characters = 0 settings_test_tracks = 0 settings_test_languages = 0 WidgetHostBegin(session, SettingsTestAssets) AppsUiBegin(SettingsTestCall, null) drawn := PracticeRun(PracticeMessage.{.action = PRACTICE_SETTINGS_VIEW}) AppsUiEnd() WidgetHostEnd() painted := PendingPaintCount(session) unused EndFrame(session) unused SessionClose(session) if !drawn.succeeded { return 1 } if settings_test_writes != 1 { return 2 } if painted == 0 { return 3 } return 0 } // Draws Meditation's page with a track downloading, then Astral // Projection's with narration in two voices; returns 0 when the package // drew both through the host and asked for nothing. CheckPracticeSettings :: () -> s32 { frame := PracticeSettingsFrame.{.scale = 1.0, .view_width = 411, .view_height = 900, .font = 16, .small_font = 14, .title_height = 48, .scroll_y = 66, .scroll_height = 834, .canvas_color = Color.{.r = 245, .g = 248, .b = 246, .a = 255}, .accent_color = Color.{.r = 120, .g = 200, .b = 160, .a = 255}, .practice = EXERCISE_MEDITATION, .duration_mode = 1, .custom_minutes = 20, .bell_minutes = 5, .music = true, .music_selection = 1, .music_count = 3, .music_built_in = true, .music_show_status = true, .music_downloading = true, .music_bytes = 40, .music_total = 100, .music_status = "Downloading 40%"} meditation := SettingsTestDraw(frame, cast(u64)1) if meditation != 0 { return meditation } if settings_test_tracks != 3 || settings_test_frame.action != PRACTICE_SETTINGS_NONE { return 4 } frame.practice = EXERCISE_ASTRAL_PROJECTION frame.music_selection = 0 frame.narration = true frame.narration_enabled = true frame.narration_voices = true frame.narration_count = 2 frame.narration_selected = 0 frame.narration_status = "Downloading English…" astral := SettingsTestDraw(frame, cast(u64)2) if astral != 0 { return 4 + astral } if settings_test_languages != 2 || settings_test_frame.action != PRACTICE_SETTINGS_NONE { return 8 } frame.narration = false frame.practice = EXERCISE_PATTERNS frame.pattern = 4 frame.pattern_inhale = 4 frame.pattern_hold_in = 2 frame.pattern_exhale = 6 frame.pattern_minutes = 5 patterns := SettingsTestDraw(frame, cast(u64)3) if patterns != 0 { return 8 + patterns } if settings_test_frame.action != PRACTICE_SETTINGS_NONE { return 12 } frame.practice = EXERCISE_WIM_HOF frame.whm_speed = 6 frame.whm_speed_min = 1 frame.whm_speed_max = 8 frame.whm_rounds = 3 frame.whm_rounds_max = 12 frame.whm_breaths = 30 frame.whm_breaths_min = 15 frame.whm_breaths_max = 80 frame.whm_pause_max = 30 frame.whm_progressive = true frame.whm_start_speed = 3 frame.whm_reminder = 30 frame.whm_preview = 0.5 frame.whm_editor = true frame.whm_editor_preview = 0.25 frame.surface_color = Color.{.r = 255, .g = 255, .b = 255, .a = 255} frame.border_color = Color.{.r = 220, .g = 224, .b = 222, .a = 255} frame.link_color = Color.{.r = 40, .g = 120, .b = 90, .a = 255} frame.text_color = Color.{.r = 20, .g = 24, .b = 22, .a = 255} whm := SettingsTestDraw(frame, cast(u64)4) if whm != 0 { return 12 + whm } if settings_test_frame.action != PRACTICE_SETTINGS_NONE { return 16 } frame.practice = EXERCISE_SUN_SALUTATION frame.sun_repetitions = 4 frame.sun_start_seconds = 6 frame.sun_end_seconds = 3 frame.sun_seconds_min = 1 frame.sun_seconds_max = 20 frame.sun_duration = 240 frame.whm_editor = false frame.narration = true sun := SettingsTestDraw(frame, cast(u64)5) if sun != 0 { return 16 + sun } if settings_test_frame.action != PRACTICE_SETTINGS_NONE { return 20 } frame.practice = EXERCISE_TAI_CHI frame.tai_character_count = 4 frame.tai_preview_item = 0 tai := SettingsTestDraw(frame, cast(u64)6) if tai != 0 { return 20 + tai } if settings_test_figures != 4 || settings_test_characters != 4 || settings_test_frame.action != PRACTICE_SETTINGS_NONE { return 24 } return 0 }