PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Keep the Color panel selected when switching themes (#3371) (#3433)
prekabrekif9e94aa53559
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rsindex 8937ea964..354f4d45d 100644--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@ -634,6 +634,9 @@ fn dispatch(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest)if let Some(m) = selection_mode {app.ui.selection_mode = m.min(3) as u8;}+ if let Some(k) = theme {+ app.set_theme(ctx, k);+ }if let Some(v) = dock_tabs {app.ui.dock_tabs = v;}@@ -671,9 +674,6 @@ fn dispatch(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest)app.ui.views[i].rotation = crate::rotate_view::wrap_deg(r as f32);}}- if let Some(k) = theme {- app.set_theme(ctx, k);- }if let Some(i) = brush_section {app.ui.brush_section = (i as usize).min(crate::brush_panel::SECTIONS.len() - 1);}@@ -1961,6 +1961,17 @@ mod tests {assert_eq!(call(&mut app, &ctx, "ui.set", json!({"brushSize": "large"}))["ok"], true);}+ #[test]+ fn ui_set_theme_keeps_explicit_dock_tab_indices() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ let ctx = egui::Context::default();+ for theme in ["adwaitaDark", "pro"] {+ let r = call(&mut app, &ctx, "ui.set", json!({"theme": theme, "dockTabs": {"color": 0}}));+ assert_eq!(r["ok"], true, "{r}");+ assert_eq!(app.ui.dock_tabs.color, 0, "{theme}: explicit tab index changed");+ }+ }+#[test]fn ui_set_color_panel_picks_the_edited_chip() {let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());diff --git a/crates/ui-egui/src/dock_tests.rs b/crates/ui-egui/src/dock_tests.rsindex 47623dff9..dddcce655 100644--- a/crates/ui-egui/src/dock_tests.rs+++ b/crates/ui-egui/src/dock_tests.rs@@ -638,6 +638,29 @@ fn is_pro(theme: ThemeKind) -> bool {theme.is_pro()}+#[test]+fn theme_switch_keeps_the_selected_color_group_panel() {+ use egui_kittest::kittest::Queryable;++ for theme in ThemeKind::ALL {+ for (tab, name) in Group::Color.tabs(true).iter().enumerate() {+ let (mut app, _, _) = app_with_layers();+ app.ui.dock_tabs.color = tab;+ let mut h = harness(app, vec2(1200.0, 900.0), ThemeKind::Pro);+ let ctx = h.ctx.clone();+ h.state_mut().set_theme(&ctx, theme);+ h.run_steps(4);+ assert_eq!(Group::Color.tabs(is_pro(theme)).get(h.state().ui.dock_tabs.color), Some(name), "{theme:?}");+ if *name == "Color" && !is_pro(theme) {+ assert!(h.query_by_label("Hue").is_some(), "{theme:?}: Color picker missing");+ }+ h.state_mut().set_theme(&ctx, ThemeKind::Pro);+ h.run_steps(4);+ assert_eq!(h.state().ui.dock_tabs.color, tab, "{theme:?}: switching back changed the panel");+ }+ }+}+/// Full app at `size` (1× scale) on a document with `n` layers named "Row 00", "Row 01", …fn app_harness_rows(size: egui::Vec2, theme: ThemeKind, n: usize) -> Harness<'static, PhotocraftApp> {let mut h = Harness::builder().with_size(size).with_max_steps(64).build_eframe(move |cc| {diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 1290f089c..8a90bacd6 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1806,6 +1806,12 @@ impl PhotocraftApp {}pub(crate) fn apply_theme(&mut self, ctx: &egui::Context, kind: theme::ThemeKind) {+ // Color and Swatches trade indices between Pro and Studio layouts.+ if let Some(selected) = dock::Group::Color.tabs(theme::Tokens::for_kind(self.ui.theme).pro).get(self.ui.dock_tabs.color)+ && let Some(tab) = dock::Group::Color.tabs(theme::Tokens::for_kind(kind).pro).iter().position(|name| name == selected)+ {+ self.ui.dock_tabs.color = tab;+ }self.ui.theme = kind;panel_docking::sync_visibility(self);theme::apply(ctx, kind);diff --git a/crates/ui-egui/tests/camera_raw_histogram.rs b/crates/ui-egui/tests/camera_raw_histogram.rsindex 26b1736a9..144522908 100644--- a/crates/ui-egui/tests/camera_raw_histogram.rs+++ b/crates/ui-egui/tests/camera_raw_histogram.rs@@ -1,6 +1,9 @@//! Camera Raw through the real app shell and its existing agent entry point.use egui::{Event, Modifiers, MouseWheelUnit, accesskit::Role, pos2, vec2};-use egui_kittest::{Harness, kittest::Queryable};+use egui_kittest::{+ Harness,+ kittest::{NodeT, Queryable},+};use photocraft_ui_egui::{PhotocraftApp, camera_raw_ui, control, theme::ThemeKind};use serde_json::{Value, json};@@ -109,8 +112,12 @@ fn settings_sections_group_existing_controls_without_rendering_or_document_editsh.run_steps(12);h.get_by_role_and_label(Role::Button, tr("Color")).click();h.run_steps(12);+ // The dock also has Saturation; query only the Camera Raw settings panel.+ let settings = std::iter::successors(Some(h.get_by_role_and_label(Role::Button, tr("Color"))), |node| node.parent())+ .find(|node| node.query_by_label(tr("Tone Histogram")).is_some())+ .expect("Camera Raw settings panel");for label in ["Temperature", "Tint", "Vibrance", "Saturation"] {- assert!(h.query_by_label(tr(label)).is_some(), "color control: {label}");+ assert!(settings.query_by_label(tr(label)).is_some(), "color control: {label}");}assert!(h.query_by_label(tr("Exposure")).is_none());h.get_by_role_and_label(Role::Button, tr("Color")).click();