Repository navigation
Use theme defaults for new maps and the Blank basemap #3606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1666,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<web_time::Instant>, | ||||||
| applied_theme: Option<(String, bool)>, | ||||||
| /// A fresh startup project created before the window reported the system theme. | ||||||
| startup_theme_project: Option<u64>, | ||||||
| /// The themes the app can offer: built in, then the ones in the user's themes folder. | ||||||
| pub themes: Vec<theme::Theme>, | ||||||
| /// The theme files that did not load, with the reason. | ||||||
|
|
@@ -2023,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(), | ||||||
|
|
@@ -3435,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 | ||||||
|
|
@@ -3447,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, | ||||||
|
|
@@ -3922,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), | ||||||
|
|
@@ -3935,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"))] | ||||||
|
|
@@ -7888,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) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The startup flag is taken on the first
Suggested change
Suggested test: a first Category: bug
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the startup marker until the system theme arrives. If the first Wait for an available system theme before consuming the matching marker. Preserve the project-ID and explicit-basemap guards.
|
||||||
| && 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)) { | ||||||
|
|
@@ -11497,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")]); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refresh the default after a theme command changes brightness.
When
ui.themeswitches Light to Dark, this assignment stores Paper beforerun_uichangesui.dark. The default remains Paper until another dispatch or the end oflogic().On the next frame,
relay.poll(&mut self.session)runs before that refresh. A relaymap.newtherefore creates Paper instead of Midnight, and the later refresh does not correct that map.Synchronize
new_map_basemapafter a successful theme change, before direct session consumers can run.