PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Type: a scaled type layer keeps its size when the Character fields show it (#5717) (#5718)
David Mann8d8db22c94f8
diff --git a/crates/ui-egui/src/type_tool_tests.rs b/crates/ui-egui/src/type_tool_tests.rsindex 725d2890f..f56829c6d 100644--- a/crates/ui-egui/src/type_tool_tests.rs+++ b/crates/ui-egui/src/type_tool_tests.rs@@ -1545,6 +1545,26 @@ mod multi_layer_formatting {assert_eq!(text(h.state(), ids[1]).char_runs(), peer);}+ /// #5717: a layer scaled so its shown size or leading is past a field's range (2400 pt, or+ /// 0.08 pt) keeps it while the Character panel and the options bar only show it.+ #[test]+ fn showing_a_scaled_layer_past_the_size_range_does_not_change_it() {+ for (layer, scale) in [(0, 200.0), (1, 0.005)] {+ for properties in [true, false] {+ let (mut app, ids) = fixture();+ let id = ids[layer];+ app.run("type.edit", json!({"layer": id.0, "transform": [scale, 0.0, 0.0, scale, 0.0, 0.0]})).unwrap();+ selected(&mut app, &[id]);+ let before = text(&app, id).char_runs();+ let steps = app.session.active().unwrap().history.entries().len();+ let mut h = controls(app, properties);+ h.run_steps(3);+ assert_eq!(text(h.state(), id).char_runs(), before, "scale {scale}, properties {properties}");+ assert_eq!(h.state().session.active().unwrap().history.entries().len(), steps, "no history step");+ }+ }+ }+#[test]fn formatting_menus_isolate_the_edit_layer_and_range_but_honor_explicit_targets() {let (mut app, ids) = fixture();diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rsindex 9f2521a86..6e841292e 100644--- a/crates/ui-egui/src/widgets.rs+++ b/crates/ui-egui/src/widgets.rs@@ -824,6 +824,9 @@ fn number_edit(let mut resp = ui.add(egui::DragValue::new(value).range(range.clone())+ // Only edits are clamped (below): showing a value past the range, such as a type layer+ // scaled to 2400 pt in a 1296 pt field, must not change it (#5717).+ .clamp_existing_to_range(false)// A warp is an absolute-position jump. The scoped scrub below removes that jump..speed(if wrapped_drag { 0.0 } else { speed }).custom_formatter(move |v, _| match decimals {@@ -844,7 +847,12 @@ fn number_edit(}),);if wrap_drag {- crate::scrub_wrap::update(ui, &resp, value, before, range, speed, wrapping);+ crate::scrub_wrap::update(ui, &resp, value, before, range.clone(), speed, wrapping);+ }+ let (lo, hi) = (*range.start(), *range.end());+ // `f32::clamp` panics on a reversed or NaN range, which `DragValue::range` accepts.+ if *value != before && lo <= hi {+ *value = value.clamp(lo, hi);}resp.flags.set(egui::response::Flags::CHANGED, *value != before);resp@@ -2280,6 +2288,29 @@ mod tests {assert_eq!(*h.state(), (25.0, 3));}+ /// #5717: a value past the range shows as it is without reporting a change; an edit is clamped.+ #[test]+ fn value_field_keeps_a_shown_value_past_its_range_and_clamps_edits() {+ use egui_kittest::{Harness, kittest::Queryable};+ let mut h = Harness::builder().with_size(egui::vec2(300.0, 100.0)).build_ui_state(+ |ui, (v, changes): &mut (f32, u32)| {+ if super::value_field(ui, v, 0.1..=1296.0, "pt", 90.0).changed() {+ *changes += 1;+ }+ },+ (2400.0, 0),+ );+ h.run_steps(3);+ assert_eq!(*h.state(), (2400.0, 0), "showing it changes nothing");+ h.get_by_role(egui::accesskit::Role::SpinButton).click();+ h.run();+ h.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::A);+ h.event(egui::Event::Text("5000".into()));+ h.key_press(egui::Key::Enter);+ h.run();+ assert_eq!(h.state().0, 1296.0, "a typed value is clamped");+ }+#[test]fn value_field_applies_typed_arithmetic() {use egui::Key::{Enter, Tab};