diff options
author | 2021-10-25 16:16:35 +0700 | |
---|---|---|
committer | 2021-10-25 16:35:02 +0700 | |
commit | 4a11cbd99445338619dfaf1f327dbc25b2983cb7 (patch) | |
tree | 254598ff97f17cb33e44bd1402323d3b6892cb6b /native/src/widget/pane_grid.rs | |
parent | 41394b4e90a81a43c796c070e706e6aa4d8652bc (diff) | |
download | iced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.tar.gz iced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.tar.bz2 iced-4a11cbd99445338619dfaf1f327dbc25b2983cb7.zip |
Implement `Widget::mouse_interaction` for `PaneGrid`
... and fix rendering of drag interaction in `PaneGrid` by
introducing an explicit `with_translation` method to `Renderer`
and simplifying the `with_layer` and `Clip` primitive.
Diffstat (limited to 'native/src/widget/pane_grid.rs')
-rw-r--r-- | native/src/widget/pane_grid.rs | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index cb386959..5f0e73e4 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -471,6 +471,33 @@ where .fold(event_status, event::Status::merge) } + fn mouse_interaction( + &self, + layout: Layout<'_>, + viewport: &Rectangle, + cursor_position: Point, + ) -> mouse::Interaction { + if self.state.picked_pane().is_some() { + return mouse::Interaction::Grab; + } + + if let Some((_, axis)) = self.state.picked_split() { + return match axis { + Axis::Horizontal => mouse::Interaction::ResizingHorizontally, + Axis::Vertical => mouse::Interaction::ResizingVertically, + }; + } + + self.elements + .iter() + .zip(layout.children()) + .map(|((_pane, content), layout)| { + content.mouse_interaction(layout, viewport, cursor_position) + }) + .max() + .unwrap_or_default() + } + fn draw( &self, renderer: &mut Renderer, @@ -543,22 +570,22 @@ where Some((dragging, origin)) if *id == dragging => { let bounds = layout.bounds(); - renderer.with_layer( - Rectangle { - x: cursor_position.x - origin.x, - y: cursor_position.y - origin.y, - width: bounds.width + 0.5, - height: bounds.height + 0.5, - }, - Vector::new(0, 0), + renderer.with_translation( + cursor_position + - Point::new( + bounds.x + origin.x, + bounds.y + origin.y, + ), |renderer| { - pane.draw( - renderer, - style, - layout, - pane_cursor_position, - viewport, - ); + renderer.with_layer(bounds, |renderer| { + pane.draw( + renderer, + style, + layout, + pane_cursor_position, + viewport, + ); + }); }, ); } |