Files
breeze/apps/practice/settings_view.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

1249 lines
52 KiB
Ziran

#import, file "figure_view.zi";
// A practice's Customize page: Meditation's duration, extend controls and
// interval bell, a breathing pattern with its custom seconds and minutes,
// Wim Hof's breathing, rounds and session options with a breathing preview,
// the background music with its test and download, and Astral Projection's
// voice narration with its voice and language. The host
// keeps the settings, the music and the narration downloads, and saves each
// change the page asks for.
#import "session"
#import "geometry"
#import "vec"
#import "dpi"
Box :: #import "kryon/box";
Button :: #import "kryon/button";
Dropdown :: #import "kryon/dropdown";
Layout :: #import "kryon/layout";
Modal :: #import "kryon/modal";
Scroll :: #import "kryon/scroll";
SegmentedControl :: #import "kryon/segmented_control";
Shape :: #import "kryon/shape";
Slider :: #import "kryon/slider";
Text :: #import "kryon/text";
TitleBar :: #import "kryon/title_bar";
Toggle :: #import "kryon/toggle";
#import "kryon/system_clipboard"
#import "drawing_props"
#import "semantic"
#import "text_align"
#import "text_measure"
#import "control_props"
#import "toggle_measure"
#import "kryon/tree"
#import, file "../../src/apps/practice_ui_types.zi";
#import, file "../../src/apps/practice_types.zi";
#import, file "../../src/app/exercise_types.zi";
#import, file "../../src/practices/patterns/patterns_rules.zi";
using ButtonTone;
using ButtonEmphasis;
using ExerciseType;
using SemanticKind;
using Text.Wrap;
using TextAlign;
host_api :: #system_library "host_api";
ReadPracticeSettingsHost :: () -> PracticeSettingsFrame #foreign host_api;
WritePracticeSettingsHost :: (frame: PracticeSettingsFrame) #foreign host_api;
ReadPracticeMusicTrackHost :: (index: s32) -> PracticeMusicTrack #foreign host_api;
ReadPracticeNarrationHost :: (index: s32) -> PracticeNarrationChoice #foreign host_api;
ReadPracticeCharacterHost :: (index: s32) -> PracticeCharacterChoice #foreign host_api;
SettingsLocaleHost :: (key: string) -> string #foreign host_api;
settings: PracticeSettingsFrame;
SETTINGS_CONTENT_MAX_WIDTH :: 440
SETTINGS_MUSIC_TRACK_MAX :: 64
SETTINGS_LANGUAGE_MAX :: 32
SETTINGS_TEXT_12 :: 12
// MingCute's regular download_2, delete_2 and close icons (Apache-2.0),
// copied from kryonlabs/mingcute's generated shapes.
NARRATION_DOWNLOAD_ICON :: "S2rr:M20 16V20C20 20.5523 19.5523 21 19 21H5C4.44772 21 4 20.5523 4 20V16M12 3V15M7.75736 11.4143L12 15.6569L16.2426 11.4143"
NARRATION_REMOVE_ICON :: "S2rm:M5 6L5.87554 19.133C5.94558 20.1836 6.81818 21 7.87111 21H16.1289C17.1818 21 18.0544 20.1836 18.1245 19.133L19 6M8 6L8.77208 3.68377C8.90819 3.27543 9.29033 3 9.72076 3H14.2792C14.7097 3 15.0918 3.27543 15.2279 3.68377L16 6M10 11V16M14 11V16M4 6H20"
NARRATION_CANCEL_ICON :: "S2rm:M5.63599 5.63672L18.3639 18.3646M5.63599 18.3647L18.3639 5.63682"
Scale :: (pixels: s32) -> s32 {
return ScalePixels(pixels, settings.scale)
}
Bounds :: (x: s32, y: s32, width: s32, height: s32) -> Rectangle {
return Rectangle.{cast(float32)x, cast(float32)y,
cast(float32)width, cast(float32)height}
}
Locale :: (key: string) -> string {
return SettingsLocaleHost(key)
}
Width :: (text: string, font: s32) -> s32 {
return TextWidth(settings.session, Text.Props.{.text = text, .size = font})
}
ParagraphHeight :: (text: string, width: s32, font: s32, line_gap: s32) -> s32 {
return TextHeight(settings.session, Text.Props.{.text = text, .size = font,
.bounds = Bounds(0, 0, width, 0), .wrap = cast(Text.Wrap)TextWrapAuto,
.line_gap = line_gap})
}
// A label at its natural size from x, y.
Label :: (text: string, x: s32, y: s32) {
Text.Draw(settings.session, Text.Props.{.bounds = Bounds(x, y, 0, 0), .text = text,
.wrap = cast(Text.Wrap)TextWrapNone})
}
Choice :: (bounds: Rectangle, label: string, chosen: bool) -> bool {
return Button.Draw(settings.session, Button.Props.{.bounds = bounds, .label = label,
.tone = cast(ButtonTone)(ifx chosen then ButtonToneAccent else ButtonToneNeutral),
.emphasis = cast(ButtonEmphasis)(ifx chosen then ButtonEmphasisFilled else ButtonEmphasisSoft)}) != 0
}
Ask :: (action: s32, value: s32) {
settings.action = action
settings.value = value
}
// ---- Meditation -----------------------------------------------------------------------
MEDITATION_PRESETS :: 5
DurationHeight :: (width: s32) -> s32 {
columns: s32 = ifx width >= Scale(520) then 3 else 2
rows := (MEDITATION_PRESETS + 1 + columns - 1) / columns
return Scale(30) + rows * Scale(56) + (rows - 1) * Scale(8) + Scale(108) + Scale(84) +
Scale(18) + Scale(112)
}
// The duration presets and custom minutes, the extend controls, and the
// interval bell.
Duration :: (x: s32, width: s32, y: *s32) {
labels: [6]string = .[Locale("duration_5m"), Locale("duration_15m"), Locale("duration_30m"),
Locale("duration_1h"), Locale("duration_2h"), Locale("meditation_duration_custom")]
gap := Scale(8)
button_height := Scale(48)
Label(Locale("meditation_duration_setting"), x, y.*)
y.* += Scale(30)
columns: s32 = ifx width >= Scale(520) then 3 else 2
button_width := (width - gap * (columns - 1)) / columns
for index: cast(s32)0..MEDITATION_PRESETS {
if Choice(Bounds(x + (index % columns) * (button_width + gap),
y.* + (index / columns) * (button_height + gap), button_width, button_height),
labels[index], index == settings.duration_mode) {
Ask(PRACTICE_SETTINGS_DURATION, index)
}
}
y.* += ((MEDITATION_PRESETS + 1 + columns - 1) / columns) * (button_height + gap) + Scale(8)
custom_y := y.*
custom: Vec(u8)
BuilderPrint(*custom, "%: % min", Locale("meditation_custom_minutes"), settings.custom_minutes)
Label(BuilderFinish(custom), x, custom_y)
adjust_labels: [4]string = .["-5", "-1", "+1", "+5"]
adjust_values: [4]s32 = .[-5, -1, 1, 5]
adjust_width := Scale(50)
adjust_x := x + (width - (adjust_width * 4 + gap * 3)) / 2
for index: cast(s32)0..3 {
if Button.Draw(settings.session, Button.Props.{
.bounds = Bounds(adjust_x + index * (adjust_width + gap), custom_y + Scale(34),
adjust_width, button_height),
.label = adjust_labels[index], .tone = cast(ButtonTone)ButtonToneNeutral,
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
Ask(PRACTICE_SETTINGS_CUSTOM, adjust_values[index])
}
}
y.* += Scale(108)
Label(Locale("meditation_extend_controls_label"), x, y.*)
extend := Toggle.Props.{.value = settings.extend_controls, .off_label = Locale("toggle_off"),
.on_label = Locale("toggle_on")}
// The toggle takes the room its labels need.
size := ToggleSize(settings.session, extend)
extend.bounds = Rectangle.{cast(float32)x, cast(float32)(y.* + Scale(26)), size.x,
ifx size.y > cast(float32)Scale(30) then size.y else cast(float32)Scale(30)}
toggled := Toggle.Draw(settings.session, extend)
if toggled.changed {
Ask(PRACTICE_SETTINGS_EXTEND, ifx toggled.value then 1 else 0)
}
y.* += Scale(84)
// The interval bell: a soft bell every n minutes.
Label(Locale("meditation_interval_bell_label"), x, y.*)
bell_labels: [7]string = .[Locale("meditation_interval_bell_off"), "1", "2", "5", "10", "15", "30"]
bell_values: [7]s32 = .[0, 1, 2, 5, 10, 15, 30]
// Minutes that are not offered show Off as chosen.
bell_chosen: s32 = 0
for index: cast(s32)0..6 {
if settings.bell_minutes == bell_values[index] {
bell_chosen = index
}
}
bell_columns: s32 = ifx width >= Scale(460) then 7 else 4
bell_width := (width - gap * (bell_columns - 1)) / bell_columns
if bell_width > Scale(72) {
bell_width = Scale(72)
}
for index: cast(s32)0..6 {
if Choice(Bounds(x + (index % bell_columns) * (bell_width + gap),
y.* + Scale(26) + (index / bell_columns) * (button_height + gap), bell_width,
button_height), bell_labels[index], index == bell_chosen) {
Ask(PRACTICE_SETTINGS_BELL, bell_values[index])
}
}
bell_rows := (7 + bell_columns - 1) / bell_columns
y.* += Scale(26) + bell_rows * button_height + (bell_rows - 1) * gap + Scale(12)
}
// ---- Breathing patterns ---------------------------------------------------------------
PatternSeconds :: (phase: s32) -> s32 {
if phase == PATTERNS_PHASE_HOLD_IN {
return settings.pattern_hold_in
}
if phase == PATTERNS_PHASE_EXHALE {
return settings.pattern_exhale
}
if phase == PATTERNS_PHASE_HOLD_OUT {
return settings.pattern_hold_out
}
return settings.pattern_inhale
}
PatternHeight :: () -> s32 {
button_height := Scale(48)
gap := Scale(8)
height := Scale(24) + Scale(30) + PATTERNS_PRESET_COUNT * (button_height + gap) + Scale(10)
if settings.pattern == PATTERNS_PRESET_CUSTOM {
height += Scale(30) + 4 * (button_height + gap) + Scale(6)
}
return height + Scale(30) + button_height + Scale(10)
}
// The patterns with their seconds, the custom pattern's seconds for each
// phase, and how many minutes to breathe.
Pattern :: (x: s32, width: s32, y: *s32) {
button_height := Scale(48)
gap := Scale(8)
Label(Locale("patterns_preset_label"), x, y.*)
y.* += Scale(30)
for preset: cast(s32)0..PATTERNS_PRESET_COUNT - 1 {
seconds: [4]s32
for phase: cast(s32)0..3 {
seconds[phase] = patterns_preset_ratio(preset, phase)
if preset == PATTERNS_PRESET_CUSTOM {
seconds[phase] = PatternSeconds(phase)
}
}
label: Vec(u8)
BuilderPrint(*label, "% %-%-%-%", Locale(patterns_preset_label_key(preset)),
seconds[0], seconds[1], seconds[2], seconds[3])
if Choice(Bounds(x, y.* + preset * (button_height + gap), width, button_height),
BuilderFinish(label), settings.pattern == preset) {
Ask(PRACTICE_SETTINGS_PATTERN, preset)
}
}
y.* += PATTERNS_PRESET_COUNT * (button_height + gap) + Scale(10)
if settings.pattern == PATTERNS_PRESET_CUSTOM {
Label(Locale("patterns_custom_label"), x, y.*)
y.* += Scale(30)
phases: [4]string = .[Locale("patterns_phase_inhale"), Locale("patterns_phase_hold_in"),
Locale("patterns_phase_exhale"), Locale("patterns_phase_hold_out")]
step_width := Scale(46)
for phase: cast(s32)0..3 {
Label(phases[phase], x, y.*)
if Button.Draw(settings.session, Button.Props.{
.bounds = Bounds(x + width - step_width * 2 - gap, y.*, step_width, button_height),
.label = "-5", .tone = cast(ButtonTone)ButtonToneNeutral,
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
Ask(PRACTICE_SETTINGS_PATTERN_LESS, phase)
}
if Button.Draw(settings.session, Button.Props.{
.bounds = Bounds(x + width - step_width, y.*, step_width, button_height),
.label = "+5", .tone = cast(ButtonTone)ButtonToneNeutral,
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
Ask(PRACTICE_SETTINGS_PATTERN_MORE, phase)
}
value: Vec(u8)
BuilderPrint(*value, "% s", PatternSeconds(phase))
value_text := BuilderFinish(value)
Label(value_text, x + width - step_width * 2 - gap - Width(value_text, settings.font) -
Scale(8), y.*)
y.* += button_height + gap
}
y.* += Scale(6)
}
Label(Locale("patterns_duration_label"), x, y.*)
y.* += Scale(30)
minutes: [5]s32 = .[0, 3, 5, 10, 20]
minutes_width := (width - gap * 4) / 5
for index: cast(s32)0..4 {
label: Vec(u8)
if minutes[index] == 0 {
BuilderPrint(*label, "%", Locale("patterns_duration_open"))
} else {
BuilderPrint(*label, "%", minutes[index])
}
if Choice(Bounds(x + index * (minutes_width + gap), y.*, minutes_width, button_height),
BuilderFinish(label), settings.pattern_minutes == minutes[index]) {
Ask(PRACTICE_SETTINGS_PATTERN_MINUTES, minutes[index])
}
}
y.* += button_height + Scale(10)
}
// ---- Wim Hof -----------------------------------------------------------------------------
// A setting's label and value over its slider; its value when it changed.
SliderRow :: (id: s32, x: s32, width: s32, y: *s32, row_height: s32, label: string,
minimum: s32, maximum: s32, value: s32, suffix: string) -> Slider.SliderDiscreteStep {
number: Vec(u8)
BuilderPrint(*number, "%", value)
BuilderPrint(*number, "%", suffix)
Text.Draw(settings.session, Text.Props.{.text = label, .size = settings.small_font,
.wrap = cast(Text.Wrap)TextWrapNone, .bounds = Bounds(x, y.*, width - Scale(64), Scale(20))})
Text.Draw(settings.session, Text.Props.{.text = BuilderFinish(number), .size = settings.small_font,
.wrap = cast(Text.Wrap)TextWrapNone, .align = cast(TextAlign)TextAlignEnd,
.bounds = Bounds(x + width - Scale(64), y.*, Scale(64), Scale(20))})
step := Slider.DiscreteSlider(settings.session, Slider.DiscreteSliderProps.{.id = id,
.bounds = Bounds(x, y.* + Scale(20), width, Scale(36)), .semantic_label = label,
.value = value, .min = minimum, .max = maximum})
y.* += row_height
return step
}
// The card the breathing, rounds and options each sit on, its corners
// rounding off 8% of its shorter side.
Card :: (x: s32, y: s32, width: s32, height: s32) {
shorter := ifx height < width then height else width
Box.Draw(settings.session, Box.Props.{.bounds = Bounds(x, y, width, height),
.fill = settings.surface_color, .border = settings.border_color,
.radius = 0.08 * cast(float32)shorter * 0.5})
}
// The breathing preview, sized for its room as the session's circle is and
// breathing at this share of its range.
BreathPreview :: (center_x: s32, center_y: s32, width: s32, height: s32, share: float32) {
span := ifx height > 0 && height < width then height else width
largest := span / 2
if largest < Scale(60) {
largest = Scale(60)
}
if largest > Scale(120) {
largest = Scale(120)
}
smallest := largest / 2
if smallest < Scale(24) {
smallest = Scale(24)
}
if smallest > largest - Scale(10) {
smallest = largest - Scale(10)
}
if smallest < 8 {
smallest = 8
}
if largest < smallest + 8 {
largest = smallest + 8
}
radius := (cast(float32)smallest + share * cast(float32)(largest - smallest)) * 0.72
if radius <= 0.0 {
return
}
center := Vector2.{cast(float32)center_x, cast(float32)center_y}
Shape.Circle(settings.session, Shape.CircleProps.{.center = center, .radius = radius, .fill = settings.accent_color})
Shape.Ring(settings.session, Shape.RingProps.{.center = center, .inner_radius = radius - 0.75,
.outer_radius = radius + 0.75, .start_angle = 0.0, .end_angle = 360.0,
.color = settings.text_color})
}
// A setting's label with its Off and On toggle at the row's end.
ToggleRow :: (id: s32, label: string, value: bool, x: s32, width: s32, y: s32,
row_height: s32) -> Toggle.ToggleValueResult {
Label(label, x, y)
toggle := Toggle.Props.{.id = id, .value = value, .off_label = Locale("toggle_off"),
.on_label = Locale("toggle_on")}
size := ToggleSize(settings.session, toggle)
toggle_height := ifx size.y > cast(float32)Scale(30) then cast(s32)size.y else Scale(30)
toggle.bounds = Bounds(x + width - cast(s32)size.x, y + (row_height - toggle_height) / 2,
cast(s32)size.x, toggle_height)
return Toggle.Draw(settings.session, toggle)
}
WhmBreathHeight :: () -> s32 {
height := Scale(88) + Scale(154) + Scale(78) + Scale(72)
if settings.whm_progressive {
height += Scale(66)
}
return height
}
WhmRoundsHeight :: () -> s32 {
return Scale(82) * 3 + Scale(24)
}
WhmOptionsHeight :: () -> s32 {
return Scale(22) * 2 + Scale(88) * 2 + Scale(26 + 48)
}
WhmHeight :: (width: s32) -> s32 {
return Scale(16) + WhmBreathHeight() + Scale(16) + WhmRoundsHeight() + Scale(16) +
WhmOptionsHeight() + Scale(40) + MusicHeight(width) + Scale(12) + Scale(48) + Scale(24) +
settings.bottom + Scale(24)
}
// The breath animation with its preview, the speed, and speeding up through
// the round with the start speed's editor.
WhmBreath :: (x: s32, width: s32, y: *s32) {
height := WhmBreathHeight()
Card(x, y.*, width, height)
padding := Scale(22)
inner_x := x + padding
inner_width := width - padding * 2
inner_y := y.* + padding
Label(Locale("breath_animation_label"), inner_x, inner_y)
animations: [2]Dropdown.Option = .[Dropdown.Option.{.label = Locale("breath_animation_linear")},
Dropdown.Option.{.label = Locale("breath_animation_in_out")}]
animation := Dropdown.Draw(settings.session, Dropdown.Props.{.id = 104,
.bounds = Bounds(inner_x, inner_y + Scale(26), inner_width, Scale(48)),
.selected_index = settings.whm_animation}, animations[:])
if animation.changed {
Ask(PRACTICE_SETTINGS_WHM_ANIMATION, animation.selected_index)
}
inner_y += Scale(82)
preview_height := Scale(144)
halo := settings.link_color
halo.a = cast(u8)(255.0 * 0.16)
clear := settings.canvas_color
clear.a = 0
Shape.Circle(settings.session, Shape.CircleProps.{
.center = Vector2.{cast(float32)(inner_x + inner_width / 2),
cast(float32)(inner_y + preview_height / 2)},
.radius = cast(float32)Scale(72), .fill = halo, .edge = clear, .has_edge = true})
BreathPreview(inner_x + inner_width / 2, inner_y + preview_height / 2, inner_width,
preview_height, settings.whm_preview)
inner_y += preview_height + Scale(20)
speed := SliderRow(1, inner_x, inner_width, *inner_y, Scale(78), Locale("speed_label"),
settings.whm_speed_min, settings.whm_speed_max, settings.whm_speed, "")
if speed.changed {
Ask(PRACTICE_SETTINGS_WHM_SPEED, speed.value)
}
progressive := ToggleRow(1101, Locale("progressive_speed_label"), settings.whm_progressive,
inner_x, inner_width, inner_y, Scale(58))
if progressive.changed {
Ask(PRACTICE_SETTINGS_WHM_PROGRESSIVE, ifx progressive.value then 1 else 0)
}
inner_y += Scale(58)
if settings.whm_progressive {
if FittedButton(Locale("modify_start_speed_button"), inner_x, inner_y, inner_width, false) {
Ask(PRACTICE_SETTINGS_WHM_START_EDITOR, 0)
}
}
y.* += height + Scale(16)
}
// The rounds, the breaths in each and the pause after one.
WhmRounds :: (x: s32, width: s32, y: *s32) {
height := WhmRoundsHeight()
Card(x, y.*, width, height)
padding := Scale(22)
inner_x := x + padding
inner_width := width - padding * 2
inner_y := y.* + padding
rounds := SliderRow(2, inner_x, inner_width, *inner_y, Scale(82), Locale("max_rounds_label"),
1, settings.whm_rounds_max, settings.whm_rounds, "")
if rounds.changed {
Ask(PRACTICE_SETTINGS_WHM_ROUNDS, rounds.value)
}
breaths := SliderRow(3, inner_x, inner_width, *inner_y, Scale(82), Locale("max_breaths_label"),
settings.whm_breaths_min, settings.whm_breaths_max, settings.whm_breaths, "")
if breaths.changed {
Ask(PRACTICE_SETTINGS_WHM_BREATHS, breaths.value)
}
pause := SliderRow(4, inner_x, inner_width, *inner_y, Scale(56), Locale("pause_after_round_label"),
settings.whm_pause_min, settings.whm_pause_max, settings.whm_pause, "s")
if pause.changed {
Ask(PRACTICE_SETTINGS_WHM_PAUSE, pause.value)
}
y.* += height + Scale(16)
}
// Double tap to breathe, the session controls, and the hold reminder.
WhmOptions :: (x: s32, width: s32, y: *s32) {
height := WhmOptionsHeight()
Card(x, y.*, width, height)
padding := Scale(22)
inner_x := x + padding
inner_width := width - padding * 2
inner_y := y.* + padding
double_tap := ToggleRow(1201, Locale("double_tap_to_breathe_label"), settings.whm_double_tap,
inner_x, inner_width, inner_y, Scale(60))
if double_tap.changed {
Ask(PRACTICE_SETTINGS_WHM_DOUBLE_TAP, ifx double_tap.value then 1 else 0)
}
inner_y += Scale(88)
controls := ToggleRow(1202, Locale("advanced_session_controls_label"), settings.whm_controls,
inner_x, inner_width, inner_y, Scale(60))
if controls.changed {
Ask(PRACTICE_SETTINGS_WHM_CONTROLS, ifx controls.value then 1 else 0)
}
inner_y += Scale(88)
Label(Locale("whm_hold_reminder_label"), inner_x, inner_y)
seconds: [3]s32 = .[0, 30, 60]
reminders: [3]Dropdown.Option = .[Dropdown.Option.{.label = Locale("whm_hold_reminder_off")},
Dropdown.Option.{.label = Locale("whm_hold_reminder_30s")},
Dropdown.Option.{.label = Locale("whm_hold_reminder_60s")}]
chosen: s32 = ifx settings.whm_reminder == 30 then 1 else ifx settings.whm_reminder == 60 then 2 else 0
reminder := Dropdown.Draw(settings.session, Dropdown.Props.{.id = 1203,
.bounds = Bounds(inner_x, inner_y + Scale(26), inner_width, Scale(48)),
.selected_index = chosen}, reminders[:])
if reminder.changed && reminder.selected_index >= 0 && reminder.selected_index < 3 {
Ask(PRACTICE_SETTINGS_WHM_REMINDER, seconds[reminder.selected_index])
}
y.* += height + Scale(16)
}
Whm :: (x: s32, width: s32, y: *s32) {
y.* += Scale(16)
WhmBreath(x, width, y)
WhmRounds(x, width, y)
WhmOptions(x, width, y)
y.* += Scale(24)
Music(x, width, y)
y.* += Scale(12)
label := Locale("reset_to_defaults_label")
reset_width := Width(label, settings.font) + Scale(24)
if reset_width > width {
reset_width = width
}
if Button.Draw(settings.session, Button.Props.{.bounds = Bounds(x + width - reset_width, y.*,
reset_width, Scale(48)), .label = label, .tone = cast(ButtonTone)ButtonToneNeutral,
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
Ask(PRACTICE_SETTINGS_WHM_RESET, 0)
}
y.* += Scale(48) + Scale(24)
}
// The start speed's editor over the page: its own preview and slider, up to
// the speed the round reaches.
WhmStartSpeedEditor :: () {
frame := Modal.Draw(settings.session, Modal.Props.{.key = Layout.KeyHash("whm/start_speed"),
.title = Locale("progressive_start_speed_editor_title"), .width = Scale(340),
.height = Scale(360), .scale = settings.scale, .has_right_action = true,
.right_label = Locale("close_button")})
if frame.dismissed || frame.right_clicked {
Ask(PRACTICE_SETTINGS_WHM_EDITOR_CLOSE, 0)
return
}
if !frame.opened {
return
}
content := frame.layout.content
x := cast(s32)content.x
y := cast(s32)content.y
width := cast(s32)content.width
BreathPreview(x + width / 2, y + Scale(90), width, Scale(180), settings.whm_editor_preview)
slider_y := y + Scale(206)
start := SliderRow(12, x, width, *slider_y, Scale(56), Locale("progressive_start_speed_label"),
settings.whm_speed_min, settings.whm_speed, settings.whm_start_speed, "")
if start.changed {
Ask(PRACTICE_SETTINGS_WHM_START_SPEED, start.value)
}
unused End(settings.session)
}
// ---- Background music ----------------------------------------------------------------
AttributionHeight :: (width: s32) -> s32 {
if width <= 0 {
return 0
}
return ParagraphHeight(Locale("meditation_music_attribution"), width, SETTINGS_TEXT_12, 0)
}
MusicHeight :: (width: s32) -> s32 {
height := Scale(90)
if settings.music_selection == 0 {
return height
}
if settings.music_installed {
height += Scale(60)
}
if settings.music_built_in && (!settings.music_installed || settings.music_redownload) {
height += Scale(60)
}
if settings.music_show_status {
height += ifx settings.music_downloading then Scale(50) else Scale(34)
}
return height + AttributionHeight(width) + Scale(10)
}
// The download's bar, bevelled like a well with the accent filling it.
MusicProgress :: (x: s32, y: s32, width: s32) {
if width <= 0 {
return
}
bar_height := Scale(10)
fill: s32 = 0
if settings.music_total > 0 {
fill = cast(s32)(settings.music_bytes * cast(s64)width / settings.music_total)
}
if fill < 0 {
fill = 0
}
if fill > width {
fill = width
}
background := settings.canvas_color
Box.Draw(settings.session, Box.Props.{.bounds = Bounds(x, y, width, bar_height),
.fill = DarkenColor(background, 28)})
dark := DarkenColor(background, 55)
light := LightenColor(background, 35)
left := cast(float32)x
top := cast(float32)y
right := cast(float32)(x + width - 1)
bottom := cast(float32)(y + bar_height - 1)
Shape.Draw(settings.session, Shape.Props.{.start = Vector2.{left, top}, .end = Vector2.{right, top},
.color = light})
Shape.Draw(settings.session, Shape.Props.{.start = Vector2.{left, top}, .end = Vector2.{left, bottom},
.color = light})
Shape.Draw(settings.session, Shape.Props.{.start = Vector2.{left, bottom}, .end = Vector2.{right, bottom},
.color = dark})
Shape.Draw(settings.session, Shape.Props.{.start = Vector2.{right, top}, .end = Vector2.{right, bottom},
.color = dark})
if fill > 0 {
inner := fill - Scale(4)
if inner < Scale(2) {
inner = Scale(2)
}
Box.Draw(settings.session, Box.Props.{.bounds = Bounds(x + Scale(2), y + Scale(2), inner,
bar_height - Scale(4)), .fill = settings.accent_color})
}
}
FittedButton :: (label: string, x: s32, y: s32, width: s32, accent: bool) -> bool {
button_width := Width(label, settings.font) + Scale(24)
if button_width > width {
button_width = width
}
return Button.Draw(settings.session, Button.Props.{.bounds = Bounds(x, y, button_width, Scale(48)),
.label = label,
.tone = cast(ButtonTone)(ifx accent then ButtonToneAccent else ButtonToneNeutral),
.emphasis = cast(ButtonEmphasis)(ifx accent then ButtonEmphasisFilled else ButtonEmphasisSoft)}) != 0
}
// The track that plays during the practice, with Test once it is on this
// device, Download for a built-in track that is not, and how a download goes.
Music :: (x: s32, width: s32, y: *s32) {
Label(Locale(ifx settings.practice == EXERCISE_SUN_SALUTATION then
"sun_salutation_music_track_label" else "practice_background_music_label"), x, y.*)
count := settings.music_count
if count > SETTINGS_MUSIC_TRACK_MAX {
count = SETTINGS_MUSIC_TRACK_MAX
}
options: [SETTINGS_MUSIC_TRACK_MAX + 1]Dropdown.Option
options[0] = Dropdown.Option.{.label = Locale("audio_music_none_option")}
for index: cast(s32)0..count - 1 {
options[index + 1] = Dropdown.Option.{.label = ReadPracticeMusicTrackHost(index).label}
}
selection := settings.music_selection
if selection < 0 || selection > count {
selection = 0
}
picked := Dropdown.Draw(settings.session, Dropdown.Props.{.id = 451 + settings.practice,
.bounds = Bounds(x, y.* + Scale(26), width, Scale(48)), .selected_index = selection},
options[:count + 1])
if picked.changed {
Ask(PRACTICE_SETTINGS_MUSIC, picked.selected_index)
}
y.* += Scale(90)
if selection == 0 {
return
}
if settings.music_installed {
if FittedButton(Locale(ifx settings.music_playing then "meditation_music_stop_test_button"
else "meditation_music_test_button"), x, y.*, width, false) {
Ask(PRACTICE_SETTINGS_MUSIC_TEST, 0)
}
y.* += Scale(60)
}
// The download only brings the built-in tracks.
if settings.music_built_in && (!settings.music_installed || settings.music_redownload) {
if FittedButton(Locale(ifx settings.music_installed then "meditation_music_redownload_button"
else "meditation_music_download_button"), x, y.*, width, true) {
Ask(PRACTICE_SETTINGS_MUSIC_DOWNLOAD, 0)
}
y.* += Scale(60)
}
if settings.music_show_status {
Label(settings.music_status, x, y.*)
if settings.music_downloading {
y.* += Scale(28)
MusicProgress(x, y.*, width)
y.* += Scale(22)
} else {
y.* += Scale(34)
}
}
height := AttributionHeight(width)
Text.Draw(settings.session, Text.Props.{.bounds = Bounds(x, y.*, width, height),
.text = Locale("meditation_music_attribution"), .size = SETTINGS_TEXT_12,
.wrap = cast(Text.Wrap)TextWrapAuto})
y.* += height + Scale(10)
}
// ---- Voice narration ------------------------------------------------------------------
NarrationStatusHeight :: (width: s32) -> s32 {
if settings.narration_status.count == 0 {
return 0
}
return ParagraphHeight(settings.narration_status, width, settings.font, Scale(3)) + Scale(12)
}
NarrationHeight :: (width: s32) -> s32 {
height := Scale(36 + 56)
if settings.narration_enabled {
height += Scale(44 + 16) + NarrationStatusHeight(width)
if settings.narration_voices {
height += Scale(42 + 12)
}
}
return height
}
// The languages the voice is recorded in. Choosing one makes narration speak
// it, downloading it if needed; a row's icon downloads, stops or removes it.
NarrationLanguages :: (x: s32, width: s32, y: *s32) {
count := settings.narration_count
if count > SETTINGS_LANGUAGE_MAX {
count = SETTINGS_LANGUAGE_MAX
}
if count <= 0 {
return
}
options: [SETTINGS_LANGUAGE_MAX]Dropdown.Option
for index: cast(s32)0..count - 1 {
language := ReadPracticeNarrationHost(index)
state := language.state
options[index] = Dropdown.Option.{.key = cast(u64)(language.rank + 1), .label = language.label,
.action_shape = ifx state == 2 then NARRATION_REMOVE_ICON else
ifx state == 1 then NARRATION_CANCEL_ICON else NARRATION_DOWNLOAD_ICON,
.action_label = Locale(ifx state == 2 then "practice_download_remove" else
ifx state == 1 then "cancel_button" else "practice_narration_download")}
}
picked := Dropdown.Draw(settings.session, Dropdown.Props.{
.key = Layout.KeyHash("inbe/practice/customize/narration-language") + cast(u64)settings.practice,
.bounds = Bounds(x, y.*, width, Scale(44)), .selected_index = settings.narration_selected,
.placeholder = Locale("language_label")}, options[0:count])
if picked.action_index >= 0 && picked.action_index < count {
Ask(PRACTICE_SETTINGS_LANGUAGE_ACTION, picked.action_index)
}
if picked.changed && picked.selected_index >= 0 && picked.selected_index < count {
Ask(PRACTICE_SETTINGS_LANGUAGE, picked.selected_index)
}
y.* += Scale(44 + 16)
if settings.narration_status.count > 0 {
height := ParagraphHeight(settings.narration_status, width, settings.font, Scale(3))
Text.Draw(settings.session, Text.Props.{.bounds = Bounds(x, y.*, width, height),
.text = settings.narration_status, .size = settings.font,
.wrap = cast(Text.Wrap)TextWrapAuto})
y.* += height + Scale(12)
}
}
// Narration on or off, with the voice when it is recorded in two, and its
// language.
Narration :: (x: s32, width: s32, y: *s32) {
Text.Draw(settings.session, Text.Props.{.bounds = Bounds(x, y.*, width, Scale(28)),
.text = Locale("voice_narration_label")})
y.* += Scale(36)
toggled := Toggle.Draw(settings.session, Toggle.Props.{.id = 15422, .bounds = Bounds(x, y.*, width, Scale(44)),
.value = settings.narration_enabled, .off_label = Locale("toggle_off"),
.on_label = Locale("toggle_on")})
if toggled.changed {
Ask(PRACTICE_SETTINGS_NARRATION, ifx toggled.value then 1 else 0)
}
y.* += Scale(56)
if !settings.narration_enabled {
return
}
if settings.narration_voices {
voices: [2]SegmentedControl.SegmentOption = .[SegmentedControl.SegmentOption.{.label = Locale("practice_voice_female")},
SegmentedControl.SegmentOption.{.label = Locale("practice_voice_male")}]
voice := SegmentedControl.Draw(settings.session, SegmentedControl.Props.{
.key = Layout.KeyHash("inbe/practice/customize/voice") + cast(u64)settings.practice,
.bounds = Bounds(x, y.*, width, Scale(42)), .height = Scale(42),
.selected_index = ifx settings.narration_male then 1 else 0, .has_selection = true},
voices[:])
if voice.changed {
Ask(PRACTICE_SETTINGS_VOICE, voice.selected_index)
}
y.* += Scale(42 + 12)
}
NarrationLanguages(x, width, y)
}
// The existing movement settings, carried by the independently updated page.
MovementVolume :: (x: s32, width: s32, y: *s32, cue: bool) {
value := ifx cue then settings.cue_volume else settings.music_volume
out: Vec(u8)
BuilderPrint(*out, "%", value)
slider := Slider.DiscreteSlider(settings.session, Slider.DiscreteSliderProps.{
.id = ifx cue then 15421 else ifx settings.practice == EXERCISE_SUN_SALUTATION then 614 else 15420,
.bounds = Bounds(x, y.*, width, Scale(56)),
.label = Locale(ifx cue then "cue_volume_label" else "music_volume_label"),
.value_text = BuilderFinish(out), .value = value, .min = 0, .max = 100})
if slider.changed {
Ask(ifx cue then PRACTICE_SETTINGS_CUE_VOLUME else PRACTICE_SETTINGS_MUSIC_VOLUME, slider.value)
}
y.* += Scale(74)
}
SunHeight :: (width: s32) -> s32 {
return Scale(76 + 24 + 32 + 74 * 3 + 24 + 86 + 32 + 74 + 12) +
ParagraphHeight(Locale("sun_salutation_tempo_preview_hint"), width, settings.small_font, Scale(3)) +
MusicHeight(width) + NarrationHeight(width) + settings.bottom + Scale(24)
}
SunSetting :: (id: s32, key: string, value: s32, minimum: s32, maximum: s32,
action: s32, x: s32, width: s32, y: *s32) {
out: Vec(u8)
BuilderPrint(*out, "%", value)
shown := BuilderFinish(out)
if id != 610 {
shown = CountText(Locale("sun_salutation_seconds_per_breath"), value)
}
slider := Slider.DiscreteSlider(settings.session, Slider.DiscreteSliderProps.{.id = id,
.bounds = Bounds(x, y.*, width, Scale(56)), .label = Locale(key), .value_text = shown,
.value = value, .min = minimum, .max = maximum})
if slider.changed {
Ask(action, slider.value)
}
y.* += Scale(74)
}
Sun :: (x: s32, width: s32, y: *s32) {
fill := settings.canvas_color
fill.r = ifx fill.r > 6 then fill.r - cast(u8)6 else cast(u8)0
fill.g = ifx fill.g > 6 then fill.g - cast(u8)6 else cast(u8)0
fill.b = ifx fill.b > 6 then fill.b - cast(u8)6 else cast(u8)0
Box.Draw(settings.session, Box.Props.{.bounds = Bounds(x, y.*, width, Scale(76)), .fill = fill})
Text.Draw(settings.session, Text.Props.{.bounds = Bounds(x + Scale(14), y.* + Scale(10), 0, 0),
.text = Locale("sun_salutation_duration_label"), .size = settings.small_font})
// The locale uses minutes and seconds, including a padded seconds field.
Text.Draw(settings.session, Text.Props.{.bounds = Bounds(x + Scale(14), y.* + Scale(35), 0, 0),
.text = SunDuration(), .size = settings.font + Scale(3)})
y.* += Scale(100)
Label(Locale("sun_salutation_timing_label"), x, y.*)
y.* += Scale(32)
SunSetting(610, "sun_salutation_repetitions_label", settings.sun_repetitions, 2, 12,
PRACTICE_SETTINGS_SUN_REPETITIONS, x, width, y)
SunSetting(611, "sun_salutation_start_speed_label", settings.sun_start_seconds,
settings.sun_seconds_min, settings.sun_seconds_max, PRACTICE_SETTINGS_SUN_START, x, width, y)
SunSetting(612, "sun_salutation_end_speed_label", settings.sun_end_seconds,
settings.sun_seconds_min, settings.sun_start_seconds, PRACTICE_SETTINGS_SUN_END, x, width, y)
hint := Locale("sun_salutation_tempo_preview_hint")
height := ParagraphHeight(hint, width, settings.small_font, Scale(3))
Text.Draw(settings.session, Text.Props.{.text = hint, .bounds = Bounds(x, y.*, width, height),
.size = settings.small_font})
y.* += height + Scale(24)
Label(Locale("sun_salutation_character_label"), x, y.*)
options: [2]Dropdown.Option = .[Dropdown.Option.{.label = Locale("sun_salutation_character_bun_woman")},
Dropdown.Option.{.label = Locale("sun_salutation_character_short_hair_man")}]
picked := Dropdown.Draw(settings.session, Dropdown.Props.{.id = 613,
.bounds = Bounds(x, y.* + Scale(26), width, Scale(44)), .selected_index = settings.sun_character}, options[:])
if picked.changed {
Ask(PRACTICE_SETTINGS_SUN_CHARACTER, picked.selected_index)
}
y.* += Scale(86)
Label(Locale("settings_tab_audio"), x, y.*)
y.* += Scale(32)
MovementVolume(x, width, y, false)
Music(x, width, y)
y.* += Scale(12)
Narration(x, width, y)
}
// Preserve the locale's existing two-number duration template, including %02d.
SunDuration :: () -> string {
template := Locale("sun_salutation_duration_value")
out: Vec(u8)
at: s64 = 0
part: s32 = 0
while at < template.count {
if at + 3 < template.count && template[at:at + 4] == "%02d" {
value := settings.sun_duration % 60
if value < 10 {
BuilderPrint(*out, "0")
}
BuilderPrint(*out, "%", value)
at += 4
part += 1
} else if at + 1 < template.count && template[at:at + 2] == "%d" {
BuilderPrint(*out, "%", ifx part == 0 then settings.sun_duration / 60 else settings.sun_duration % 60)
part += 1
at += 2
} else {
BuilderPrint(*out, "%", template[at:at + 1])
at += 1
}
}
return BuilderFinish(out)
}
TaiAudioHeight :: (width: s32) -> s32 {
return MusicHeight(width) + Scale(12 + 74 * 2) + NarrationHeight(width) +
ParagraphHeight(Locale("tai_chi_narration_hint"), width, settings.font, Scale(3))
}
TaiAudio :: (x: s32, width: s32, y: s32) {
Music(x, width, *y)
y += Scale(12)
MovementVolume(x, width, *y, false)
MovementVolume(x, width, *y, true)
Narration(x, width, *y)
text := Locale("tai_chi_narration_hint")
Text.Draw(settings.session, Text.Props.{.text = text, .bounds = Bounds(x, y, width,
ParagraphHeight(text, width, settings.font, Scale(3))), .size = settings.font, .disabled = true})
}
TaiCharacters :: (bounds: Rectangle) {
gap := Scale(16)
card_w := (cast(s32)bounds.width - gap) / 2
card_h := Scale(280)
for character: cast(s32)0..settings.tai_character_count - 1 {
title := ReadPracticeCharacterHost(character).label
key := Layout.KeyHash("inbe/tai_chi/character-card") + cast(u64)character * cast(u64)4096
card := Bounds(cast(s32)bounds.x + character % 2 * (card_w + gap),
cast(s32)bounds.y + character / 2 * (card_h + gap), card_w, card_h)
if Button.Draw(settings.session, Button.Props.{.key = key, .bounds = card,
.selected = settings.tai_character == character, .tone = cast(ButtonTone)ButtonToneNeutral,
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
Ask(PRACTICE_SETTINGS_TAI_CHARACTER, character)
}
PracticeFigure(PracticeFigureRequest.{.practice = EXERCISE_TAI_CHI, .preview = true,
.index = settings.tai_preview_item, .character = character,
.bounds = Rectangle.{card.x + cast(float32)Scale(14), card.y + cast(float32)Scale(14),
card.width - cast(float32)Scale(28), card.height - cast(float32)Scale(94)},
.key = key + cast(u64)1000, .alt_text = title})
Text.Draw(settings.session, Text.Props.{.text = title, .size = settings.font,
.bounds = Rectangle.{card.x + cast(float32)Scale(14), card.y + card.height - cast(float32)Scale(76),
card.width - cast(float32)Scale(28), cast(float32)Scale(44)}})
}
}
TaiCustomize :: () {
width := settings.view_width - Scale(32)
if width > Scale(940) {
width = Scale(940)
}
height := settings.view_height - Scale(48)
if height > Scale(740) {
height = Scale(740)
}
frame := Modal.Draw(settings.session, Modal.Props.{.key = Layout.KeyHash("inbe/tai_chi/modal"),
.title = Locale("practice_configure_button"), .width = width, .height = height, .scale = settings.scale,
.title_at_start = true, .strong_title = true, .has_right_action = true, .right_label = Locale("close_button")})
if frame.dismissed || frame.right_clicked {
Ask(PRACTICE_SETTINGS_BACK, 0)
return
}
if !frame.opened {
return
}
bounds := frame.layout.content
gap := Scale(24)
wide := bounds.width >= cast(float32)Scale(700)
audio_w := cast(s32)bounds.width - Scale(10)
character_w := audio_w
if wide {
character_w = (audio_w - gap) / 2
audio_w -= character_w + gap
}
audio_h := TaiAudioHeight(audio_w)
rows := (settings.tai_character_count + 1) / 2
if rows < 1 {
rows = 1
}
// Section title's existing scale-aware height.
title := Locale("tai_chi_character_label")
title_font := settings.font + Scale(2)
title_h := ParagraphHeight(title, character_w, title_font, Scale(3))
character_h := title_h + Scale(12) + rows * Scale(280) + (rows - 1) * Scale(16)
content_h := audio_h + gap + character_h
if wide {
content_h = ifx audio_h > character_h then audio_h else character_h
}
scrolled := Scroll.Draw(settings.session, Scroll.Props.{.key = Layout.KeyHash("inbe/tai_chi/customize/scroll"),
.bounds = bounds, .content_height = content_h + Scale(16), .scroll_offset = settings.scroll})
settings.scroll = scrolled.scroll_offset
if scrolled.opened {
x := cast(s32)scrolled.content.x
y := cast(s32)scrolled.content.y
character_y := ifx wide then y else y + audio_h + gap
audio_x := ifx wide then x + character_w + gap else x
TaiAudio(audio_x, audio_w, y)
Text.Draw(settings.session, Text.Props.{.text = title, .size = title_font,
.bounds = Bounds(x, character_y, character_w, title_h)})
TaiCharacters(Bounds(x, character_y + title_h + Scale(12), character_w, character_h - title_h - Scale(12)))
unused End(settings.session)
}
unused End(settings.session)
}
// ---- The page ---------------------------------------------------------------------------
ContentHeight :: (width: s32) -> s32 {
if settings.practice == EXERCISE_SUN_SALUTATION {
return SunHeight(width)
}
if settings.practice == EXERCISE_ASTRAL_PROJECTION {
return Scale(320) + NarrationHeight(width)
}
if settings.practice == EXERCISE_PATTERNS {
return PatternHeight() + MusicHeight(width) + Scale(24)
}
if settings.practice == EXERCISE_WIM_HOF {
return WhmHeight(width)
}
return DurationHeight(width) + MusicHeight(width) + settings.bottom + Scale(24)
}
ScrollKey :: () -> u64 {
if settings.practice == EXERCISE_SUN_SALUTATION {
return Layout.KeyHash("inbe/practices/sun_salutation/sun_salutation_practice/scroll/1")
}
if settings.practice == EXERCISE_ASTRAL_PROJECTION {
return Layout.KeyHash("astral/customize/scroll")
}
if settings.practice == EXERCISE_PATTERNS {
return Layout.KeyHash("inbe/practices/patterns/patterns_practice/scroll/1")
}
if settings.practice == EXERCISE_WIM_HOF {
return Layout.KeyHash("inbe/practices/whm/whm_config/scroll/1")
}
return Layout.KeyHash("inbe/practices/meditation/meditation_config/scroll/1")
}
Page :: (x: s32, width: s32, y: s32) {
if settings.practice == EXERCISE_SUN_SALUTATION {
Sun(x, width, *y)
return
}
if settings.practice == EXERCISE_ASTRAL_PROJECTION {
Music(x, width, *y)
y += Scale(12)
Narration(x, width, *y)
return
}
if settings.practice == EXERCISE_PATTERNS {
Pattern(x, width, *y)
Music(x, width, *y)
return
}
if settings.practice == EXERCISE_WIM_HOF {
Whm(x, width, *y)
return
}
Duration(x, width, *y)
Music(x, width, *y)
}
Settings :: () {
if settings.practice == EXERCISE_TAI_CHI {
TaiCustomize()
return
}
options: [1]Dropdown.Option
bar := TitleBar.Draw(settings.session, TitleBar.Props.{.title = Locale("practice_configure_button"),
.height = settings.title_height, .has_leading_action = true,
.leading_label = Locale("back_button")}, options[0:0])
if bar.clicked_leading {
Ask(PRACTICE_SETTINGS_BACK, 0)
return
}
padding := Layout.PageSidePaddingFor(settings.view_width)
if settings.practice == EXERCISE_ASTRAL_PROJECTION {
padding = Scale(16)
}
max_width := Scale(SETTINGS_CONTENT_MAX_WIDTH)
available := settings.view_width - padding * 2
if max_width > available {
max_width = available
}
if settings.practice == EXERCISE_WIM_HOF {
// Wim Hof's cards take a phone's whole width.
if max_width < available && settings.view_width <= Scale(520) {
max_width = available
}
if max_width < Scale(240) {
max_width = available
}
} else if max_width < Scale(320) {
max_width = Scale(320)
}
x := padding
width := settings.view_width - padding * 2
if width > max_width {
x += (width - max_width) / 2
width = max_width
}
scrolled := Scroll.Draw(settings.session, Scroll.Props.{.key = ScrollKey(),
.bounds = Bounds(0, settings.scroll_y, settings.view_width, settings.scroll_height),
.content_height = ContentHeight(width), .scroll_offset = settings.scroll})
settings.scroll = scrolled.scroll_offset
if scrolled.opened {
Page(x, width, cast(s32)scrolled.content.y)
unused End(settings.session)
}
if settings.practice == EXERCISE_WIM_HOF && settings.whm_editor {
WhmStartSpeedEditor()
}
}
// Session audio stays in one modal; choices apply without leaving the practice.
SessionAudio :: () {
width := settings.view_width - Scale(32)
if width > Scale(560) {
width = Scale(560)
}
height := settings.view_height - Scale(32)
if height > Scale(680) {
height = Scale(680)
}
frame := Modal.Draw(settings.session, Modal.Props.{
.key = Layout.KeyHash("inbe/practice/session-audio"),
.title = Locale("practice_background_music_label"),
.width = width, .height = height, .scale = settings.scale,
.title_at_start = true, .strong_title = true,
.has_right_action = true, .right_label = Locale("close_button")})
if frame.dismissed || frame.right_clicked {
Ask(PRACTICE_SETTINGS_BACK, 0)
return
}
if !frame.opened {
return
}
bounds := frame.layout.content
count := settings.music_count
if count < 0 {
count = 0
} else if count > SETTINGS_MUSIC_TRACK_MAX {
count = SETTINGS_MUSIC_TRACK_MAX
}
content_width := cast(s32)bounds.width
status_height: s32 = 0
if settings.music_show_status && settings.music_status.count > 0 {
status_height = ParagraphHeight(settings.music_status, content_width, settings.font, 0) + Scale(12)
}
attribution_height := AttributionHeight(content_width)
content_height := Scale(74 * 2 + 34 + 52 * (count + 1) + 16)
if settings.music_selection > 0 {
content_height += status_height + attribution_height + Scale(12)
if settings.music_built_in && !settings.music_installed {
content_height += Scale(56)
}
if settings.music_downloading {
content_height += Scale(28)
}
}
scrolled := Scroll.Draw(settings.session, Scroll.Props.{
.key = Layout.KeyHash("inbe/practice/session-audio/scroll"),
.bounds = bounds, .content_height = content_height,
.scroll_offset = settings.scroll})
settings.scroll = scrolled.scroll_offset
if scrolled.opened {
x := cast(s32)scrolled.content.x
y := cast(s32)scrolled.content.y
MovementVolume(x, content_width, *y, true)
MovementVolume(x, content_width, *y, false)
Label(Locale("practice_background_music_label"), x, y)
y += Scale(34)
for index: cast(s32)0..count {
label := Locale("audio_music_none_option")
if index > 0 {
label = ReadPracticeMusicTrackHost(index - 1).label
}
selected := settings.music_selection == index
if Button.Draw(settings.session, Button.Props.{
.key = Layout.KeyHash("inbe/practice/session-audio/track") + cast(u64)index,
.bounds = Bounds(x, y, content_width, Scale(44)),
.label = label, .selected = selected, .fit_content = true,
.tone = cast(ButtonTone)(ifx selected then ButtonToneAccent else ButtonToneNeutral),
.emphasis = cast(ButtonEmphasis)(ifx selected then ButtonEmphasisFilled else ButtonEmphasisSoft)}) != 0 {
Ask(PRACTICE_SETTINGS_MUSIC, index)
}
y += Scale(52)
}
if settings.music_selection > 0 {
if settings.music_built_in && !settings.music_installed {
if Button.Draw(settings.session, Button.Props.{
.key = Layout.KeyHash("inbe/practice/session-audio/download"),
.bounds = Bounds(x, y, content_width, Scale(44)),
.label = Locale("meditation_music_download_button"),
.disabled = settings.music_downloading,
.tone = cast(ButtonTone)ButtonToneAccent,
.emphasis = cast(ButtonEmphasis)ButtonEmphasisSoft}) != 0 {
Ask(PRACTICE_SETTINGS_MUSIC_DOWNLOAD, 0)
}
y += Scale(56)
}
if status_height > 0 {
Text.Draw(settings.session, Text.Props.{
.bounds = Bounds(x, y, content_width, status_height - Scale(12)),
.text = settings.music_status, .wrap = cast(Text.Wrap)TextWrapAuto})
y += status_height
}
if settings.music_downloading {
MusicProgress(x, y, content_width)
y += Scale(28)
}
Text.Draw(settings.session, Text.Props.{
.bounds = Bounds(x, y, content_width, attribution_height),
.text = Locale("meditation_music_attribution"),
.size = SETTINGS_TEXT_12, .wrap = cast(Text.Wrap)TextWrapAuto})
}
unused End(settings.session)
}
unused End(settings.session)
}
PracticeSessionAudioView :: (message: PracticeMessage) -> PracticeMessage {
settings = ReadPracticeSettingsHost()
settings.action = PRACTICE_SETTINGS_NONE
settings.value = 0
SessionAudio()
WritePracticeSettingsHost(settings)
message.succeeded = true
return message
}
PracticeSettingsView :: (message: PracticeMessage) -> PracticeMessage {
settings = ReadPracticeSettingsHost()
settings.action = PRACTICE_SETTINGS_NONE
settings.value = 0
Settings()
WritePracticeSettingsHost(settings)
message.succeeded = true
return message
}
CountText :: (template: string, value: s32) -> string {
out: Vec(u8)
at: s64 = 0
replaced := false
while at < template.count {
if !replaced && at + 1 < template.count && template[at:at + 2] == "%d" {
BuilderPrint(*out, "%", value)
replaced = true
at += 2
} else {
BuilderPrint(*out, "%", template[at:at + 1])
at += 1
}
}
if !replaced {
BuilderPrint(*out, " %", value)
}
return BuilderFinish(out)
}