- timefmt.hhmm12 + render_digital(hour12=); compositor panel shows '7:51 PM' (wasm clock component keeps 24h by default) - wp_cursor_shape_v1: server lets clients pick their cursor; nested window forwards the shape to the host. Launcher button/entries show a hand, the search field a text cursor, client windows what the client asked for. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a63f65806d
commit
59ea224d38
8 files changed
+146
-3
No files matched your search
+15
-1
@@ -11,11 +11,16 @@ pub fn render_digital(
|
||||
size : @types.Size,
|
||||
t : @theme.Tokens,
|
||||
now : @types.Datetime,
|
||||
hour12? : Bool = false,
|
||||
) -> Array[@types.DrawOp] {
|
||||
let w = size.w.reinterpret_as_int()
|
||||
let h = size.h.reinterpret_as_int()
|
||||
let fs = t.font_size.reinterpret_as_int()
|
||||
let time = @timefmt.hhmm(now.hour.to_int(), now.minute.to_int())
|
||||
let time = if hour12 {
|
||||
@timefmt.hhmm12(now.hour.to_int(), now.minute.to_int())
|
||||
} else {
|
||||
@timefmt.hhmm(now.hour.to_int(), now.minute.to_int())
|
||||
}
|
||||
let date = @timefmt.date_line(
|
||||
now.weekday.to_int(),
|
||||
now.day.to_int(),
|
||||
@@ -72,6 +77,15 @@ pub fn render_binary(
|
||||
ops
|
||||
}
|
||||
|
||||
///|
|
||||
test "digital clock in 12-hour mode" {
|
||||
let ops = render_digital(@ui.size(120, 36), test_tokens(), test_time(), hour12=true)
|
||||
match ops[0] {
|
||||
Text(t) => assert_eq(t.text, "2:07 PM")
|
||||
_ => fail("expected text")
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn test_tokens() -> @theme.Tokens {
|
||||
let c = @ui.color(10, 20, 30, 255)
|
||||
|
||||
@@ -30,6 +30,13 @@ pub fn hhmm(hour : Int, minute : Int) -> String {
|
||||
pad2(hour) + ":" + pad2(minute)
|
||||
}
|
||||
|
||||
///| 12-hour clock, e.g. 14:07 -> "2:07 PM", 00:05 -> "12:05 AM".
|
||||
pub fn hhmm12(hour : Int, minute : Int) -> String {
|
||||
let h = hour % 12
|
||||
let h = if h == 0 { 12 } else { h }
|
||||
h.to_string() + ":" + pad2(minute) + (if hour >= 12 { " PM" } else { " AM" })
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn hhmmss(hour : Int, minute : Int, second : Int) -> String {
|
||||
hhmm(hour, minute) + ":" + pad2(second)
|
||||
@@ -55,6 +62,11 @@ pub fn bcd_bits(digit : Int, bits : Int) -> Array[Bool] {
|
||||
test "formatting" {
|
||||
assert_eq(hhmm(9, 5), "09:05")
|
||||
assert_eq(hhmmss(23, 59, 7), "23:59:07")
|
||||
assert_eq(hhmm12(14, 7), "2:07 PM")
|
||||
assert_eq(hhmm12(0, 5), "12:05 AM")
|
||||
assert_eq(hhmm12(12, 0), "12:00 PM")
|
||||
assert_eq(hhmm12(23, 59), "11:59 PM")
|
||||
assert_eq(hhmm12(9, 30), "9:30 AM")
|
||||
assert_eq(date_line(2, 24, 11), "Tue 24 Nov")
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user