Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Color panel state: still read Only Web Colors under its old web_only key (#6000)

Khawar Zamman Wanif89ce5ce073f
diff --git a/crates/ui-egui/src/color_panel_tests.rs b/crates/ui-egui/src/color_panel_tests.rs
index 65239d6a1..1152561d9 100644
--- a/crates/ui-egui/src/color_panel_tests.rs
+++ b/crates/ui-egui/src/color_panel_tests.rs
@@ -326,3 +326,12 @@ fn control_sets_the_mode_ramp_and_web_safe_ramp() {
assert_eq!(app.ui.color_panel, cp, "{bad}: nothing changes");
}
}
+
+/// Only Web Colors is `webOnly` now that the state is camelCase; state saved before still loads.
+#[test]
+fn web_only_reads_its_old_snake_case_key() {
+ let old: crate::state::ColorPanelState = serde_json::from_value(json!({"background": true, "web_only": true})).unwrap();
+ assert!(old.background && old.web_only);
+ let new = serde_json::to_value(old).unwrap();
+ assert_eq!((new.get("webOnly"), new.get("web_only")), (Some(&json!(true)), None));
+}
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index 07c49f909..8f1adf3ec 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -1054,8 +1054,9 @@ pub struct DockTabs {
pub struct ColorPanelState {
/// The panel edits the background colour (its chip was clicked), not the foreground.
pub background: bool,
- /// Color Picker › Only Web Colors, kept across opens like Photoshop (#4995).
- #[serde(default)]
+ /// Color Picker › Only Web Colors, kept across opens like Photoshop (#4995). `web_only` is
+ /// its name before the camelCase rename (#6000).
+ #[serde(default, alias = "web_only")]
pub web_only: bool,
/// What the panel shows, picked from its panel menu as in Photoshop (#6000).
pub mode: ColorPanelMode,