From 7b7ad0bd0e2bbb0f6725291a82ea7f907fedf2b8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 23:07:01 -0800 Subject: [PATCH] Brush Options: test that a canceled Bristle slider drag leaves the brush as it was For each of the five Bristle sliders, a held drag ended with Escape restores the open dialog's field, and OK then keeps the brush and the undo history unchanged. A released drag is kept by OK in one undo step. --- .../src/dialogs/brush_options/tests.rs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/crates/ui-egui/src/dialogs/brush_options/tests.rs b/crates/ui-egui/src/dialogs/brush_options/tests.rs index 7e6fdf0952..a63d0cef53 100644 --- a/crates/ui-egui/src/dialogs/brush_options/tests.rs +++ b/crates/ui-egui/src/dialogs/brush_options/tests.rs @@ -362,6 +362,52 @@ fn canceled_pattern_scale_edits_do_not_reach_the_brush() { assert_eq!(panel.app().run("brush.get", json!({"name": "Diamonds"})).unwrap(), original); } +/// Bristle Brush Options' sliders: a held drag ended with Escape leaves the open dialog's field as it +/// opened, and OK then leaves the brush as it was; a released drag is kept by OK. +#[test] +fn canceled_bristle_slider_drags_do_not_reach_the_brush() { + use crate::tests::panel_harness::Panel; + use craft::ui::contract::Role; + use egui::{Key, Modifiers}; + + for (key, label, _) in BRISTLE { + let mut app = app(); + let params = json!({"length": 150.0, "density": 50.0, "thickness": 50.0, "opacity": 50.0, "stiffness": 50.0}); + app.run("brush.options", json!({"name": "Bristle Round", "params": params})).unwrap(); + let original = app.run("brush.get", json!({"name": "Bristle Round"})).unwrap(); + let undo = app.session.active().unwrap().history.undo.len(); + let mut panel = Panel::new(app, draw_hosted_options); + panel.room(egui::vec2(1000.0, 1000.0)); + open(&mut panel.app(), "Bristle Round"); + panel.frame(); + let initial = fields_of(&panel.app()).number(key).unwrap(); + panel.drag_hold_role(label, Role::SLIDER, egui::vec2(40.0, 0.0)); + assert_ne!(fields_of(&panel.app()).number(key), Some(initial), "the held drag previews another {key}"); + panel.key(Key::Escape, Modifiers::NONE); + panel.release(); + assert!(is_open(&panel.app())); + assert_eq!(fields_of(&panel.app()).number(key), Some(initial), "the canceled drag restores the opening {key}"); + panel.click("OK"); + panel.frame(); + assert!(!is_open(&panel.app())); + assert_eq!(panel.app().run("brush.get", json!({"name": "Bristle Round"})).unwrap(), original, "OK after a canceled {key} drag"); + assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo); + + open(&mut panel.app(), "Bristle Round"); + panel.frame(); + panel.drag_hold_role(label, Role::SLIDER, egui::vec2(40.0, 0.0)); + panel.release(); + let accepted = fields_of(&panel.app()).number(key).unwrap(); + assert_ne!(accepted, initial); + panel.click("OK"); + panel.frame(); + assert_eq!(panel.app().run("brush.get", json!({"name": "Bristle Round"})).unwrap()[key], accepted); + assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo + 1); + panel.app().run("edit.undo", json!({})).unwrap(); + assert_eq!(panel.app().run("brush.get", json!({"name": "Bristle Round"})).unwrap(), original); + } +} + /// What a step of the table expects at a JSON pointer of the saved brush. enum Expect { Is(Value),