fix(format): Reflection None clears after another preset (#1356)

The effect sliders rounded 55.000000000000007 to 55 and read that as a change,
so each frame re-added the reflection the None button had just cleared.
This commit is contained in:
Harrison Booth
2026-10-26 17:29:31 -05:00
parent 27009cd941
commit 5a28760b1e
3 changed files with 51 additions and 0 deletions
+2
View File
@@ -3571,6 +3571,8 @@ mod ime_tests;
#[cfg(test)]
mod last_color_tests;
#[cfg(test)]
mod reflection_pane_tests;
#[cfg(test)]
mod replacefonts_tests;
#[cfg(test)]
mod reuse_picker_tests;
+6
View File
@@ -658,8 +658,14 @@ fn fx_slider(
} else {
ui.data_mut(|d| d.remove::<f64>(sid));
}
// The slider rounds to whole numbers, which reads as a change for a value such as 55.000000000000007;
// acting on it would re-add an effect the pane just cleared.
let moved = v.round() != value.round();
if r.drag_stopped() || r.lost_focus() || (r.changed() && !r.dragged()) {
ui.data_mut(|d| d.remove::<f64>(sid));
if !moved {
return;
}
run(app, "shape.effects", json!({key: {prop: v * scale}}));
}
});
@@ -0,0 +1,43 @@
//! Format Shape ▸ Effects (#1356): Reflection "None" clears the effect after another preset.
#![allow(clippy::unwrap_used, clippy::expect_used)]
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use serde_json::json;
use crate::{Services, SlideApp};
use deckcraft_engine::Session;
fn has_reflection(h: &Harness<'_, SlideApp>) -> bool {
let st = h.state().session.active().unwrap();
let id = *st.selection.shapes.first().unwrap();
st.shape(id).unwrap().effects.as_ref().is_some_and(|e| e.reflection.is_some())
}
#[test]
fn reflection_none_clears_after_a_second_preset() {
let mut s = Session::with_new();
s.execute("slide.new", &json!({"layout": "blank"})).unwrap();
let id = s.execute("shape.insert", &json!({"preset": "rect", "rect": [72.0, 36.0, 144.0, 108.0]})).unwrap()["id"].as_u64().unwrap();
s.execute("edit.select", &json!({"ids": [id]})).unwrap();
let mut app = SlideApp::new(s, Services::default());
app.ui.pane = Some("format".into());
app.ui.format_tab = "effects".into();
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state(
|ui, app: &mut SlideApp| {
app.logic(ui.ctx());
app.ui(ui);
},
app,
);
h.run_steps(3);
// The Shadow row has a "None" too; Reflection's is the later one.
for preset in ["Tight", "Half", "Full"] {
h.get_by_label(preset).click();
h.run_steps(4);
assert!(has_reflection(&h), "{preset} adds a reflection");
}
h.get_all_by_label("None").last().unwrap().click();
h.run_steps(4);
assert!(!has_reflection(&h), "None clears the reflection");
}