From 116f7421bf7120df8997b94a5f009b652968de60 Mon Sep 17 00:00:00 2001 From: "robin.cole@earthdaily.com" Date: Wed, 2 Dec 2026 11:14:09 +0000 Subject: [PATCH 1/2] Let the Blank basemap follow the app theme in the map view --- crates/ui-egui/src/chrome.rs | 1 + crates/ui-egui/src/lib.rs | 21 +++++++++ crates/ui-egui/src/mapview.rs | 85 ++++++++++++++++++++++++++++++++--- crates/ui-egui/src/ribbon.rs | 16 +++++-- docs/user-guide/maps.md | 6 ++- 5 files changed, 117 insertions(+), 12 deletions(-) diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index edf3b6f64f..5433172b46 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -1439,6 +1439,7 @@ pub(crate) const UI_COMMANDS: &[(&str, &str, &str)] = &[ ("ui.themeReload", "Reload Themes", "Settings › Theme"), ("ui.scale", "Reset Interface Scale", "Settings › Theme"), ("ui.datumGrids", "Toggle Downloading Datum Grids", "Settings › Datum Grids"), + ("ui.followBlankTheme", "Follow App Theme for Blank Paper", "Home › Add › Basemap"), ("ui.sharpTiles", "Toggle Sharp Tiles on HiDPI Displays", "Settings › Map Tiles"), ("ui.map.gpu", "Toggle GPU Rendering", "View"), ("ui.importShapefile", "Import Shapefile with Projection…", "Home › Add"), diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index f9f581bc56..d551baa511 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1070,6 +1070,8 @@ pub struct UiState { /// Whether raster tiles and single pictures are fetched for a HiDPI display's own pixels /// (#2390): on unless turned off. pub sharp_tiles: bool, + /// Use the interface canvas colour for blank maps with no fixed paper colour. + pub(crate) follow_blank_theme: bool, /// Key combinations the native menu bar keeps for itself (macOS: Quit, Close Window, Hide…): /// a shortcut on one would never reach the app, so the shortcut editor refuses them, except /// their own commands in `forwarded_shortcuts`. @@ -1368,6 +1370,7 @@ impl Default for UiState { ask_layers: true, download_grids: false, sharp_tiles: true, + follow_blank_theme: false, reserved_shortcuts: Vec::new(), forwarded_shortcuts: Vec::new(), choosing: Vec::new(), @@ -2134,6 +2137,7 @@ impl RustGisApp { self.ui.ask_layers = self.services.load_pref.as_ref().and_then(|load| load("ask_file_layers")).is_none_or(|v| v != "off"); self.ui.download_grids = self.services.load_pref.as_ref().and_then(|load| load("download_datum_grids")).is_some_and(|v| v == "on"); rustgis_engine::grids::set_enabled(self.ui.download_grids); + self.ui.follow_blank_theme = self.services.load_pref.as_ref().and_then(|load| load("follow_blank_theme")).as_deref() == Some("on"); self.ui.sharp_tiles = self.services.load_pref.as_ref().and_then(|load| load("sharp_tiles")).is_none_or(|v| v != "off"); rustgis_engine::render::rustgis_tiles::template::set_sharp(self.ui.sharp_tiles); // A stored projection this version can't use means Web Mercator. @@ -4664,6 +4668,23 @@ impl RustGisApp { } return Ok(json!({"on": self.ui.download_grids})); } + "ui.followBlankTheme" => { + let map = self.session.map(); + if map.basemap != rustgis_engine::map::Basemap::Blank || map.tiles.iter().any(|t| !t.overlay) { + return Err("choose the Blank basemap first".into()); + } + let fixed = map.paper.is_some(); + let on = match p.get("on") { + None | Some(Value::Null) => fixed || !self.ui.follow_blank_theme, + Some(v) => v.as_bool().ok_or("on must be true or false")?, + }; + if on && fixed { + self.run("map.basemap", json!({"name": "blank", "color": null, "keepTiles": true}))?; + } + self.ui.follow_blank_theme = on; + self.save_pref("follow_blank_theme", if on { "on" } else { "off" }); + return Ok(json!({"on": on})); + } // Whether raster tiles are sharp on a HiDPI display (#2390). "ui.sharpTiles" => { // Without `on` it toggles; a value that isn't true or false is refused. diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index 7a74954011..bcf4f054a5 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -259,6 +259,7 @@ struct SelectionGesture { pub struct MapView { /// The project whose frames and reported tile errors are kept here. project: Option, + theme_paper: Option, texture: Option, key: Option, /// A preview is attempted once for each frame key, including when drawing fails. @@ -373,7 +374,7 @@ pub struct MapView { snap: Option<([f64; 5], Option)>, /// The side-by-side map's last render (texture and labels) and what it was drawn for, so it /// redraws only when that map, the project or the view changes. - split: Option<([f64; 10], egui::TextureHandle, Vec)>, + split: Option<([f64; 11], egui::TextureHandle, Vec)>, /// The picture an identified feature carries (a photo's thumbnail, a `data:image/…` value): /// a hash of the value, and its texture (or why it couldn't be read). picture: Option<(u64, Result)>, @@ -423,7 +424,7 @@ pub struct MapView { pub(crate) gpu_target: std::sync::Arc>>, /// The last side-by-side map's GPU scene (its key, buffers and labels), when the second /// map rendered on the GPU. - pub(crate) split_gpu: Option<([f64; 10], std::sync::Arc, Vec)>, + pub(crate) split_gpu: Option<([f64; 11], std::sync::Arc, Vec)>, /// The split map's offscreen MSAA target (its own slot — main and split differ in size). pub(crate) gpu_target_split: std::sync::Arc>>, pub(crate) render_state: Option, @@ -443,6 +444,7 @@ impl Default for MapView { /// Starts with no chosen node, preview or retained gesture owner, alongside empty map caches. fn default() -> Self { MapView { + theme_paper: None, texture: None, key: None, preview_attempt: None, @@ -935,11 +937,14 @@ fn split_view(app: &mut RustGisApp, ui: &mut Ui, other: usize, rect: Rect, t: &T let ppp = ui.ctx().pixels_per_point(); let revision = app.session.revision; let Some(m) = app.session.project.maps.get_mut(other) else { return }; + let saved_paper = m.paper; + m.paper = theme_paper(m, app.ui.follow_blank_theme, t).or(saved_paper); let view = View { width: w, height: h, pixels_per_point: ppp as f64, camera: m.camera, sky: true }; let painter = ui.painter_at(rect); painter.rect_filled(rect, 0.0, c32(m.palette().0)); let key = [ other as f64, + f64::from(u32::from_be_bytes(m.palette().0.0)), revision as f64, m.camera.center.x, m.camera.center.y, @@ -991,6 +996,7 @@ fn split_view(app: &mut RustGisApp, ui: &mut Ui, other: usize, rect: Rect, t: &T } } } + m.paper = saved_paper; if let (Some((_, bufs, labels)), Some(gr)) = (&app.map.split_gpu, &app.map.gpu_renderer) { painter.add(egui_wgpu::Callback::new_paint_callback( rect, @@ -1031,6 +1037,12 @@ fn split_view(app: &mut RustGisApp, ui: &mut Ui, other: usize, rect: Rect, t: &T } } +/// The paper substituted only while drawing the interactive view. Explicit paper colours belong to the map. +fn theme_paper(map: &rustgis_engine::map::Map, follow: bool, t: &Tokens) -> Option { + (follow && map.basemap == rustgis_engine::map::Basemap::Blank && map.paper.is_none() && map.tiles.iter().all(|tile| tile.overlay)) + .then(|| crate::theme::rgba(t.canvas)) +} + /// Draws the interactive map and its active tool controls before dispatching pointer gestures. fn main_view(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { let t = *t; @@ -1058,6 +1070,28 @@ fn main_view(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } interact(app, ui, &resp, rect); + let paper = theme_paper(app.session.map(), app.ui.follow_blank_theme, &t); + if app.map.theme_paper != paper { + app.map.theme_paper = paper; + app.map.invalidate(); + app.map.drape.clear(); + app.map.tilt_drape.clear(); + } + let saved_paper = app.session.map().paper; + app.session.map_mut().paper = paper.or(saved_paper); + paint_map(app, ui, rect, ppp, time); + app.session.map_mut().paper = saved_paper; + + if !app.map.hide_overlays { + overlays(app, ui, &ui.painter_at(rect), rect, &t); + popup(app, ui, rect); + } +} + +/// Draws the map and its labels while the view's paper colour is in effect. +fn paint_map(app: &mut RustGisApp, ui: &mut Ui, rect: Rect, ppp: f32, time: f64) { + let (w, h) = (rect.width() as f64, rect.height() as f64); + // Render when the map changed and we're not in the middle of a pan/zoom: meanwhile the flat // map's last frame is shifted and scaled. The globe can't be faked that way (turning and // zooming in perspective aren't shifts and scales): while it moves, the map drawn flat is @@ -1801,11 +1835,6 @@ fn main_view(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { draw_label(&painter, &callout_from(l, at, feature), at); } } - if app.map.hide_overlays { - return; - } - overlays(app, ui, &painter, rect, &t); - popup(app, ui, rect); } /// What a drape of the map shows besides the view (see `DrapeKey`), and the tiles come so far (0 @@ -5828,6 +5857,48 @@ fn clear_selection_quietly(app: &mut RustGisApp) { mod tests { use super::*; + #[test] + fn blank_paper_follows_the_theme_around_a_raster() { + use rustgis_engine::data::raster::{ColorHint, Crs, GeoTransform, Raster}; + use rustgis_engine::map::{Basemap, RasterLayer}; + + let mut app = RustGisApp::new(rustgis_engine::Session::new(rustgis_engine::Project::default())); + let map = app.session.map_mut(); + let gt = GeoTransform { origin_x: -20.0, origin_y: 20.0, pixel_width: 10.0, pixel_height: -10.0 }; + let image = Raster::new("image", 4, 4, vec![vec![100.0; 16]], gt, Crs::WebMercator, None, ColorHint::Gray, "Byte").unwrap(); + map.add_raster("image", RasterLayer::from_path(image, "image.tif")); + map.camera = Camera::new(Coord::new(0.0, 0.0), 1.0); + map.basemap = Basemap::Blank; + map.graticule = false; + app.map.hide_overlays = true; + let ctx = egui::Context::default(); + let frame = |app: &mut RustGisApp, theme: Tokens| { + let input = egui::RawInput { time: Some(10.0), ..Default::default() }; + let mut output = ctx.run_ui(input, |ui| { + ui.set_max_size(vec2(128.0, 128.0)); + main_view(app, ui, &theme); + }); + let id = app.map.texture.as_ref().unwrap().id(); + let pixels = output.textures_delta.set.get(&id).map(|deltas| { + let egui::ImageData::Color(image) = &deltas.last().unwrap().image; + (image[(0, 0)], image[(image.size[0] / 2, image.size[1] / 2)]) + }); + output.textures_delta.clear(); + pixels + }; + let (paper, raster) = frame(&mut app, Tokens::dark()).unwrap(); + assert_eq!(paper, Color32::WHITE); + assert_ne!(raster, paper); + app.run("ui.followBlankTheme", json!({"on": true})).unwrap(); + for theme in [Tokens::light(), Tokens::dark(), Tokens::light()] { + assert_eq!(frame(&mut app, theme), Some((theme.canvas, raster))); + assert!(app.session.map().paper.is_none(), "the map keeps its own paper for saving and export"); + } + app.run("map.basemap", json!({"name": "blank", "color": "#663344"})).unwrap(); + assert_eq!(frame(&mut app, Tokens::light()), Some((Color32::from_rgb(0x66, 0x33, 0x44), raster))); + assert_eq!(frame(&mut app, Tokens::dark()), None, "fixed paper needs no new frame"); + } + /// The graphics card running out of memory doesn't close the app (#1777): it's noted, and /// the map then leaves the GPU for the CPU with a notice, its GPU resources let go. Once: /// turned on again, running out again falls back again. With the map already on the CPU, diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index e2b83c4176..c088a53e42 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -792,11 +792,21 @@ fn blank_paper(ui: &mut Ui, app: &mut RustGisApp) { if map.basemap != Basemap::Blank || !map.tiles.iter().all(|t| t.overlay) { return; } - let current = map.palette().0; + let fixed = map.paper; ui.add_space(6.0); egui::CollapsingHeader::new(tl!("Paper color")).id_salt("blank_paper").show(ui, |ui| { - if let Some(c) = opaque_picker(ui, app, current) { - let _ = app.run("map.basemap", json!({"name": "blank", "color": c.hex(), "keepTiles": true})); + let mut follow = app.ui.follow_blank_theme && fixed.is_none(); + if ui.checkbox(&mut follow, tl!("Follow app theme")).changed() { + let _ = app.run("ui.followBlankTheme", json!({"on": follow})); + } + let current = if follow { crate::theme::rgba(Tokens::get(ui.ctx()).canvas) } else { app.session.map().palette().0 }; + if let Some(c) = opaque_picker(ui, app, current) + && app.run("map.basemap", json!({"name": "blank", "color": c.hex(), "keepTiles": true})).is_ok() + && app.ui.follow_blank_theme + && app.session.map().paper.is_none() + { + // The map stores fixed white as the absence of a paper colour. + let _ = app.run("ui.followBlankTheme", json!({"on": false})); } }); } diff --git a/docs/user-guide/maps.md b/docs/user-guide/maps.md index c03e108b67..6223553d5d 100644 --- a/docs/user-guide/maps.md +++ b/docs/user-guide/maps.md @@ -537,8 +537,10 @@ place names there. On the desktop, its optional `url` selects another Valhalla s Ocean, Atlas, Blank), which need no network, and web tile layers over them. On Blank, **Paper color** under the basemaps sets the colour the map draws where it would draw white, a tilted view's sky included, so a map frame sits on a coloured layout page without a white box around it -(`map.basemap {"name": "blank", "color": "#F1EADF"}`). Choosing another basemap takes the paper -colour off, as that basemap draws its own colours: +(`map.basemap {"name": "blank", "color": "#F1EADF"}`). Turn on **Follow app theme** here to use the interface canvas +colour when viewing a blank map. A fixed paper colour takes precedence. Layouts and exports use +the map's own paper colour. Choosing another basemap takes the paper colour off, as that basemap +draws its own colours: - **Raster tiles** from an XYZ or TMS template (`https://…/{z}/{x}/{y}.png`; `{-y}` for rows from the south, `{s}` for subdomains, `{q}` for Bing-style quadkeys) or a WMS through From 3a4e0b33f19637684edfc8c31005bc8e16d0b68a Mon Sep 17 00:00:00 2001 From: "robin.cole@earthdaily.com" Date: Wed, 2 Dec 2026 12:05:20 +0000 Subject: [PATCH 2/2] Use theme defaults for new maps and blank paper --- crates/engine/src/cmd/navigate.rs | 11 ++-- crates/engine/src/cmd/project.rs | 6 +- crates/engine/src/lib.rs | 3 + crates/engine/src/project_capabilities.rs | 10 +-- crates/engine/src/tests.rs | 2 +- crates/ui-egui/src/chrome.rs | 1 - crates/ui-egui/src/lib.rs | 78 +++++++++++++++++------ crates/ui-egui/src/mapview.rs | 18 ++++-- crates/ui-egui/src/ribbon.rs | 16 ++--- docs/user-guide/maps.md | 17 +++-- 10 files changed, 105 insertions(+), 57 deletions(-) diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index cc6569d74f..8a85571d87 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -77,7 +77,7 @@ pub fn commands() -> Vec { .view() .params(r#"{"scale": number}"#), C::new("map.basemap", "Basemap", "Home › Add", basemap).roles(&[]).effects(crate::policy::Effects::NONE) - .params(r##"{"name": "paper"|"midnight"|"ocean"|"atlas"|"blank", "keepTiles"?: bool (keeps the web tile basemaps over it), "color"?: "#RRGGBB" (blank: the paper's colour, drawn where a blank map draws white, the tilted view's sky included; null or #FFFFFF: white; default: as it was. Another basemap takes the paper off and keeps its own colours; a color given with it is said as a warning)}"##), + .params(r##"{"name": "paper"|"midnight"|"ocean"|"atlas"|"blank", "keepTiles"?: bool (keeps the web tile basemaps over it), "color"?: "#RRGGBB" (blank: the paper's colour, drawn where a blank map draws white, the tilted view's sky included; null: reset to default paper; default: as it was. Another basemap takes the paper off and keeps its own colours; a color given with it is said as a warning)}"##), C::new("map.graticule", "Graticule", "View › Display", graticule).roles(&[]).effects(crate::policy::Effects::NONE) .params(r##"{"on"?: bool (toggles when omitted, on when a type or crs is given, kept as it is when only onTop or color is given), "type"?: "degrees"|"measured"|"utm"|"mgrs", "crs"?: a projected system for the measured grid (EPSG:2056, WKT or a PROJ string; "" or null: the map's own when projected, else the UTM zone at the view's centre), "onTop"?: bool (the lines over the layers, under the labels; false or null: with the basemap, under the layers), "color"?: "#RRGGBB"|"#RRGGBBAA" ("" or null: the basemap's)}"##), C::new("map.reloadWebLayers", "Reload Web Layers", "View › Display", |_, _| { @@ -1333,8 +1333,7 @@ fn basemap(s: &mut Session, p: &Value) -> CmdResult { return Ok(json!({"warning": warning})); } } else if let Some(paper) = paper { - // White is the blank basemap's own paper: nothing to keep, or to require of a reader. - m.paper = paper.filter(|c| *c != rustgis_map::Rgba::rgb(0xFF, 0xFF, 0xFF)); + m.paper = paper; } Ok(Value::Null) } @@ -1588,7 +1587,11 @@ fn new_map(s: &mut Session, p: &Value) -> CmdResult { name = format!("{base}{i}"); } let mut m = Map::new(name.clone()); - (m.basemap, m.paper) = (s.map().basemap, s.map().paper); + if let Some(basemap) = s.new_map_basemap { + m.basemap = basemap; + } else { + (m.basemap, m.paper) = (s.map().basemap, s.map().paper); + } // Drawn in the project's coordinate system, where the active map is looking; one a map can't // be drawn in is said, and the map starts in Web Mercator as without one. if let Some(crs) = s.project.coordinate_system { diff --git a/crates/engine/src/cmd/project.rs b/crates/engine/src/cmd/project.rs index 0c01262837..920fbf23be 100644 --- a/crates/engine/src/cmd/project.rs +++ b/crates/engine/src/cmd/project.rs @@ -712,7 +712,11 @@ fn reset(s: &mut Session, p: Project) { } fn new(s: &mut Session, p: &Value) -> CmdResult { - reset(s, Project::new(super::ps(p, "name").unwrap_or("Untitled"))); + let mut project = Project::new(super::ps(p, "name").unwrap_or("Untitled")); + if let Some(basemap) = s.new_map_basemap { + project.map_mut().basemap = basemap; + } + reset(s, project); s.path = None; Ok(Value::Null) } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 3137f6ac15..15e4ab4d7f 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -831,6 +831,8 @@ pub struct Session { /// A native transport answer scoped over one synchronous connection.browse dispatch. pub(crate) browse_response: Option<(String, String, crate::render::rustgis_tiles::address::Origin)>, pub project: Project, + /// Basemap for new maps in a themed interface. Headless sessions inherit the active map's basemap. + pub new_map_basemap: Option, pub path: Option, /// What was run in this session (#797), whatever project was open: kept in memory only, so /// a saved or shared project carries none of it. @@ -1501,6 +1503,7 @@ impl Session { let open_layout = project.saved_open_layout(); let mut session = Session { project, + new_map_basemap: None, path: None, log: project_log::SessionLog::default(), opened_package: None, diff --git a/crates/engine/src/project_capabilities.rs b/crates/engine/src/project_capabilities.rs index e817be5fff..f0cb586d65 100644 --- a/crates/engine/src/project_capabilities.rs +++ b/crates/engine/src/project_capabilities.rs @@ -1014,12 +1014,12 @@ fn command_colours_the_page(id: &str, params: &Value) -> bool { } /// A `map.basemap` command that gives the blank basemap a paper colour (#2532): an older reader -/// ignores `color` and draws white. White, `null` or another basemap leaves no paper to keep. +/// ignores `color` and draws white. An explicit colour, including white, is fixed paper. fn command_uses_blank_paper(id: &str, params: &Value) -> bool { match id { "map.basemap" => { params.get("name").and_then(Value::as_str).is_some_and(|n| n.trim().eq_ignore_ascii_case("blank")) - && params.get("color").and_then(Value::as_str).is_some_and(|c| !c.trim().eq_ignore_ascii_case("#FFFFFF")) + && params.get("color").and_then(Value::as_str).is_some() } "script.run" => params.get("script").and_then(Value::as_str).is_some_and(|s| script_uses(s, command_uses_blank_paper)), _ => false, @@ -4601,7 +4601,7 @@ mod tests { } /// A blank basemap's paper colour (#2532) is required by name in a project and a map file: an - /// older reader would draw the paper white and save the colour away. White paper needs nothing. + /// older reader would draw the paper white and save the colour away. Default paper needs nothing. #[test] fn a_blank_paper_colour_is_required_where_it_is_saved() { let mut p = Project::from_json(include_str!("../../../schema/fixtures/blank_paper.rgis")).unwrap(); @@ -4614,12 +4614,12 @@ mod tests { let clean = serde_json::to_value(&p).unwrap(); assert!(clean.get("requires").is_none()); assert!(clean["maps"][0].get("paper").is_none()); - // A saved command that gives the blank basemap a colour needs it too; white, null or + // A saved command that gives the blank basemap a colour needs it too; null or // another basemap doesn't. for (params, required) in [ (json!({"name": "blank", "color": "#F1EADF"}), true), (json!({"name": "Blank", "color": "#101820"}), true), - (json!({"name": "blank", "color": "#ffffff"}), false), + (json!({"name": "blank", "color": "#ffffff"}), true), (json!({"name": "blank", "color": null}), false), (json!({"name": "blank"}), false), (json!({"name": "paper", "color": "#F1EADF"}), false), diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 07938c2032..ad43dee571 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -22268,7 +22268,7 @@ fn a_blank_basemap_takes_a_paper_colour() { let inside = pm.pixel(71, 71).unwrap(); assert_eq!((inside.red(), inside.green(), inside.blue()), (0xF1, 0xEA, 0xDF)); s.run("map.basemap", &json!({"name": "blank", "color": "#ffffff"})).unwrap(); - assert_eq!(s.map().paper, None, "white is the blank basemap's own paper"); + assert_eq!(s.map().paper, Some(rustgis_map::Rgba::rgb(255, 255, 255)), "explicit white is fixed paper"); s.run("map.basemap", &json!({"name": "blank", "color": "#F1EADF"})).unwrap(); s.run("map.basemap", &json!({"name": "blank", "color": null})).unwrap(); assert_eq!(s.map().paper, None, "null: white again"); diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index 5433172b46..edf3b6f64f 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -1439,7 +1439,6 @@ pub(crate) const UI_COMMANDS: &[(&str, &str, &str)] = &[ ("ui.themeReload", "Reload Themes", "Settings › Theme"), ("ui.scale", "Reset Interface Scale", "Settings › Theme"), ("ui.datumGrids", "Toggle Downloading Datum Grids", "Settings › Datum Grids"), - ("ui.followBlankTheme", "Follow App Theme for Blank Paper", "Home › Add › Basemap"), ("ui.sharpTiles", "Toggle Sharp Tiles on HiDPI Displays", "Settings › Map Tiles"), ("ui.map.gpu", "Toggle GPU Rendering", "View"), ("ui.importShapefile", "Import Shapefile with Projection…", "Home › Add"), diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index d551baa511..9fc0b71ae9 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1070,8 +1070,6 @@ pub struct UiState { /// Whether raster tiles and single pictures are fetched for a HiDPI display's own pixels /// (#2390): on unless turned off. pub sharp_tiles: bool, - /// Use the interface canvas colour for blank maps with no fixed paper colour. - pub(crate) follow_blank_theme: bool, /// Key combinations the native menu bar keeps for itself (macOS: Quit, Close Window, Hide…): /// a shortcut on one would never reach the app, so the shortcut editor refuses them, except /// their own commands in `forwarded_shortcuts`. @@ -1370,7 +1368,6 @@ impl Default for UiState { ask_layers: true, download_grids: false, sharp_tiles: true, - follow_blank_theme: false, reserved_shortcuts: Vec::new(), forwarded_shortcuts: Vec::new(), choosing: Vec::new(), @@ -1669,6 +1666,8 @@ pub struct RustGisApp { /// When this frame's `logic` began, for the double-click delay `ui` sets when it ends. frame_start: Option, applied_theme: Option<(String, bool)>, + /// A fresh startup project created before the window reported the system theme. + startup_theme_project: Option, /// The themes the app can offer: built in, then the ones in the user's themes folder. pub themes: Vec, /// The theme files that did not load, with the reason. @@ -2026,6 +2025,7 @@ impl RustGisApp { fonts_frames: 0, frame_start: None, applied_theme: None, + startup_theme_project: None, themes: theme::Theme::builtin(), theme_errors: Vec::new(), theme_notes: Vec::new(), @@ -2137,7 +2137,6 @@ impl RustGisApp { self.ui.ask_layers = self.services.load_pref.as_ref().and_then(|load| load("ask_file_layers")).is_none_or(|v| v != "off"); self.ui.download_grids = self.services.load_pref.as_ref().and_then(|load| load("download_datum_grids")).is_some_and(|v| v == "on"); rustgis_engine::grids::set_enabled(self.ui.download_grids); - self.ui.follow_blank_theme = self.services.load_pref.as_ref().and_then(|load| load("follow_blank_theme")).as_deref() == Some("on"); self.ui.sharp_tiles = self.services.load_pref.as_ref().and_then(|load| load("sharp_tiles")).is_none_or(|v| v != "off"); rustgis_engine::render::rustgis_tiles::template::set_sharp(self.ui.sharp_tiles); // A stored projection this version can't use means Web Mercator. @@ -3439,6 +3438,11 @@ impl RustGisApp { Ok(()) } + fn theme_basemap(&self) -> rustgis_engine::map::Basemap { + use rustgis_engine::map::Basemap; + if self.ui.dark { Basemap::Midnight } else { Basemap::Paper } + } + /// Sets up the project the app opens with, from the Settings › Start-up preferences; a shell /// passes its own overrides (the web app's `?blank`, `?projection=` and `?extent=`). Call it /// once, after [`Self::with_services`] and before opening files. The start is not an edit to @@ -3451,6 +3455,9 @@ impl RustGisApp { let opened = match (overrides.blank, self.ui.start_with.clone()) { (Some(true), _) | (None, StartWith::Blank) => { self.run("project.new", Value::Null)?; + if self.ui.dark_follows_system && self.applied_theme.is_none() { + self.startup_theme_project = Some(self.session.opened); + } false } (Some(false), _) | (None, StartWith::Sample) => false, @@ -3926,6 +3933,7 @@ impl RustGisApp { if id == "gpkg.discardEdits" { diskwatch::reading(self, id, ¶ms); } + self.session.new_map_basemap = Some(self.theme_basemap()); let mut r = match dispatch { AppDispatch::Prepared(prepared) => self.session.run_prepared(*prepared), AppDispatch::InPlace(id) => self.session.add_in_place_for(id, ¶ms), @@ -3939,6 +3947,9 @@ impl RustGisApp { AppDispatch::Direct if id.starts_with(rustgis_engine::plugins::PREFIX) => self.session.run_leaving_downloads(id, ¶ms), AppDispatch::Direct => self.session.run(id, ¶ms), }; + if r.is_ok() && id == "map.basemap" { + self.startup_theme_project = None; + } r = self.deliver_gp_files(r); // A reload acknowledges what it read; a save into a watched file is RustGIS's own write. #[cfg(not(target_arch = "wasm32"))] @@ -4668,23 +4679,6 @@ impl RustGisApp { } return Ok(json!({"on": self.ui.download_grids})); } - "ui.followBlankTheme" => { - let map = self.session.map(); - if map.basemap != rustgis_engine::map::Basemap::Blank || map.tiles.iter().any(|t| !t.overlay) { - return Err("choose the Blank basemap first".into()); - } - let fixed = map.paper.is_some(); - let on = match p.get("on") { - None | Some(Value::Null) => fixed || !self.ui.follow_blank_theme, - Some(v) => v.as_bool().ok_or("on must be true or false")?, - }; - if on && fixed { - self.run("map.basemap", json!({"name": "blank", "color": null, "keepTiles": true}))?; - } - self.ui.follow_blank_theme = on; - self.save_pref("follow_blank_theme", if on { "on" } else { "off" }); - return Ok(json!({"on": on})); - } // Whether raster tiles are sharp on a HiDPI display (#2390). "ui.sharpTiles" => { // Without `on` it toggles; a value that isn't true or false is refused. @@ -7909,6 +7903,14 @@ impl RustGisApp { { self.ui.dark = system == egui::Theme::Dark; } + let basemap = self.theme_basemap(); + self.session.new_map_basemap = Some(basemap); + if self.startup_theme_project.take() == Some(self.session.opened) + && let Some(map) = self.session.project.maps.first_mut() + && matches!(map.basemap, rustgis_engine::map::Basemap::Paper | rustgis_engine::map::Basemap::Midnight) + { + map.basemap = basemap; + } widgets::let_go_on_panel_press(ctx); widgets::note_escape(ctx); if self.applied_theme.as_ref() != Some(&(self.ui.theme_name.clone(), self.ui.dark)) { @@ -11518,6 +11520,40 @@ mod look_tests { assert_eq!(crate::i18n::current().code(), "de"); } + #[test] + fn theme_basemap_for_new_projects_and_maps() { + use rustgis_engine::map::Basemap; + let mut app = app_with(&[]); + for (dark, expected) in [(true, Basemap::Midnight), (false, Basemap::Paper)] { + app.run("ui.theme", serde_json::json!({"dark": dark})).unwrap(); + app.run("project.new", serde_json::Value::Null).unwrap(); + assert_eq!(app.session.map().basemap, expected); + app.run("map.basemap", serde_json::json!({"name": "blank", "color": "#ffffff"})).unwrap(); + app.run("map.new", serde_json::Value::Null).unwrap(); + assert_eq!(app.session.map().basemap, expected); + assert!(app.session.map().paper.is_none()); + assert_eq!(app.session.project.maps[0].basemap, Basemap::Blank); + let saved = serde_json::to_string(&app.session.project).unwrap(); + app.run("ui.theme", serde_json::json!({"dark": !dark})).unwrap(); + app.run("project.openText", serde_json::json!({"text": saved})).unwrap(); + assert_eq!(app.session.map().basemap, expected); + } + } + + #[test] + fn theme_basemap_at_start_uses_the_first_system_theme() { + use rustgis_engine::map::Basemap; + let ctx = egui::Context::default(); + let mut app = app_with(&[]); + app.start(&super::Start { blank: Some(true), ..Default::default() }).unwrap(); + for theme in [egui::Theme::Dark, egui::Theme::Light] { + let input = egui::RawInput { system_theme: Some(theme), ..Default::default() }; + let mut output = ctx.run_ui(input, |ui| app.logic(ui.ctx())); + output.textures_delta.clear(); + assert_eq!(app.session.map().basemap, Basemap::Midnight); + } + } + #[test] fn the_saved_theme_is_taken_at_start() { let mut app = app_with(&[("theme", "Mine"), ("ui_scale", "9")]); diff --git a/crates/ui-egui/src/mapview.rs b/crates/ui-egui/src/mapview.rs index bcf4f054a5..6894c21751 100644 --- a/crates/ui-egui/src/mapview.rs +++ b/crates/ui-egui/src/mapview.rs @@ -938,7 +938,7 @@ fn split_view(app: &mut RustGisApp, ui: &mut Ui, other: usize, rect: Rect, t: &T let revision = app.session.revision; let Some(m) = app.session.project.maps.get_mut(other) else { return }; let saved_paper = m.paper; - m.paper = theme_paper(m, app.ui.follow_blank_theme, t).or(saved_paper); + m.paper = theme_paper(m, t).or(saved_paper); let view = View { width: w, height: h, pixels_per_point: ppp as f64, camera: m.camera, sky: true }; let painter = ui.painter_at(rect); painter.rect_filled(rect, 0.0, c32(m.palette().0)); @@ -1038,8 +1038,8 @@ fn split_view(app: &mut RustGisApp, ui: &mut Ui, other: usize, rect: Rect, t: &T } /// The paper substituted only while drawing the interactive view. Explicit paper colours belong to the map. -fn theme_paper(map: &rustgis_engine::map::Map, follow: bool, t: &Tokens) -> Option { - (follow && map.basemap == rustgis_engine::map::Basemap::Blank && map.paper.is_none() && map.tiles.iter().all(|tile| tile.overlay)) +fn theme_paper(map: &rustgis_engine::map::Map, t: &Tokens) -> Option { + (map.basemap == rustgis_engine::map::Basemap::Blank && map.paper.is_none() && map.tiles.iter().all(|tile| tile.overlay)) .then(|| crate::theme::rgba(t.canvas)) } @@ -1070,9 +1070,10 @@ fn main_view(app: &mut RustGisApp, ui: &mut Ui, t: &Tokens) { } interact(app, ui, &resp, rect); - let paper = theme_paper(app.session.map(), app.ui.follow_blank_theme, &t); + let paper = theme_paper(app.session.map(), &t); if app.map.theme_paper != paper { app.map.theme_paper = paper; + app.map.texture = None; app.map.invalidate(); app.map.drape.clear(); app.map.tilt_drape.clear(); @@ -5887,9 +5888,8 @@ mod tests { pixels }; let (paper, raster) = frame(&mut app, Tokens::dark()).unwrap(); - assert_eq!(paper, Color32::WHITE); + assert_eq!(paper, Tokens::dark().canvas); assert_ne!(raster, paper); - app.run("ui.followBlankTheme", json!({"on": true})).unwrap(); for theme in [Tokens::light(), Tokens::dark(), Tokens::light()] { assert_eq!(frame(&mut app, theme), Some((theme.canvas, raster))); assert!(app.session.map().paper.is_none(), "the map keeps its own paper for saving and export"); @@ -5897,6 +5897,12 @@ mod tests { app.run("map.basemap", json!({"name": "blank", "color": "#663344"})).unwrap(); assert_eq!(frame(&mut app, Tokens::light()), Some((Color32::from_rgb(0x66, 0x33, 0x44), raster))); assert_eq!(frame(&mut app, Tokens::dark()), None, "fixed paper needs no new frame"); + app.run("map.basemap", json!({"name": "blank", "color": "#FFFFFF"})).unwrap(); + assert_eq!(frame(&mut app, Tokens::dark()), Some((Color32::WHITE, raster))); + let saved = serde_json::to_string(&app.session.project).unwrap(); + assert_eq!(rustgis_engine::Project::from_json(&saved).unwrap().map().paper, app.session.map().paper); + app.run("map.basemap", json!({"name": "blank", "color": null})).unwrap(); + assert_eq!(frame(&mut app, Tokens::dark()), Some((Tokens::dark().canvas, raster))); } /// The graphics card running out of memory doesn't close the app (#1777): it's noted, and diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index c088a53e42..7dd4ac67a5 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -795,18 +795,12 @@ fn blank_paper(ui: &mut Ui, app: &mut RustGisApp) { let fixed = map.paper; ui.add_space(6.0); egui::CollapsingHeader::new(tl!("Paper color")).id_salt("blank_paper").show(ui, |ui| { - let mut follow = app.ui.follow_blank_theme && fixed.is_none(); - if ui.checkbox(&mut follow, tl!("Follow app theme")).changed() { - let _ = app.run("ui.followBlankTheme", json!({"on": follow})); + let current = fixed.unwrap_or_else(|| crate::theme::rgba(Tokens::get(ui.ctx()).canvas)); + if let Some(c) = opaque_picker(ui, app, current) { + let _ = app.run("map.basemap", json!({"name": "blank", "color": c.hex(), "keepTiles": true})); } - let current = if follow { crate::theme::rgba(Tokens::get(ui.ctx()).canvas) } else { app.session.map().palette().0 }; - if let Some(c) = opaque_picker(ui, app, current) - && app.run("map.basemap", json!({"name": "blank", "color": c.hex(), "keepTiles": true})).is_ok() - && app.ui.follow_blank_theme - && app.session.map().paper.is_none() - { - // The map stores fixed white as the absence of a paper colour. - let _ = app.run("ui.followBlankTheme", json!({"on": false})); + if ui.add_enabled(fixed.is_some(), egui::Button::new(tl!("Use theme color"))).clicked() { + let _ = app.run("map.basemap", json!({"name": "blank", "color": null, "keepTiles": true})); } }); } diff --git a/docs/user-guide/maps.md b/docs/user-guide/maps.md index 6223553d5d..99b47c53e7 100644 --- a/docs/user-guide/maps.md +++ b/docs/user-guide/maps.md @@ -534,13 +534,16 @@ place names there. On the desktop, its optional `url` selects another Valhalla s **Home › Add › Basemap** offers five built-in basemaps drawn from a world outline (Paper, Midnight, -Ocean, Atlas, Blank), which need no network, and web tile layers over them. On Blank, **Paper -color** under the basemaps sets the colour the map draws where it would draw white, a tilted view's -sky included, so a map frame sits on a coloured layout page without a white box around it -(`map.basemap {"name": "blank", "color": "#F1EADF"}`). Turn on **Follow app theme** here to use the interface canvas -colour when viewing a blank map. A fixed paper colour takes precedence. Layouts and exports use -the map's own paper colour. Choosing another basemap takes the paper colour off, as that basemap -draws its own colours: +Ocean, Atlas, Blank), which need no network. New maps start with Midnight in Dark mode and Paper +in Light mode. Opening a saved map restores its basemap. + +Blank uses the interface canvas colour around layers. To give a Blank map a fixed paper colour, +including white, use **Paper color** in the basemap gallery +(`map.basemap {"name": "blank", "color": "#F1EADF"}`). Choose **Use theme color** to reset it. +Layouts and exports use the saved paper colour, or white when the map has no fixed colour. +Choosing another built-in basemap clears the fixed paper colour. + +The gallery also offers these tile layers. - **Raster tiles** from an XYZ or TMS template (`https://…/{z}/{x}/{y}.png`; `{-y}` for rows from the south, `{s}` for subdomains, `{q}` for Bing-style quadkeys) or a WMS through