summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-20 11:53:08 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2020-03-20 11:53:08 +0100
commit33f33ed4e32932175f1a77a0d8b59b81380ccf74 (patch)
tree380bbe0823e10f5aa2bc8677000053b0b024137a /native
parent31aaf207d6772e2ef332bf523cde262cac118d1a (diff)
downloadiced-33f33ed4e32932175f1a77a0d8b59b81380ccf74.tar.gz
iced-33f33ed4e32932175f1a77a0d8b59b81380ccf74.tar.bz2
iced-33f33ed4e32932175f1a77a0d8b59b81380ccf74.zip
Check cursor is in-bounds before resizing panes
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/pane_grid.rs83
1 files changed, 44 insertions, 39 deletions
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs
index 5ced6610..5b609b56 100644
--- a/native/src/widget/pane_grid.rs
+++ b/native/src/widget/pane_grid.rs
@@ -467,48 +467,53 @@ where
&& self.pressed_modifiers.matches(self.modifier_keys) =>
{
let bounds = layout.bounds();
- let relative_cursor = Point::new(
- cursor_position.x - bounds.x,
- cursor_position.y - bounds.y,
- );
-
- let splits = self.state.splits(
- f32::from(self.spacing),
- Size::new(bounds.width, bounds.height),
- );
- let mut sorted_splits: Vec<_> = splits
- .iter()
- .filter(|(_, (axis, rectangle, _))| match axis {
- Axis::Horizontal => {
- relative_cursor.x > rectangle.x
- && relative_cursor.x
- < rectangle.x + rectangle.width
- }
- Axis::Vertical => {
- relative_cursor.y > rectangle.y
- && relative_cursor.y
- < rectangle.y + rectangle.height
- }
- })
- .collect();
-
- sorted_splits.sort_by_key(|(_, (axis, rectangle, ratio))| {
- let distance = match axis {
- Axis::Horizontal => (relative_cursor.y
- - (rectangle.y + rectangle.height * ratio))
- .abs(),
- Axis::Vertical => (relative_cursor.x
- - (rectangle.x + rectangle.width * ratio))
- .abs(),
- };
+ if bounds.contains(cursor_position) {
+ let relative_cursor = Point::new(
+ cursor_position.x - bounds.x,
+ cursor_position.y - bounds.y,
+ );
+
+ let splits = self.state.splits(
+ f32::from(self.spacing),
+ Size::new(bounds.width, bounds.height),
+ );
+
+ let mut sorted_splits: Vec<_> = splits
+ .iter()
+ .filter(|(_, (axis, rectangle, _))| match axis {
+ Axis::Horizontal => {
+ relative_cursor.x > rectangle.x
+ && relative_cursor.x
+ < rectangle.x + rectangle.width
+ }
+ Axis::Vertical => {
+ relative_cursor.y > rectangle.y
+ && relative_cursor.y
+ < rectangle.y + rectangle.height
+ }
+ })
+ .collect();
+
+ sorted_splits.sort_by_key(
+ |(_, (axis, rectangle, ratio))| {
+ let distance = match axis {
+ Axis::Horizontal => (relative_cursor.y
+ - (rectangle.y + rectangle.height * ratio))
+ .abs(),
+ Axis::Vertical => (relative_cursor.x
+ - (rectangle.x + rectangle.width * ratio))
+ .abs(),
+ };
- distance.round() as u32
- });
+ distance.round() as u32
+ },
+ );
- if let Some((split, (axis, _, _))) = sorted_splits.first() {
- self.state.pick_split(split, *axis);
- self.trigger_resize(layout, cursor_position, messages);
+ if let Some((split, (axis, _, _))) = sorted_splits.first() {
+ self.state.pick_split(split, *axis);
+ self.trigger_resize(layout, cursor_position, messages);
+ }
}
}
Event::Mouse(mouse::Event::Input {