diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 08:42:30 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-28 08:42:30 +0100 |
| commit | aab6af1601fa4cdb9b351987220f32de062d4b2c (patch) | |
| tree | e5d2b4b6af7e5d8fd8d19717786ed0f29b619b0f /crates/wipfel | |
| parent | d57f022243850b532239ae08dd75717f55415fbf (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')
| -rw-r--r-- | crates/wipfel/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/wipfel/src/bridge.rs | 12 | ||||
| -rw-r--r-- | crates/wipfel/src/canvas_view.rs | 7 | ||||
| -rw-r--r-- | crates/wipfel/src/compass.rs | 16 | ||||
| -rw-r--r-- | crates/wipfel/www/index.html | 2 | ||||
| -rw-r--r-- | crates/wipfel/www/style.css | 126 |
6 files changed, 117 insertions, 47 deletions
diff --git a/crates/wipfel/Cargo.toml b/crates/wipfel/Cargo.toml index fad31ce..47faa60 100644 --- a/crates/wipfel/Cargo.toml +++ b/crates/wipfel/Cargo.toml @@ -19,6 +19,7 @@ features = [ "Blob", "CanvasRenderingContext2d", "DataTransfer", + "CssStyleDeclaration", "Document", "DomRect", "DragEvent", 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(÷r, 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"); diff --git a/crates/wipfel/www/index.html b/crates/wipfel/www/index.html index 98f81e8..67d0378 100644 --- a/crates/wipfel/www/index.html +++ b/crates/wipfel/www/index.html @@ -3,6 +3,8 @@ <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> + <meta name="theme-color" content="#101014" media="(prefers-color-scheme: dark)" /> + <meta name="theme-color" content="#e9eaf0" media="(prefers-color-scheme: light)" /> <title>wipfel — web based gipfel photogrammetry</title> <link rel="stylesheet" href="style.css" /> </head> diff --git a/crates/wipfel/www/style.css b/crates/wipfel/www/style.css index 3ef48b1..80c4d15 100644 --- a/crates/wipfel/www/style.css +++ b/crates/wipfel/www/style.css @@ -1,6 +1,56 @@ * { box-sizing: border-box; } +:root { + /* dark is the default theme; the light block below overrides for + users whose OS/browser prefers light */ + --bg: #101014; + --panel: #1a1a20; + --panel-border: #2c2c34; + --text: #e8e8ea; + --text-dim: #c8c8d0; + --text-faint: #8a8a94; + --input-bg: #24242c; + --input-border: #34343e; + --chip-bg: #2c2c34; + --chip-hover: #3b3b46; + --btn: #3b6fd4; + --btn-hover: #4a7ee4; + --accent: #7fa5e8; + --fitinfo: #9fd09f; + --canvas-bg: #101014; + --compass-bg: rgb(41, 41, 41); + --compass-fg: rgb(217, 217, 217); + --compass-divider: rgb(82, 82, 82); + --popover-bg: #1e1e26; + --popover-border: #3a3a46; + --popover-shadow: rgba(0, 0, 0, 0.5); +} +@media (prefers-color-scheme: light) { + :root { + --bg: #e9eaf0; + --panel: #ffffff; + --panel-border: #d6d8de; + --text: #1e1e26; + --text-dim: #44464e; + --text-faint: #7c7e88; + --input-bg: #f0f1f5; + --input-border: #c9ccd4; + --chip-bg: #e2e3e9; + --chip-hover: #d0d2da; + --btn: #3b6fd4; + --btn-hover: #2f5fbd; + --accent: #2b5cb8; + --fitinfo: #2e7d32; + --canvas-bg: #d9dbe2; + --compass-bg: rgb(240, 241, 245); + --compass-fg: rgb(40, 40, 48); + --compass-divider: rgb(170, 173, 182); + --popover-bg: #ffffff; + --popover-border: #c9ccd4; + --popover-shadow: rgba(40, 40, 60, 0.25); + } +} html, body { margin: 0; @@ -14,14 +64,14 @@ body { area behind the collapsing URL bar, pushing the compass below the fold; dvh tracks the actually visible area */ height: 100dvh; - background: #101014; - color: #e8e8ea; + background: var(--bg); + color: var(--text); } .sidebar { width: 300px; padding: 16px; - background: #1a1a20; - border-right: 1px solid #2c2c34; + background: var(--panel); + border-right: 1px solid var(--panel-border); display: flex; flex-direction: column; gap: 8px; @@ -38,12 +88,13 @@ body { width: 28px; height: 28px; padding: 0; - background: #2c2c34; + background: var(--chip-bg); + color: var(--text); font-size: 12px; border-radius: 5px; } .sidebar .collapse-btn:hover { - background: #3b3b46; + background: var(--chip-hover); } .nav-toggle { position: absolute; @@ -63,6 +114,7 @@ body { .nav-toggle:hover { background: rgba(59, 111, 212, 0.9); } +/* sits on top of the photo, so it stays dark in both themes */ .canvasstatus { position: absolute; bottom: 6px; @@ -89,19 +141,19 @@ body { .tag { display: block; margin: 0 0 12px; - color: #8a8a94; + color: var(--text-faint); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; text-decoration: none; } .tag:hover { - color: #7fa5e8; + color: var(--accent); text-decoration: underline; } .sidebar button { padding: 8px 12px; - background: #3b6fd4; + background: var(--btn); color: #fff; border: 0; border-radius: 6px; @@ -109,16 +161,16 @@ body { cursor: pointer; } .sidebar button:hover { - background: #4a7ee4; + background: var(--btn-hover); } .status { font-size: 13px; - color: #c8c8d0; + color: var(--text-dim); word-break: break-word; } .hint { font-size: 12px; - color: #8a8a94; + color: var(--text-faint); } .row { display: flex; @@ -129,13 +181,13 @@ body { } .fitinfo { font-size: 12px; - color: #9fd09f; + color: var(--fitinfo); font-variant-numeric: tabular-nums; } .hover { font-size: 14px; font-weight: 600; - color: #ffffff; + color: var(--text); } .dim { opacity: 0.6; @@ -143,7 +195,6 @@ body { .hidden-file { display: none; } -/* pin the optional track section to the bottom of the control pane */ .infofoot { /* pins the info texts to the bottom of the sidebar */ margin-top: auto; @@ -158,6 +209,7 @@ body { flex: 1; position: relative; min-height: 0; + background: var(--canvas-bg); } canvas.viewport { position: absolute; @@ -179,8 +231,8 @@ canvas.compass { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; - color: #8a8a94; - border-bottom: 1px solid #2c2c34; + color: var(--text-faint); + border-bottom: 1px solid var(--panel-border); padding-bottom: 3px; } .slider { @@ -193,10 +245,11 @@ canvas.compass { display: flex; justify-content: space-between; font-size: 12px; - color: #c8c8d0; + color: var(--text-dim); } .slider input[type="range"] { width: 100%; + accent-color: var(--btn); } .numrow { display: flex; @@ -209,9 +262,9 @@ canvas.compass { .numrow input { width: 130px; padding: 4px 6px; - background: #24242c; - color: #e8e8ea; - border: 1px solid #34343e; + background: var(--input-bg); + color: var(--text); + border: 1px solid var(--input-border); border-radius: 4px; } .numrow input[type="text"] { @@ -226,24 +279,24 @@ canvas.compass { position: absolute; z-index: 10; width: 280px; - background: #1e1e26; - border: 1px solid #3a3a46; + background: var(--popover-bg); + border: 1px solid var(--popover-border); border-radius: 6px; - box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); + box-shadow: 0 8px 24px var(--popover-shadow); display: flex; flex-direction: column; } .fpsearch { padding: 8px; - border-bottom: 1px solid #2c2c34; + border-bottom: 1px solid var(--panel-border); } .fpsearch input { width: 100%; padding: 5px 8px; - background: #24242c; - border: 1px solid #3a3a46; + background: var(--input-bg); + border: 1px solid var(--popover-border); border-radius: 4px; - color: #e8e8ea; + color: var(--text); font-size: 13px; } .fplist { @@ -253,18 +306,18 @@ canvas.compass { .fpempty { padding: 8px 10px; font-size: 13px; - color: #8a8a94; + color: var(--text-faint); margin: 0; } .fpfoot { padding: 6px 8px; - border-top: 1px solid #2c2c34; + border-top: 1px solid var(--panel-border); text-align: right; } .fpcancel { padding: 4px 12px; - background: #34343e; - color: #e8e8ea; + background: var(--chip-bg); + color: var(--text); border: 0; border-radius: 4px; font-size: 12px; @@ -275,8 +328,8 @@ canvas.compass { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; - color: #8a8a94; - border-bottom: 1px solid #2c2c34; + color: var(--text-faint); + border-bottom: 1px solid var(--panel-border); } .fpitem { display: block; @@ -285,10 +338,11 @@ canvas.compass { padding: 6px 10px; background: none; border: 0; - color: #e8e8ea; + color: var(--text); font-size: 13px; cursor: pointer; } .fpitem:hover { - background: #2f6fd4; + background: var(--btn); + color: #fff; } |
