Module settings in each module's right-click menu, and System settings
CI / test (push) Failing after 15s
CI / test (push) Failing after 15s
- New optional WIT export `chandra:desktop/module-config` (wit/plasmoid.wit): config-items (key,
label, choices, current value; no choices = an on/off switch) and set-config. Hosts look it up
by name, so modules without it (or prebuilt ones like Pulse) load as before.
- Right-click a panel module: "Module settings..." (or a greyed "No module settings"), then
"System settings..." (the settings module, Session tab), then Replace with... and Remove widget.
The "Modules..." row is gone; right-clicking empty panel space offers "System settings..." on the
Panel tab instead. Module settings open in the same menu: on/off rows with a check box, choices
under a heading with the current one ticked; clicking applies at once and the menu stays open.
- Choices are saved per module id in state.edn as :module-config {"clock-digital" {"format"
"12-hour"}} (module_config.mbt; not an owned key, so save_state keeps it) and handed back through
set-config whenever the module is loaded. Other instances of the module follow a change.
- Both hosts: wasmer stub (optional exports 8-10, canonical-ABI decoding in wasm_native.mbt) and
host-wasm (chandra:host/plasmoids config-items/set-config, bound with a separate `configurable`
world so the export stays optional).
- Adopted by the digital clock (Time format 24-hour/12-hour, Show date) and the binary clock (Show
seconds); clock-widget now exports module-config.
- Tests: native menu end-to-end (open, pick 12-hour, heading inert, reload keeps it), state.edn
round trip, EDN unit test, wasmer and host-wasm module-config tests, lib/clock settings test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hjuApkJR4sVRYDpDLy
This commit is contained in:
37 files changed
+1285
-128
No files matched your search
+103
-3
@@ -12,6 +12,7 @@ pub fn render_digital(
|
||||
t : @theme.Tokens,
|
||||
now : @types.Datetime,
|
||||
hour12? : Bool = false,
|
||||
show_date? : Bool = true,
|
||||
) -> Array[@types.DrawOp] {
|
||||
let w = size.w.reinterpret_as_int()
|
||||
let h = size.h.reinterpret_as_int()
|
||||
@@ -21,6 +22,9 @@ pub fn render_digital(
|
||||
} else {
|
||||
@timefmt.hhmm(now.hour.to_int(), now.minute.to_int())
|
||||
}
|
||||
if !show_date {
|
||||
return [@ui.text(w / 2, h / 2, time, fs + 4, t.palette.foreground, align=CENTER, bold=true)]
|
||||
}
|
||||
let date = @timefmt.date_line(
|
||||
now.weekday.to_int(),
|
||||
now.day.to_int(),
|
||||
@@ -43,6 +47,7 @@ pub fn render_binary(
|
||||
size : @types.Size,
|
||||
t : @theme.Tokens,
|
||||
now : @types.Datetime,
|
||||
seconds? : Bool = true,
|
||||
) -> Array[@types.DrawOp] {
|
||||
let w = size.w.reinterpret_as_int()
|
||||
let h = size.h.reinterpret_as_int()
|
||||
@@ -51,14 +56,16 @@ pub fn render_binary(
|
||||
(now.hour.to_int() % 10, 4),
|
||||
(now.minute.to_int() / 10, 3),
|
||||
(now.minute.to_int() % 10, 4),
|
||||
(now.second.to_int() / 10, 3),
|
||||
(now.second.to_int() % 10, 4),
|
||||
]
|
||||
if seconds {
|
||||
digits.push((now.second.to_int() / 10, 3))
|
||||
digits.push((now.second.to_int() % 10, 4))
|
||||
}
|
||||
let ops = []
|
||||
let cols = digits.length()
|
||||
// Columns are grouped HH MM SS with a wider gap between groups.
|
||||
let group_gap = 8
|
||||
let step_x = (w - 2 * group_gap) / cols
|
||||
let step_x = (w - (cols / 2 - 1) * group_gap) / cols
|
||||
let step_y = h / 4
|
||||
let r = (if step_x < step_y { step_x } else { step_y }) / 2 - 1
|
||||
let lit = t.palette.accent
|
||||
@@ -160,3 +167,96 @@ test "binary clock draws one dot per displayed bit" {
|
||||
// 14:07:37 -> 1,4,0,7,3,7 -> popcount 1+1+0+3+2+3
|
||||
assert_eq(lit, 10)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- module settings
|
||||
|
||||
///| One item of a clock's right-click "Module settings" menu (the `module-config` record, minus
|
||||
/// the generated type): key, label, choices (empty: an on/off switch) and the current value.
|
||||
#derive(Eq, Debug)
|
||||
pub(all) struct ConfigEntry {
|
||||
key : String
|
||||
label : String
|
||||
choices : Array[String]
|
||||
value : String
|
||||
}
|
||||
|
||||
///| What the user picked for a clock; each clock module keeps one.
|
||||
pub(all) struct ClockConfig {
|
||||
mut hour12 : Bool
|
||||
mut show_date : Bool
|
||||
mut seconds : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn ClockConfig::new() -> ClockConfig {
|
||||
{ hour12: false, show_date: true, seconds: true }
|
||||
}
|
||||
|
||||
///|
|
||||
fn on_off(b : Bool) -> String {
|
||||
if b { "on" } else { "off" }
|
||||
}
|
||||
|
||||
///| The digital clock's settings: time format and whether the date line shows.
|
||||
pub fn ClockConfig::digital_items(self : ClockConfig) -> Array[ConfigEntry] {
|
||||
[
|
||||
{
|
||||
key: "format",
|
||||
label: "Time format",
|
||||
choices: ["24-hour", "12-hour"],
|
||||
value: if self.hour12 { "12-hour" } else { "24-hour" },
|
||||
},
|
||||
{ key: "date", label: "Show date", choices: [], value: on_off(self.show_date) },
|
||||
]
|
||||
}
|
||||
|
||||
///| 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) }]
|
||||
}
|
||||
|
||||
///| Apply one setting; true when it changed something. Unknown keys and values are ignored.
|
||||
pub fn ClockConfig::set(self : ClockConfig, key : String, value : String) -> Bool {
|
||||
let flag = fn(cur : Bool, set : (Bool) -> Unit) -> Bool {
|
||||
match value {
|
||||
"on" if !cur => { set(true); true }
|
||||
"off" if cur => { set(false); true }
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
match key {
|
||||
"format" =>
|
||||
match value {
|
||||
"12-hour" if !self.hour12 => { self.hour12 = true; true }
|
||||
"24-hour" if self.hour12 => { self.hour12 = false; true }
|
||||
_ => false
|
||||
}
|
||||
"date" => flag(self.show_date, fn(b) { self.show_date = b })
|
||||
"seconds" => flag(self.seconds, fn(b) { self.seconds = b })
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
test "clock settings" {
|
||||
let c = ClockConfig::new()
|
||||
assert_eq(c.digital_items()[0].value, "24-hour")
|
||||
assert_true(c.set("format", "12-hour"))
|
||||
assert_false(c.set("format", "12-hour")) // no change
|
||||
assert_false(c.set("format", "bogus"))
|
||||
assert_eq(c.digital_items()[0].value, "12-hour")
|
||||
assert_true(c.set("date", "off"))
|
||||
assert_eq(c.digital_items()[1].value, "off")
|
||||
assert_false(c.set("nope", "on"))
|
||||
let ops = render_digital(@ui.size(120, 36), test_tokens(), test_time(), show_date=false)
|
||||
assert_eq(ops.length(), 1)
|
||||
assert_true(c.set("seconds", "off"))
|
||||
let bin = render_binary(@ui.size(96, 36), test_tokens(), test_time(), seconds=false)
|
||||
assert_eq(bin.length() < 30, true) // two columns fewer
|
||||
}
|
||||
|
||||
///| The digital clock module's settings (one module instance per wasm instance).
|
||||
pub let digital_config : ClockConfig = ClockConfig::new()
|
||||
|
||||
///| The binary clock module's settings.
|
||||
pub let binary_config : ClockConfig = ClockConfig::new()
|
||||
Reference in new issue
Block a user