///| The clocks' calendar flyout driven through the shell: a left click on the clock slides it /// out of the panel, its buttons change the month, and Escape, a click elsewhere or another click /// on the clock slide it away. Needs the modules: run scripts/build-modules.sh. ///| fn cal_texts(comp : @host.ChandraCompositor, id : String) -> Array[String] { comp.shell.slot_popup_texts(comp.shell.slot_of(id)).map(t => t.0) } ///| Wait out the slide, drawing frames like the main loop does while one runs. fn finish_slide(comp : @host.ChandraCompositor) -> Unit { let mut n = 0 while comp.has_timed_work() && n < 200 { @sys.sleep_ms(5) ignore(comp.compose_frame()) n = n + 1 } } ///| test "left click on the clock slides out a calendar; Escape, a click elsewhere or the clock close it" { let comp = new_comp("calendar") let slot = comp.shell.slot_of("clock-digital") let clock = rect_of(comp, "clock-digital") assert_true(clock.w > 0) assert_false(comp.has_timed_work()) // an idle desktop doesn't animate click_module(comp, "clock-digital", 1U) let pr = comp.shell.slot_popup_rect(slot) assert_true(pr.w > 0) assert_true(pr.y + pr.h <= clock.y) // above the panel assert_true(pr.x + pr.w <= 1280) // It is sliding: frames keep coming until it sits in place. assert_true(comp.has_timed_work()) assert_true(comp.shell.slot_slide_offset(slot) > 0) @sys.sleep_ms(60) ignore(@sys.write_file_bytes("_build/calendar_sliding.png", @renderer.encode_png(comp.compose_frame()))) finish_slide(comp) assert_false(comp.has_timed_work()) assert_eq(comp.shell.slot_slide_offset(slot), 0) ignore(@sys.write_file_bytes("_build/calendar_open.png", @renderer.encode_png(comp.compose_frame()))) // The header, the month and the buttons. let month = cal_texts(comp, "clock-digital")[2] // e.g. "November 2026" assert_true(month.contains(" 20")) assert_true(cal_texts(comp, "clock-digital").contains("Today")) // The buttons sit right-aligned in the month row: next, Today, previous. let row_y = pr.y + 80 + 14 click_at(comp, pr.x + pr.w - 12 - 14, row_y, 10U) // next month assert_true(cal_texts(comp, "clock-digital")[2] != month) click_at(comp, pr.x + pr.w - 12 - 28 - 4 - 28, row_y, 20U) // Today assert_eq(cal_texts(comp, "clock-digital")[2], month) assert_false(comp.has_timed_work()) // changing month doesn't slide // Escape slides it away; input passes through at once. comp.handle_input(@nested.InputEvent::Key(1U, true), 30U) ignore(comp.compose_frame()) assert_eq(comp.shell.slot_popup_rect(slot).w, 0) assert_true(comp.has_timed_work()) finish_slide(comp) assert_false(comp.has_timed_work()) // Clicking the clock again toggles it. click_module(comp, "clock-digital", 40U) assert_true(comp.shell.slot_popup_rect(slot).w > 0) click_module(comp, "clock-digital", 50U) assert_eq(comp.shell.slot_popup_rect(slot).w, 0) // A click on the desktop closes it too. click_module(comp, "clock-digital", 60U) assert_true(comp.shell.slot_popup_rect(slot).w > 0) click_at(comp, 600, 200, 70U) assert_eq(comp.shell.slot_popup_rect(slot).w, 0) finish_slide(comp) assert_false(comp.has_timed_work()) } ///| test "the calendar's week start and week numbers are the clock's module settings" { let comp = new_comp("calendar-cfg") let slot = comp.shell.slot_of("clock-digital") comp.shell.set_module_setting(slot, "week-start", "Monday") comp.shell.set_module_setting(slot, "week-numbers", "on") assert_eq(comp.shell.module_setting("clock-digital", "week-start"), Some("Monday")) click_module(comp, "clock-digital", 1U) comp.shell.dark_mode = false comp.apply_theme() finish_slide(comp) ignore(@sys.write_file_bytes("_build/calendar_light.png", @renderer.encode_png(comp.compose_frame()))) let texts = cal_texts(comp, "clock-digital") assert_true(texts.contains("Wk")) let names = texts.filter(s => s == "Mo" || s == "Su") assert_eq(names, ["Mo", "Su"]) // The binary clock has the calendar too. assert_true(comp.shell.unload_slot(slot)) assert_true(comp.shell.load_module("clock-binary")) ignore(comp.compose_frame()) click_module(comp, "clock-binary", 10U) assert_true(comp.shell.slot_popup_rect(comp.shell.slot_of("clock-binary")).w > 0) assert_true(cal_texts(comp, "clock-binary").contains("Today")) }