Clock calendar: left click slides out a month calendar
CI / test (push) Failing after 17s

Left-clicking the Digital Clock (or the Binary Clock) opens a calendar flyout that
slides up out of the panel; Escape, a click elsewhere or another click on the clock
slides it back in.

- lib/clock/calendar.mbt: month maths (leap years, weekday, ISO week numbers), a
  six-week grid, the flyout's state, drawing and hit testing. Header with the time
  (in the clock's own 12/24-hour format) and the long date; month and year with
  previous / Today / next buttons; weekday names; today circled in the accent colour,
  other months' days muted. Keys: Escape closes, t today, p/n previous/next month.
- Module settings (right click): "Week starts on" Sunday/Monday and "Show week
  numbers", for both clocks (saved per module like the other settings).
- compositor/shell/slide.mbt: popups of the clock modules slide (200 ms, ease-out in,
  ease-in out), clipped to their final place so they come out of the panel edge; the
  popup takes input at its final place at once. A popup below the panel would slide
  the other way. Theme comes from the module's tokens, so dark/light follow.
- CPU: has_timed_work() is true only while a slide runs, so the main loop only keeps
  the frame pace for those 200 ms; an open calendar redraws only when its minute or
  month changes.
- Tests: lib/clock calendar tests (wasm), compositor/host/calendar_test.mbt (open,
  slide finishes, month buttons, Escape / click outside / toggle, settings, binary
  clock). Host failures are the 5 known input_test ones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjahaLE5XqnCWoEwKv
This commit is contained in:
Claude committed 2026-11-25 20:47:06 +00:00
1 parent 10659e7655
commit a215dd6bf7
9 files changed
+893 -18

No files matched your search

+8 -4
View File
@@ -179,6 +179,12 @@ pub(all) struct Widget {
mut popup_rect : @scene.Rect
mut popup_ops : Array[@types.DrawOp]
mut popup_hot : Bool
/// Popup slide (slide.mbt): when the running slide began (monotonic ms, 0: none), whether it
/// slides in or out, and while sliding out, where the popup was and what it showed.
mut slide_t0 : UInt64
mut slide_in : Bool
mut ghost_rect : @scene.Rect
mut ghost_ops : Array[@types.DrawOp]
}
///| A wasm module file found on the module path.
@@ -941,12 +947,10 @@ pub fn DesktopShell::render(
}
}
}
// Popups sit above the panel, left-aligned with their widget.
// Popups sit above the panel, left-aligned with their widget; some slide in and out.
for wd in self.widgets {
self.refresh_popup(wd)
if wd.popup_rect.w > 0 {
translate(wd.popup_ops, wd.popup_rect.x, wd.popup_rect.y, panel_ops)
}
self.draw_popup(wd, panel_ops)
}
if self.menu_open {
self.render_menu(w, tokens, panel_ops)
+147
View File
@@ -0,0 +1,147 @@
///| Popups that slide out of the panel when they open and back into it when they close (the
/// clocks' calendar). The popup keeps its final place for input from the first frame; only the
/// drawing moves, clipped to that place, so it looks like it comes out of the panel's edge.
/// Frames are only drawn at the frame pace while a slide runs (`animating`, which the
/// compositor's main loop checks); otherwise nothing is redrawn for it.
///| Modules whose popups slide.
let slide_modules : Array[String] = ["clock-digital", "clock-binary"]
///| How long a slide takes, in ms.
pub let slide_ms : UInt64 = 200
///|
fn Widget::slides(self : Widget) -> Bool {
slide_modules.contains(self.module_id)
}
///| How far into the running slide we are, 0.0 .. 1.0.
fn Widget::slide_progress(self : Widget, now : UInt64) -> Double {
if self.slide_t0 == 0 || now <= self.slide_t0 {
return 0.0
}
let p = (now - self.slide_t0).to_double() / slide_ms.to_double()
if p > 1.0 {
1.0
} else {
p
}
}
///| Start (or turn around) a slide, `slide_in` or out. A slide that is turned around midway
/// carries on from where it got to.
fn Widget::start_slide(self : Widget, slide_in : Bool) -> Unit {
let now = @sys.monotonic_ms()
let left = if self.slide_t0 != 0 {
let p = self.slide_progress(now)
if p < 1.0 {
((1.0 - p) * slide_ms.to_double()).to_uint64()
} else {
0UL
}
} else {
0UL
}
// Turning around at progress p starts the other way at progress 1 - p.
self.slide_t0 = if now > left { now - left } else { 1UL }
self.slide_in = slide_in
}
///| The widget's popup just opened.
fn DesktopShell::slide_in(self : DesktopShell, w : Widget) -> Unit {
ignore(self)
if w.slides() {
w.ghost_ops = []
w.ghost_rect = { x: 0, y: 0, w: 0, h: 0 }
w.start_slide(true)
}
}
///| The widget's popup just closed: it was at `rect` showing `ops`; slide that back in.
fn DesktopShell::slide_out(
self : DesktopShell,
w : Widget,
rect : @scene.Rect,
ops : Array[@types.DrawOp],
) -> Unit {
ignore(self)
if w.slides() {
w.ghost_rect = rect
w.ghost_ops = ops
w.start_slide(false)
}
}
///| True while a popup is sliding: the compositor then keeps drawing frames.
pub fn DesktopShell::animating(self : DesktopShell) -> Bool {
self.widgets.iter().any(w => w.slide_t0 != 0)
}
///| How far (pixels) a popup of height `h` is pushed back into the panel at slide progress `p`:
/// sliding in eases out (fast, then settling), sliding out eases in.
pub fn slide_offset(h : Int, p : Double, slide_in : Bool) -> Int {
let shown = if slide_in {
let q = 1.0 - p
1.0 - q * q * q
} else {
1.0 - p * p
}
((1.0 - shown) * h.to_double()).to_int()
}
///| Draw `w`'s popup (or the one sliding away) into `out`.
fn DesktopShell::draw_popup(self : DesktopShell, w : Widget, out : Array[@scene.DrawOp]) -> Unit {
let (rect, ops) = if w.popup_rect.w > 0 {
(w.popup_rect, w.popup_ops)
} else {
(w.ghost_rect, w.ghost_ops)
}
if rect.w <= 0 {
w.slide_t0 = 0
return
}
if w.slide_t0 == 0 {
if w.popup_rect.w > 0 {
translate(ops, rect.x, rect.y, out)
}
return
}
let p = w.slide_progress(@sys.monotonic_ms())
if p >= 1.0 {
// Done: drawn in place (or gone).
w.slide_t0 = 0
w.ghost_ops = []
w.ghost_rect = { x: 0, y: 0, w: 0, h: 0 }
if w.popup_rect.w > 0 {
translate(ops, rect.x, rect.y, out)
}
return
}
// A popup above the panel slides down into it; one below a top panel slides up.
let dir = if rect.y < self.panel_rect.y { 1 } else { -1 }
let dy = dir * slide_offset(rect.h, p, w.slide_in)
out.push(@scene.DrawOp::PushClip(rect))
translate(ops, rect.x, rect.y + dy, out)
out.push(@scene.DrawOp::PopClip)
}
///| The popup's drawn vertical offset from its place right now (0 when not sliding); for tests.
pub fn DesktopShell::slot_slide_offset(self : DesktopShell, slot : String) -> Int {
match self.widget_by_slot(slot) {
Some(w) if w.slide_t0 != 0 => {
let rect = if w.popup_rect.w > 0 { w.popup_rect } else { w.ghost_rect }
slide_offset(rect.h, w.slide_progress(@sys.monotonic_ms()), w.slide_in)
}
_ => 0
}
}
///|
test "slide offsets run from the panel to the popup's place and back" {
assert_eq(slide_offset(300, 0.0, true), 300)
assert_eq(slide_offset(300, 1.0, true), 0)
assert_true(slide_offset(300, 0.5, true) < 150) // eases out: most of the way after half the time
assert_eq(slide_offset(300, 0.0, false), 0)
assert_eq(slide_offset(300, 1.0, false), 300)
assert_true(slide_offset(300, 0.5, false) < 150) // eases in
}
+13
View File
@@ -309,6 +309,10 @@ pub fn DesktopShell::load_path(self : DesktopShell, path : String) -> Widget? {
popup_rect: { x: 0, y: 0, w: 0, h: 0 },
popup_ops: [],
popup_hot: false,
slide_t0: 0,
slide_in: false,
ghost_rect: { x: 0, y: 0, w: 0, h: 0 },
ghost_ops: [],
}
self.next_slot = self.next_slot + 1
self.apply_module_cfg(w)
@@ -695,8 +699,14 @@ fn DesktopShell::refresh_popup(self : DesktopShell, w : Widget) -> Unit {
if self.widget_by_slot(w.slot) is None {
return
}
let was_open = w.popup_rect.w > 0
let old_rect = w.popup_rect
let old_ops = w.popup_ops
match w.pl.popup() {
None => {
if was_open {
self.slide_out(w, old_rect, old_ops)
}
w.popup_rect = { x: 0, y: 0, w: 0, h: 0 }
w.popup_ops = []
w.popup_hot = false
@@ -705,6 +715,9 @@ fn DesktopShell::refresh_popup(self : DesktopShell, w : Widget) -> Unit {
let (px, py) = @panel.popup_position(self.screen_w, self.screen_h - self.panel_h, w.rect.x, ps.w, ps.h, 6)
w.popup_rect = { x: px, y: py, w: ps.w, h: ps.h }
w.popup_ops = ps.ops
if !was_open {
self.slide_in(w)
}
}
}
}