From 7f849e50dbaba96ba874ba85540745ac8aa99cf5 Mon Sep 17 00:00:00 2001 From: Aleksander Helgaker Date: Mon, 9 Nov 2026 01:11:49 +0100 Subject: [PATCH] Fix `Resize` corner resizing a direction that isn't resizable (#25) With `.resizable([false, true])`, dragging a `Resize`'s corner still changed its width, because the corner set the size in both directions from the pointer. A direction that isn't resizable now keeps its size. On this line the lock comes after E9 mirrors the size for a grip on the left, so it holds with the grip on either side, and the test drags the corner in both layouts. Upstream: emilk/egui#8852. Co-authored-by: Claude Opus 5.5 --- crates/egui/src/containers/resize.rs | 9 +++- crates/egui_kittest/tests/regression_tests.rs | 50 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/crates/egui/src/containers/resize.rs b/crates/egui/src/containers/resize.rs index 0945f247..ecd4c385 100644 --- a/crates/egui/src/containers/resize.rs +++ b/crates/egui/src/containers/resize.rs @@ -276,7 +276,14 @@ impl Resize { if grip_on_left { size.x = -size.x; } - user_requested_size = Some(size + 0.5 * corner_response.rect.size()); + size += 0.5 * corner_response.rect.size(); + // The corner only resizes the directions that are resizable. + for d in 0..2 { + if !self.resizable[d] { + size[d] = state.desired_size[d]; + } + } + user_requested_size = Some(size); } let is_actively_resizing = user_requested_size.is_some(); diff --git a/crates/egui_kittest/tests/regression_tests.rs b/crates/egui_kittest/tests/regression_tests.rs index 284288bf..72e03854 100644 --- a/crates/egui_kittest/tests/regression_tests.rs +++ b/crates/egui_kittest/tests/regression_tests.rs @@ -1070,3 +1070,53 @@ pub fn scene_with_zero_rect_and_unbounded_zoom_should_not_produce_nan() { "scene_rect: {scene_rect:?}" ); } + +/// Dragging the corner of a `Resize` changes only the directions that are resizable, with the +/// grip at the bottom-right and, in a right-to-left layout, at the bottom-left. +#[test] +fn resize_corner_drag_keeps_a_direction_that_is_not_resizable() { + for right_to_left in [false, true] { + let mut harness = Harness::new_ui_state( + move |ui, inner: &mut Rect| { + ui.style_mut().right_to_left = right_to_left; + egui::Resize::default() + .resizable([false, true]) + .default_size([200.0, 100.0]) + .show(ui, |ui| *inner = ui.max_rect()); + }, + Rect::NOTHING, + ); + harness.run(); + let before = *harness.state(); + + let corner = Vec2::splat(harness.ctx.global_style().visuals.resize_corner_size); + let (grab, drag) = if right_to_left { + ( + before.left_bottom() + Vec2::new(0.5 * corner.x, -0.5 * corner.y), + Vec2::new(-60.0, 40.0), + ) + } else { + (before.max - 0.5 * corner, Vec2::new(60.0, 40.0)) + }; + harness.hover_at(grab); + harness.run(); + harness.drag_at(grab); + harness.run(); + harness.hover_at(grab + drag); + harness.run(); + harness.drop_at(grab + drag); + harness.run(); + let after = *harness.state(); + + assert_eq!( + after.height(), + before.height() + drag.y, + "the height follows the drag (right_to_left: {right_to_left})" + ); + assert_eq!( + after.width(), + before.width(), + "the width stays (right_to_left: {right_to_left})" + ); + } +}