summaryrefslogtreecommitdiff
path: root/crates/wipfel/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-28 08:42:30 +0100
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2026-10-28 08:42:30 +0100
commitaab6af1601fa4cdb9b351987220f32de062d4b2c (patch)
treee5d2b4b6af7e5d8fd8d19717786ed0f29b619b0f /crates/wipfel/src
parentd57f022243850b532239ae08dd75717f55415fbf (diff)
web: follow system light/dark preference
All colors moved into CSS custom properties on :root (dark default) with a prefers-color-scheme: light override block. The two canvas- drawn surfaces follow too: the viewport now clears transparent so the CSS canvas background shows through, and the compass strip reads its colors from the same variables via a new bridge::css_var helper. theme-color metas (dark + light variants) tint mobile browser chrome to match.
Diffstat (limited to 'crates/wipfel/src')
-rw-r--r--crates/wipfel/src/bridge.rs12
-rw-r--r--crates/wipfel/src/canvas_view.rs7
-rw-r--r--crates/wipfel/src/compass.rs16
3 files changed, 24 insertions, 11 deletions
diff --git a/crates/wipfel/src/bridge.rs b/crates/wipfel/src/bridge.rs
index 6dbba93..0f252c1 100644
--- a/crates/wipfel/src/bridge.rs
+++ b/crates/wipfel/src/bridge.rs
@@ -67,3 +67,15 @@ pub fn ctx2d(canvas: &HtmlCanvasElement) -> Option<CanvasRenderingContext2d> {
.flatten()
.and_then(|c| c.dyn_into::<CanvasRenderingContext2d>().ok())
}
+
+/// Read a CSS custom property from :root (follows the active
+/// prefers-color-scheme), with a fallback when unavailable.
+pub fn css_var(name: &str, fallback: &str) -> String {
+ window()
+ .document()
+ .and_then(|d| window().get_computed_style(&d.document_element()?).ok().flatten())
+ .and_then(|s| s.get_property_value(name).ok())
+ .map(|v| v.trim().to_string())
+ .filter(|v| !v.is_empty())
+ .unwrap_or_else(|| fallback.to_string())
+}
diff --git a/crates/wipfel/src/canvas_view.rs b/crates/wipfel/src/canvas_view.rs
index c5777e3..df46b5c 100644
--- a/crates/wipfel/src/canvas_view.rs
+++ b/crates/wipfel/src/canvas_view.rs
@@ -156,10 +156,9 @@ pub fn canvas_view(props: &Props) -> Html {
canvas.set_height(bh);
}
let _ = ctx.set_transform(1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
- // web-sys 0.3: set_fill_style takes a JsValue (deprecated alias)
- #[allow(deprecated)]
- ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("#101014"));
- ctx.fill_rect(0.0, 0.0, canvas.width() as f64, canvas.height() as f64);
+ // transparent clear: the CSS background of .canvaswrap
+ // (a theme variable) shows through
+ ctx.clear_rect(0.0, 0.0, canvas.width() as f64, canvas.height() as f64);
let Some(bitmap) = bitmap else { return };
let _ = ctx.set_transform(
dpr * view.scale,
diff --git a/crates/wipfel/src/compass.rs b/crates/wipfel/src/compass.rs
index b539e07..5e91c9a 100644
--- a/crates/wipfel/src/compass.rs
+++ b/crates/wipfel/src/compass.rs
@@ -127,9 +127,11 @@ pub fn compass(props: &Props) -> Html {
}
let _ = ctx.set_transform(dpr, 0.0, 0.0, dpr, 0.0, 0.0);
- let on = "rgb(217, 217, 217)";
- let bg = "rgb(41, 41, 41)";
- let divider = "rgb(82, 82, 82)";
+ // theme colors come from the CSS variables, so the strip
+ // follows light/dark preference like the rest of the UI
+ let on = bridge::css_var("--compass-fg", "rgb(217, 217, 217)");
+ let bg = bridge::css_var("--compass-bg", "rgb(41, 41, 41)");
+ let divider = bridge::css_var("--compass-divider", "rgb(82, 82, 82)");
let red = "rgb(255, 102, 64)";
let fill = |c: &str| {
@@ -142,9 +144,9 @@ pub fn compass(props: &Props) -> Html {
ctx.set_line_width(width);
};
- fill(bg);
+ fill(&bg);
ctx.fill_rect(0.0, 0.0, w, STRIP_H);
- stroke(divider, 1.0);
+ stroke(&divider, 1.0);
ctx.begin_path();
ctx.move_to(0.0, 0.5);
ctx.line_to(w, 0.5);
@@ -188,7 +190,7 @@ pub fn compass(props: &Props) -> Html {
let a_hi = a_hi.min(c + fold);
// baseline
- stroke(on, 1.0);
+ stroke(&on, 1.0);
ctx.begin_path();
ctx.move_to(0.0, y0 + 0.5);
ctx.line_to(w, y0 + 0.5);
@@ -225,7 +227,7 @@ pub fn compass(props: &Props) -> Html {
if !x.is_finite() || x < -20.0 || x > w + 20.0 {
continue;
}
- fill(if deg == 0.0 { red } else { on });
+ fill(if deg == 0.0 { red } else { &on });
ctx.fill_text(name, x, label_y).ok();
}
ctx.set_text_align("start");