diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index c60f766b18..6e5aa48e9b 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -919,10 +919,13 @@ fn color_picker_dialog(app: &mut PhotocraftApp, p: &Value) -> Outcome { return err("need integer `parent` and string `effect` and `field`"); }; let stop = match p.get("stop") { - None | Some(Value::Null) => None, - Some(v) => match v.as_u64().and_then(|i| usize::try_from(i).ok()) {Some(i)=>Some(i),None=>return err("`stop` must be a non-negative integer")}, -}; -return match crate::layer_style::color_picker::open(app, parent, effect, field, stop) { + None | Some(Value::Null) => None, + Some(v) => match v.as_u64().and_then(|i| usize::try_from(i).ok()) { + Some(i) => Some(i), + None => return err("`stop` must be a non-negative integer"), + }, + }; + return match crate::layer_style::color_picker::open(app, parent, effect, field, stop) { Ok(id) => ok(json!({"dialog": id})), Err(error) => err(error), }; diff --git a/crates/ui-egui/src/dialogs/layer_style.rs b/crates/ui-egui/src/dialogs/layer_style.rs index 04c5c02c1e..6699f8336b 100644 --- a/crates/ui-egui/src/dialogs/layer_style.rs +++ b/crates/ui-egui/src/dialogs/layer_style.rs @@ -81,7 +81,9 @@ fn kind_of(e: &Effect) -> &'static str { fn defaults(kind: &str) -> Value { let mut p = photocraft_engine::layer_style::effect_defaults(kind); - if kind == "gradientOverlay" { gradient_field::from_to_to_stops(&mut p); } + if kind == "gradientOverlay" { + gradient_field::from_to_to_stops(&mut p); + } p } diff --git a/crates/ui-egui/src/dialogs/layer_style/gradient_field.rs b/crates/ui-egui/src/dialogs/layer_style/gradient_field.rs index 8273fcbde2..b657ef36ad 100644 --- a/crates/ui-egui/src/dialogs/layer_style/gradient_field.rs +++ b/crates/ui-egui/src/dialogs/layer_style/gradient_field.rs @@ -37,9 +37,12 @@ pub(super) fn stops_of(v: Option<&Value>) -> Option> { let t = s.get(0)?.as_f64()?; let value = s.get(1)?; let color = if let Some(hex) = value.as_str() { - let [r,g,b] = color_picker_ui::parse_hex(hex)?; Color::rgb(r,g,b) - } else {serde_json::from_value::(value.clone()).ok()?}; - (t.is_finite() && color.c.iter().all(|v| v.is_finite()) && color.alpha.is_finite()).then(|| (t.clamp(0.0,1.0) as f32,color)) + let [r, g, b] = color_picker_ui::parse_hex(hex)?; + Color::rgb(r, g, b) + } else { + serde_json::from_value::(value.clone()).ok()? + }; + (t.is_finite() && color.c.iter().all(|v| v.is_finite()) && color.alpha.is_finite()).then(|| (t.clamp(0.0, 1.0) as f32, color)) }) .collect(); if stops.len() < 2 { @@ -67,11 +70,16 @@ pub(super) fn opacity_of(v: Option<&Value>) -> Option> { } pub(super) fn stops_json(stops: &[(f32, Color)]) -> Value { - Value::Array(stops.iter().map(|(t, c)| { - let [r,g,b,_] = c.to_rgba8(); - let exact = Color::rgb(f32::from(r)/255.0,f32::from(g)/255.0,f32::from(b)/255.0); - if *c == exact {json!([t, super::hex(c)])} else {json!([t,c])} - }).collect()) + Value::Array( + stops + .iter() + .map(|(t, c)| { + let [r, g, b, _] = c.to_rgba8(); + let exact = Color::rgb(f32::from(r) / 255.0, f32::from(g) / 255.0, f32::from(b) / 255.0); + if *c == exact { json!([t, super::hex(c)]) } else { json!([t, c]) } + }) + .collect(), + ) } pub(super) fn opacity_json(os: &[(f32, f32)]) -> Value { @@ -171,7 +179,7 @@ pub(super) fn row(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map