From 4dc5bffdfbfb09a017f35c12b484301fcf044876 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 5 Jun 2020 14:02:29 +0200 Subject: Draft draggable and graphics logic for `TitleBar` --- native/src/widget/pane_grid.rs | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'native/src/widget/pane_grid.rs') diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index bf9c76fd..c0c3839e 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -30,7 +30,7 @@ pub use title_bar::TitleBar; use crate::{ container, keyboard, layout, mouse, row, Clipboard, Element, Event, Hasher, - Layout, Length, Point, Size, Widget, + Layout, Length, Point, Rectangle, Size, Widget, }; /// A collection of panes distributed using either vertical or horizontal splits @@ -427,17 +427,18 @@ where clicked_region.next() { match &self.on_drag { - Some(on_drag) - if content.is_over_drag_target( - layout, - cursor_position, - ) => - { - self.state.pick_pane(pane); - - messages.push(on_drag(DragEvent::Picked { - pane: *pane, - })); + Some(on_drag) => { + if let Some(origin) = + content.drag_origin(layout, cursor_position) + { + self.state.pick_pane(pane, origin); + + messages.push(on_drag(DragEvent::Picked { + pane: *pane, + })); + } else { + self.state.focus(pane); + } } _ => { self.state.focus(pane); @@ -448,7 +449,7 @@ where } } mouse::Event::ButtonReleased(mouse::Button::Left) => { - if let Some(pane) = self.state.picked_pane() { + if let Some((pane, _)) = self.state.picked_pane() { self.state.focus(&pane); if let Some(on_drag) = &self.on_drag { @@ -657,7 +658,7 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { &mut self, defaults: &Self::Defaults, content: &[(Pane, Content<'_, Message, Self>)], - dragging: Option, + dragging: Option<(Pane, Point)>, resizing: Option, layout: Layout<'_>, cursor_position: Point, @@ -676,6 +677,8 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { fn draw_pane( &mut self, defaults: &Self::Defaults, + bounds: Rectangle, + style: &Self::Style, title_bar: Option<(&TitleBar<'_, Message, Self>, Layout<'_>)>, body: (&Element<'_, Message, Self>, Layout<'_>), cursor_position: Point, @@ -684,6 +687,7 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { fn draw_title_bar( &mut self, defaults: &Self::Defaults, + bounds: Rectangle, style: &Self::Style, title: (&Element<'_, Message, Self>, Layout<'_>), controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>, -- cgit