mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 02:35:37 +01:00
Brushes: a canceled Pattern brush scale change does not reach the brush
The Scale and Width row that art and pattern brushes share read the slider's in-progress value, so a held drag ended with Escape left the dragged value in the dialog and rounded a fractional stored value. Main reads brush option sliders, fields and menus through landed() and committed() so a canceled or unfinished edit does not reach the brush (#9752); the row now does the same and keeps the exact opening value. The new test drags Pattern Brush Options' Scale slider, cancels with Escape while the dialog stays open and checks the field still holds the opening 100.25 %, then checks a released drag is kept by OK. The Art brush width test now finds the mode menu by its name, Width: Mode.
This commit is contained in:
1 parent
6fcd193186
commit
40eaf74680
2 files changed
+54
-3
No files matched your search
@@ -334,8 +334,9 @@ fn pen_size_row(size: PenSize) -> Param {
|
||||
Row::new()
|
||||
.show(ui, |ui, _| {
|
||||
let slid = Slider::new(Bind::given(clamped(f, key, range)), range.0..=range.1).step(1.0).label(label).id_salt(key).show(ui);
|
||||
if let Some(value) = slid.value() {
|
||||
f.set(key, value.round());
|
||||
if let Some(value) = slid.events.landed() {
|
||||
// The slider quantizes new edits; Cancel restores the exact opening value.
|
||||
f.set(key, *value);
|
||||
}
|
||||
number_cell(ui, f, max_key, max_label, range, UnitKind::Percent, mode.follows_pen());
|
||||
id_select(ui, f, mode_key, mode_label, &entries, mode.id().to_string());
|
||||
|
||||
@@ -186,7 +186,7 @@ fn canceled_art_width_drag_restores_the_opening_width() {
|
||||
let initial = fields_of(&panel.app()).number("width").unwrap();
|
||||
assert_eq!(initial, 100.25, "Cancel must preserve a valid fractional stored width");
|
||||
let mode = fields_of(&panel.app()).text("widthMode").map(str::to_owned);
|
||||
panel.click_role("Width", Role::COMBO_BOX);
|
||||
panel.click_role("Width: Mode", Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
assert_eq!(fields_of(&panel.app()).text("widthMode").map(str::to_owned), mode);
|
||||
@@ -214,6 +214,56 @@ fn canceled_art_width_drag_restores_the_opening_width() {
|
||||
assert_eq!(panel.app().run("brush.get", json!({"name": "Arrow"})).unwrap(), original);
|
||||
}
|
||||
|
||||
/// Pattern Brush Options' Scale row: a held drag ended with Escape and a mode menu closed with
|
||||
/// Escape leave the open dialog's fields as they opened, and Cancel leaves the brush as it was; a
|
||||
/// released drag is kept by OK.
|
||||
#[test]
|
||||
fn canceled_pattern_scale_edits_do_not_reach_the_brush() {
|
||||
use crate::tests::panel_harness::Panel;
|
||||
use craft::ui::contract::Role;
|
||||
use egui::{Key, Modifiers};
|
||||
|
||||
let mut app = app();
|
||||
app.run("brush.options", json!({"name": "Diamonds", "params": {"scale": 100.25}})).unwrap();
|
||||
let original = app.run("brush.get", json!({"name": "Diamonds"})).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(), "Diamonds");
|
||||
panel.frame();
|
||||
let initial = fields_of(&panel.app()).number("scale").unwrap();
|
||||
assert_eq!(initial, 100.25, "Cancel must preserve a valid fractional stored scale");
|
||||
let mode = fields_of(&panel.app()).text("scaleMode").map(str::to_owned);
|
||||
panel.click_role("Scale: Mode", Role::COMBO_BOX);
|
||||
panel.key(Key::ArrowDown, Modifiers::NONE);
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
assert!(is_open(&panel.app()));
|
||||
assert_eq!(fields_of(&panel.app()).text("scaleMode").map(str::to_owned), mode);
|
||||
panel.drag_hold_role("Scale", Role::SLIDER, egui::vec2(40.0, 0.0));
|
||||
assert_ne!(fields_of(&panel.app()).number("scale"), Some(initial), "the held drag previews another scale");
|
||||
panel.key(Key::Escape, Modifiers::NONE);
|
||||
panel.release();
|
||||
assert!(is_open(&panel.app()));
|
||||
assert_eq!(fields_of(&panel.app()).number("scale"), Some(initial), "the canceled drag restores the opening scale");
|
||||
panel.click("Cancel");
|
||||
panel.frame();
|
||||
assert_eq!(panel.app().run("brush.get", json!({"name": "Diamonds"})).unwrap(), original);
|
||||
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo);
|
||||
|
||||
open(&mut panel.app(), "Diamonds");
|
||||
panel.frame();
|
||||
panel.drag_hold_role("Scale", Role::SLIDER, egui::vec2(40.0, 0.0));
|
||||
panel.release();
|
||||
let accepted = fields_of(&panel.app()).number("scale").unwrap();
|
||||
assert_ne!(accepted, initial);
|
||||
panel.click("OK");
|
||||
panel.frame();
|
||||
assert_eq!(panel.app().run("brush.get", json!({"name": "Diamonds"})).unwrap()["scale"], 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": "Diamonds"})).unwrap(), original);
|
||||
}
|
||||
|
||||
/// What a step of the table expects at a JSON pointer of the saved brush.
|
||||
enum Expect {
|
||||
Is(Value),
|
||||
|
||||
Reference in new issue
Block a user