Fix #3370: each step stops at the bounds, so a step back in the same frame starts from there

Review follow-up (CodeRabbit): step_value clamped once after all of a
frame's steps, so at the lower bound a step down then a step up in the
same frame left the field at the bound. Each step is now clamped as it is
applied. The Stroke panel test steps down and up in one frame at each
bound and expects one step above it; it fails without the change.
This commit is contained in:
Taha-Mahmoodi
2026-10-22 18:56:33 +07:00
committed by bflatastic
parent 28ac044c74
commit cc499d7e8e
2 changed files with 7 additions and 0 deletions
+5
View File
@@ -642,6 +642,11 @@ mod tests {
let texts = frame(&mut app, vec![]);
assert_eq!(stroke(&app)[which], low, "{shown}: {:?}", stroke(&app));
assert!(texts.iter().any(|(t, _)| t == after), "{shown} → {after}: {texts:?}");
// At the bound, a step down and a step up in one frame end one step above it.
let key = |key| Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE };
frame(&mut app, vec![key(egui::Key::ArrowDown), key(egui::Key::ArrowUp)]);
let texts = frame(&mut app, vec![]);
assert!(texts.iter().any(|(t, _)| t == shown), "{after}, down and up → {shown}: {texts:?}");
}
}
}
+2
View File
@@ -390,6 +390,8 @@ fn step_value(
let mut v = read(buf)?;
for (mods, size, n) in steps {
v = if mods == egui::Modifiers::SHIFT { v + size * n } else { step_to_multiple(v, size, n) };
// Each step stops at the bounds, so a step back in the same frame starts from there.
v = within(v, bounds);
}
// Rounded as fields show it, within the field's bounds.
let v = within(round_to(v, STEP_DECIMALS), bounds);