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:
9 files changed
+893
-18
No files matched your search
+10
-5
@@ -189,11 +189,13 @@ pub(all) struct ClockConfig {
|
||||
mut show_date : Bool
|
||||
mut seconds : Bool
|
||||
mut ampm : Bool
|
||||
/// The clock's calendar flyout (left click), with its week-start and week-number settings.
|
||||
cal : Calendar
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ClockConfig::new(hour12? : Bool = false) -> ClockConfig {
|
||||
{ hour12, show_date: true, seconds: true, ampm: true }
|
||||
{ hour12, show_date: true, seconds: true, ampm: true, cal: Calendar::new() }
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -215,12 +217,15 @@ pub fn ClockConfig::digital_items(self : ClockConfig) -> Array[ConfigEntry] {
|
||||
items.push({ key: "ampm", label: "Show AM/PM", choices: [], value: on_off(self.ampm) })
|
||||
}
|
||||
items.push({ key: "date", label: "Show date", choices: [], value: on_off(self.show_date) })
|
||||
items.append(self.cal.config_items())
|
||||
items
|
||||
}
|
||||
|
||||
///| The binary clock's settings: whether the seconds columns show.
|
||||
pub fn ClockConfig::binary_items(self : ClockConfig) -> Array[ConfigEntry] {
|
||||
[{ key: "seconds", label: "Show seconds", choices: [], value: on_off(self.seconds) }]
|
||||
let items = [{ key: "seconds", label: "Show seconds", choices: [], value: on_off(self.seconds) }]
|
||||
items.append(self.cal.config_items())
|
||||
items
|
||||
}
|
||||
|
||||
///| Apply one setting; true when it changed something. Unknown keys and values are ignored.
|
||||
@@ -242,7 +247,7 @@ pub fn ClockConfig::set(self : ClockConfig, key : String, value : String) -> Boo
|
||||
"date" => flag(self.show_date, fn(b) { self.show_date = b })
|
||||
"ampm" => flag(self.ampm, fn(b) { self.ampm = b })
|
||||
"seconds" => flag(self.seconds, fn(b) { self.seconds = b })
|
||||
_ => false
|
||||
_ => self.cal.set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,7 +281,7 @@ pub let binary_config : ClockConfig = ClockConfig::new()
|
||||
test "12-hour clock shows AM/PM, and it can be switched off" {
|
||||
let c = ClockConfig::new(hour12=true)
|
||||
let items = c.digital_items()
|
||||
assert_eq(items.map(i => i.key), ["format", "ampm", "date"])
|
||||
assert_eq(items.map(i => i.key), ["format", "ampm", "date", "week-start", "week-numbers"])
|
||||
assert_eq(items[1].value, "on")
|
||||
let ops = render_digital(@ui.size(120, 36), test_tokens(), test_time(), hour12=true)
|
||||
match ops[0] {
|
||||
@@ -296,5 +301,5 @@ test "12-hour clock shows AM/PM, and it can be switched off" {
|
||||
}
|
||||
// AM/PM is only offered in 12-hour mode
|
||||
assert_true(c.set("format", "24-hour"))
|
||||
assert_eq(c.digital_items().map(i => i.key), ["format", "date"])
|
||||
assert_eq(c.digital_items().map(i => i.key), ["format", "date", "week-start", "week-numbers"])
|
||||
}
|
||||
Reference in new issue
Block a user