From f54590d7adac611db84b88cbcbf4f56c7542039c Mon Sep 17 00:00:00 2001 From: Clark Moody Date: Tue, 8 Dec 2020 18:47:01 -0600 Subject: Replace TitleBar string title with generic Content --- native/src/widget/pane_grid.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 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 ff19cbc2..85ef021f 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -586,18 +586,15 @@ pub trait Renderer: /// It receives: /// - the bounds, style of the [`TitleBar`] /// - the style of the [`TitleBar`] - /// - the title of the [`TitleBar`] with its size, font, and bounds - /// - the controls of the [`TitleBar`] with their [`Layout`+, if any + /// - the content of the [`TitleBar`] with its layout + /// - the controls of the [`TitleBar`] with their [`Layout`], if any /// - the cursor position fn draw_title_bar( &mut self, defaults: &Self::Defaults, bounds: Rectangle, style: &Self::Style, - title: &str, - title_size: u16, - title_font: Self::Font, - title_bounds: Rectangle, + content: (&Element<'_, Message, Self>, Layout<'_>), controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>, cursor_position: Point, ) -> Self::Output; -- cgit From f2c2f3fc7588054417a0c44d3890defa976c5f61 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 22 Dec 2020 14:44:44 +0100 Subject: Remove unnecessary `text::Renderer` bound for `PaneGrid` This is no longer necessary, as we do not render text directly anymore. --- native/src/widget/pane_grid.rs | 5 +---- 1 file changed, 1 insertion(+), 4 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 85ef021f..9cf8bc34 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -33,7 +33,6 @@ use crate::layout; use crate::mouse; use crate::overlay; use crate::row; -use crate::text; use crate::{ Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector, Widget, @@ -543,9 +542,7 @@ where /// able to use a [`PaneGrid`] in your user interface. /// /// [renderer]: crate::renderer -pub trait Renderer: - crate::Renderer + container::Renderer + text::Renderer + Sized -{ +pub trait Renderer: crate::Renderer + container::Renderer + Sized { /// Draws a [`PaneGrid`]. /// /// It receives: -- cgit From a7bb7bb2eaaae5a016721788fcaf03c4c7413acd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Fri, 1 Jan 2021 15:28:38 +0100 Subject: Implement split highlight on hover for `PaneGrid` --- native/src/widget/pane_grid.rs | 58 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 10 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 9cf8bc34..da3e25fd 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -97,6 +97,7 @@ pub struct PaneGrid<'a, Message, Renderer: self::Renderer> { on_click: Option Message + 'a>>, on_drag: Option Message + 'a>>, on_resize: Option<(u16, Box Message + 'a>)>, + style: ::Style, } impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> @@ -128,6 +129,7 @@ where on_click: None, on_drag: None, on_resize: None, + style: Default::default(), } } @@ -185,6 +187,15 @@ where self.on_resize = Some((leeway, Box::new(f))); self } + + /// Sets the style of the [`PaneGrid`]. + pub fn style( + mut self, + style: impl Into<::Style>, + ) -> Self { + self.style = style.into(); + self + } } impl<'a, Message, Renderer> PaneGrid<'a, Message, Renderer> @@ -382,7 +393,7 @@ where relative_cursor, ); - if let Some((split, axis)) = clicked_split { + if let Some((split, axis, _)) = clicked_split { self.state.pick_split(&split, axis); } else { self.click_pane( @@ -475,6 +486,23 @@ where let picked_split = self .state .picked_split() + .and_then(|(split, axis)| { + let bounds = layout.bounds(); + + let splits = self + .state + .split_regions(f32::from(self.spacing), bounds.size()); + + let (_axis, region, ratio) = splits.get(&split)?; + + let region = axis.split_line_bounds( + *region, + *ratio, + f32::from(self.spacing), + ); + + Some((axis, region + Vector::new(bounds.x, bounds.y), true)) + }) .or_else(|| match self.on_resize { Some((leeway, _)) => { let bounds = layout.bounds(); @@ -488,15 +516,20 @@ where .state .split_regions(f32::from(self.spacing), bounds.size()); - hovered_split( + let (_split, axis, region) = hovered_split( splits.iter(), f32::from(self.spacing + leeway), relative_cursor, - ) + )?; + + Some(( + axis, + region + Vector::new(bounds.x, bounds.y), + false, + )) } None => None, - }) - .map(|(_, axis)| axis); + }); self::Renderer::draw( renderer, @@ -505,6 +538,7 @@ where self.state.picked_pane(), picked_split, layout, + &self.style, cursor_position, ) } @@ -543,6 +577,9 @@ where /// /// [renderer]: crate::renderer pub trait Renderer: crate::Renderer + container::Renderer + Sized { + /// The style supported by this renderer. + type Style: Default; + /// Draws a [`PaneGrid`]. /// /// It receives: @@ -556,8 +593,9 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { defaults: &Self::Defaults, content: &[(Pane, Content<'_, Message, Self>)], dragging: Option<(Pane, Point)>, - resizing: Option, + resizing: Option<(Axis, Rectangle, bool)>, layout: Layout<'_>, + style: &::Style, cursor_position: Point, ) -> Self::Output; @@ -572,7 +610,7 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { &mut self, defaults: &Self::Defaults, bounds: Rectangle, - style: &Self::Style, + style: &::Style, title_bar: Option<(&TitleBar<'_, Message, Self>, Layout<'_>)>, body: (&Element<'_, Message, Self>, Layout<'_>), cursor_position: Point, @@ -590,7 +628,7 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { &mut self, defaults: &Self::Defaults, bounds: Rectangle, - style: &Self::Style, + style: &::Style, content: (&Element<'_, Message, Self>, Layout<'_>), controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>, cursor_position: Point, @@ -617,14 +655,14 @@ fn hovered_split<'a>( splits: impl Iterator, spacing: f32, cursor_position: Point, -) -> Option<(Split, Axis)> { +) -> Option<(Split, Axis, Rectangle)> { splits .filter_map(|(split, (axis, region, ratio))| { let bounds = axis.split_line_bounds(*region, *ratio, f32::from(spacing)); if bounds.contains(cursor_position) { - Some((*split, *axis)) + Some((*split, *axis, bounds)) } else { None } -- cgit From 9e453843b26f2f73228316334298a4c608b2f050 Mon Sep 17 00:00:00 2001 From: anunge Date: Fri, 12 Feb 2021 21:52:20 +0200 Subject: Touch support for `PaneGrid` and `PickList` (#650) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * touch events properly parsed and converted to logical size, button working * scrolling with a nice touch * fixed application state level touch cursor. panel_grid is touchable now. * format glicthes fixes * format glitches * tight format * fixed pane grid * fixing with upstream * Remove unused `touch` module from `iced_core` * Remove unused `crate::text` import in `iced_native` * Remove redundant match branch in `iced_winit` * Keep removed line break in `UserInterface::update` * Compute `text_size` only when bounds contains cursor in `overlay::menu` Co-authored-by: Héctor Ramón Jiménez --- native/src/widget/pane_grid.rs | 131 ++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 67 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 da3e25fd..c6fe4b60 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -33,6 +33,7 @@ use crate::layout; use crate::mouse; use crate::overlay; use crate::row; +use crate::touch; use crate::{ Clipboard, Element, Hasher, Layout, Length, Point, Rectangle, Size, Vector, Widget, @@ -368,42 +369,34 @@ where let mut event_status = event::Status::Ignored; match event { - Event::Mouse(mouse_event) => match mouse_event { - mouse::Event::ButtonPressed(mouse::Button::Left) => { - let bounds = layout.bounds(); - - if bounds.contains(cursor_position) { - event_status = event::Status::Captured; - - match self.on_resize { - Some((leeway, _)) => { - let relative_cursor = Point::new( - cursor_position.x - bounds.x, - cursor_position.y - bounds.y, - ); - - let splits = self.state.split_regions( - f32::from(self.spacing), - Size::new(bounds.width, bounds.height), - ); - - let clicked_split = hovered_split( - splits.iter(), - f32::from(self.spacing + leeway), - relative_cursor, - ); + Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) + | Event::Touch(touch::Event::FingerPressed { .. }) => { + let bounds = layout.bounds(); - if let Some((split, axis, _)) = clicked_split { - self.state.pick_split(&split, axis); - } else { - self.click_pane( - layout, - cursor_position, - messages, - ); - } - } - None => { + if bounds.contains(cursor_position) { + event_status = event::Status::Captured; + + match self.on_resize { + Some((leeway, _)) => { + let relative_cursor = Point::new( + cursor_position.x - bounds.x, + cursor_position.y - bounds.y, + ); + + let splits = self.state.split_regions( + f32::from(self.spacing), + Size::new(bounds.width, bounds.height), + ); + + let clicked_split = hovered_split( + splits.iter(), + f32::from(self.spacing + leeway), + relative_cursor, + ); + + if let Some((split, axis, _)) = clicked_split { + self.state.pick_split(&split, axis); + } else { self.click_pane( layout, cursor_position, @@ -411,47 +404,51 @@ where ); } } + None => { + self.click_pane(layout, cursor_position, messages); + } } } - mouse::Event::ButtonReleased(mouse::Button::Left) => { - if let Some((pane, _)) = self.state.picked_pane() { - if let Some(on_drag) = &self.on_drag { - let mut dropped_region = self - .elements - .iter() - .zip(layout.children()) - .filter(|(_, layout)| { + } + Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) + | Event::Touch(touch::Event::FingerLifted { .. }) + | Event::Touch(touch::Event::FingerLost { .. }) => { + if let Some((pane, _)) = self.state.picked_pane() { + if let Some(on_drag) = &self.on_drag { + let mut dropped_region = + self.elements.iter().zip(layout.children()).filter( + |(_, layout)| { layout.bounds().contains(cursor_position) - }); - - let event = match dropped_region.next() { - Some(((target, _), _)) if pane != *target => { - DragEvent::Dropped { - pane, - target: *target, - } + }, + ); + + let event = match dropped_region.next() { + Some(((target, _), _)) if pane != *target => { + DragEvent::Dropped { + pane, + target: *target, } - _ => DragEvent::Canceled { pane }, - }; + } + _ => DragEvent::Canceled { pane }, + }; - messages.push(on_drag(event)); - } + messages.push(on_drag(event)); + } - self.state.idle(); + self.state.idle(); - event_status = event::Status::Captured; - } else if self.state.picked_split().is_some() { - self.state.idle(); + event_status = event::Status::Captured; + } else if self.state.picked_split().is_some() { + self.state.idle(); - event_status = event::Status::Captured; - } - } - mouse::Event::CursorMoved { .. } => { - event_status = - self.trigger_resize(layout, cursor_position, messages); + event_status = event::Status::Captured; } - _ => {} - }, + } + Event::Mouse(mouse::Event::CursorMoved { .. }) + | Event::Touch(touch::Event::FingerMoved { .. }) => { + event_status = + self.trigger_resize(layout, cursor_position, messages); + } _ => {} } -- cgit From f52f8c1337f42cf9483abb40784129f4effbe48e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 27 Feb 2021 03:36:46 +0100 Subject: Fix `viewport` argument in `PaneGrid` draw calls --- native/src/widget/pane_grid.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (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 c6fe4b60..e6274a28 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -478,7 +478,7 @@ where defaults: &Renderer::Defaults, layout: Layout<'_>, cursor_position: Point, - _viewport: &Rectangle, + viewport: &Rectangle, ) -> Renderer::Output { let picked_split = self .state @@ -537,6 +537,7 @@ where layout, &self.style, cursor_position, + viewport, ) } @@ -594,6 +595,7 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { layout: Layout<'_>, style: &::Style, cursor_position: Point, + viewport: &Rectangle, ) -> Self::Output; /// Draws a [`Pane`]. @@ -611,6 +613,7 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { title_bar: Option<(&TitleBar<'_, Message, Self>, Layout<'_>)>, body: (&Element<'_, Message, Self>, Layout<'_>), cursor_position: Point, + viewport: &Rectangle, ) -> Self::Output; /// Draws a [`TitleBar`]. @@ -629,6 +632,7 @@ pub trait Renderer: crate::Renderer + container::Renderer + Sized { content: (&Element<'_, Message, Self>, Layout<'_>), controls: Option<(&Element<'_, Message, Self>, Layout<'_>)>, cursor_position: Point, + viewport: &Rectangle, ) -> Self::Output; } -- cgit From 21971e0037c2ddcb96fd48ea96332445de4137bb Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 10 Mar 2021 01:59:02 +0100 Subject: Make `Clipboard` argument in `Widget` trait mutable --- native/src/widget/pane_grid.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 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 c6fe4b60..9a3580e0 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -362,9 +362,9 @@ where event: Event, layout: Layout<'_>, cursor_position: Point, - messages: &mut Vec, renderer: &Renderer, - clipboard: Option<&dyn Clipboard>, + clipboard: &mut dyn Clipboard, + messages: &mut Vec, ) -> event::Status { let mut event_status = event::Status::Ignored; @@ -461,9 +461,9 @@ where event.clone(), layout, cursor_position, - messages, renderer, clipboard, + messages, ) }) .fold(event_status, event::Status::merge) -- cgit From 83d19689c80266874e0a26085f17a94fd3507e1e Mon Sep 17 00:00:00 2001 From: Yusuf Bera Ertan Date: Mon, 14 Jun 2021 21:01:37 +0300 Subject: docs: update all 0.2 github links to 0.3 --- native/src/widget/pane_grid.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (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 44028f5e..b72172cc 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -6,7 +6,7 @@ //! The [`pane_grid` example] showcases how to use a [`PaneGrid`] with resizing, //! drag and drop, and hotkey support. //! -//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.2/examples/pane_grid +//! [`pane_grid` example]: https://github.com/hecrj/iced/tree/0.3/examples/pane_grid mod axis; mod configuration; mod content; -- cgit