Merge pull request #10202 from dotCooCoo/fix/fidelity-fine-steps

Tool Options: the Fidelity slider's keys and wheel step finely at the Accurate end
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-03 07:20:38 -08:00
commit 9a3f2dcae1
2 files changed
+40 -1

No files matched your search

+3 -1
View File
@@ -134,7 +134,8 @@ pub(crate) fn fidelity_field(ui: &mut Ui, id: &str, v: f64, tool: &str) -> EditE
}
/// The Fidelity row: a logarithmic slider from the tool's lowest Fidelity to [`FIDELITY_MAX`] with the field at its
/// end, and Accurate and Smooth under the slider's ends.
/// end, and Accurate and Smooth under the slider's ends. The slider's keys and wheel step by [`fidelity_step`], as the
/// field's do.
fn fidelity_row(ui: &mut Ui, fields: &mut DialogFields, tool: &str) -> Response {
let min = vectorcraft_tools::draw2::min_fidelity(tool);
let v = fields.number("fidelity").unwrap_or(1.5);
@@ -142,6 +143,7 @@ fn fidelity_row(ui: &mut Ui, fields: &mut DialogFields, tool: &str) -> Response
let shown = Row::new().show(ui, |ui, _| {
let slid = Slider::new(Bind::given(v), min..=FIDELITY_MAX)
.scale(SliderScale::Log)
.stepper(|v, dir, steps| fidelity_step(v, f64::from(dir) * steps))
.marks_labelled([(min, tl!("Accurate")), (FIDELITY_MAX, tl!("Smooth"))])
.label(tl!("Fidelity"))
.id_salt("fidelity-slider")
@@ -422,6 +422,43 @@ fn draft_fidelity(panel: &crate::tests::panel_harness::Panel) -> Option<f64> {
panel.app().dialogs().and_then(|d| d.with(|host| host.get::<HostedParamDialog>().and_then(|dialog| dialog.fields().number("fidelity"))))
}
/// The Fidelity slider of every freehand tool steps through the field's values: an arrow key takes the next hundredth
/// at the Accurate end, Shift with an arrow multiplies by ten, and a wheel notch takes one step back.
#[test]
fn the_fidelity_slider_keys_and_wheel_step_finely_at_the_low_end() {
use craft::ui::contract::Role;
use egui::{Key, Modifiers, vec2};
for tool in ["pencil", "paintbrush", "smooth", "blobBrush"] {
let min = vectorcraft_tools::draw2::min_fidelity(tool);
let mut app = app();
app.run("tool.setOption", json!({"tool": tool, "values": {"fidelity": min}})).unwrap();
let mut panel = crate::tests::panel_harness::Panel::new(app, crate::tests::picks::dialogs);
panel.room(vec2(1000.0, 1200.0));
crate::toolbar::open_options(&mut panel.app(), tool).unwrap();
panel.frame();
assert_eq!(draft_fidelity(&panel), Some(min), "{tool}");
// The field comes after the slider, so Shift+Tab from the field gives the slider the focus.
panel.click_role("Fidelity", Role::SPIN_BUTTON);
panel.key(Key::Tab, Modifiers::SHIFT);
let at = |hundredths: f64| fidelity_round(min + hundredths / 100.0);
panel.key(Key::ArrowRight, Modifiers::NONE);
assert_eq!(draft_fidelity(&panel), Some(at(1.0)), "{tool}: an arrow takes the next hundredth");
panel.key(Key::ArrowRight, Modifiers::NONE);
assert_eq!(draft_fidelity(&panel), Some(at(2.0)), "{tool}");
panel.key(Key::ArrowRight, Modifiers::SHIFT);
assert_eq!(draft_fidelity(&panel), Some(fidelity_round(at(2.0) * 10.0)), "{tool}: Shift multiplies by ten");
panel.key(Key::ArrowLeft, Modifiers::NONE);
assert_eq!(draft_fidelity(&panel), Some(fidelity_step(fidelity_round(at(2.0) * 10.0), -1.0)), "{tool}");
let before = draft_fidelity(&panel).unwrap();
let thumb = panel.rect_role("Fidelity", Role::SLIDER).center();
panel.frame_with(vec![egui::Event::PointerMoved(thumb)]);
panel.frame_with(vec![craft::ui::testing::pointer::wheel_lines(-1.0)]);
panel.frame();
assert_eq!(draft_fidelity(&panel), Some(fidelity_step(before, -1.0)), "{tool}: a wheel notch takes one step");
assert_eq!(panel.app().session.tool_options_of(tool)["fidelity"].as_f64(), Some(min), "{tool}: the tool changes only on OK");
}
}
/// The Smooth tool's Fidelity slider and field: a drag or a typed value that Escape cancels leaves the dialog's Fidelity
/// and the tool's as they were; a finished drag or a typed value left with Tab sets the dialog's, and OK sets the tool's.
#[test]