diff options
author | 2020-07-09 05:26:11 +0200 | |
---|---|---|
committer | 2020-07-09 05:26:11 +0200 | |
commit | e3cd947437cad1a53715b77b63e6c7a348de97c5 (patch) | |
tree | ae5103607bf48f6df1b3479c826ab8cd96d873a8 /native/src/widget/pane_grid | |
parent | 733ec6b2eafd3e7267409e49f2e6cf497f7c7074 (diff) | |
download | iced-e3cd947437cad1a53715b77b63e6c7a348de97c5.tar.gz iced-e3cd947437cad1a53715b77b63e6c7a348de97c5.tar.bz2 iced-e3cd947437cad1a53715b77b63e6c7a348de97c5.zip |
Write documentation for new `PaneGrid` API
Diffstat (limited to 'native/src/widget/pane_grid')
-rw-r--r-- | native/src/widget/pane_grid/content.rs | 34 | ||||
-rw-r--r-- | native/src/widget/pane_grid/title_bar.rs | 22 |
2 files changed, 43 insertions, 13 deletions
diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 55fa4c60..1f5ce640 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -1,11 +1,12 @@ use crate::container; use crate::layout; use crate::pane_grid::{self, TitleBar}; -use crate::{Clipboard, Element, Event, Hasher, Layout, Point, Size, Vector}; +use crate::{Clipboard, Element, Event, Hasher, Layout, Point, Size}; /// The content of a [`Pane`]. /// /// [`Pane`]: struct.Pane.html +#[allow(missing_debug_implementations)] pub struct Content<'a, Message, Renderer: pane_grid::Renderer> { title_bar: Option<TitleBar<'a, Message, Renderer>>, body: Element<'a, Message, Renderer>, @@ -16,6 +17,9 @@ impl<'a, Message, Renderer> Content<'a, Message, Renderer> where Renderer: pane_grid::Renderer, { + /// Creates a new [`Content`] with the provided body. + /// + /// [`Content`]: struct.Content.html pub fn new(body: impl Into<Element<'a, Message, Renderer>>) -> Self { Self { title_bar: None, @@ -24,6 +28,10 @@ where } } + /// Sets the [`TitleBar`] of this [`Content`]. + /// + /// [`TitleBar`]: struct.TitleBar.html + /// [`Content`]: struct.Content.html pub fn title_bar( mut self, title_bar: TitleBar<'a, Message, Renderer>, @@ -45,6 +53,11 @@ impl<'a, Message, Renderer> Content<'a, Message, Renderer> where Renderer: pane_grid::Renderer, { + /// Draws the [`Content`] with the provided [`Renderer`] and [`Layout`]. + /// + /// [`Content`]: struct.Content.html + /// [`Renderer`]: trait.Renderer.html + /// [`Layout`]: ../layout/struct.Layout.html pub fn draw( &self, renderer: &mut Renderer, @@ -77,24 +90,23 @@ where } } - pub fn drag_origin( + /// Returns whether the [`Content`] with the given [`Layout`] can be picked + /// at the provided cursor position. + /// + /// [`Content`]: struct.Content.html + /// [`Layout`]: ../layout/struct.Layout.html + pub fn can_be_picked_at( &self, layout: Layout<'_>, cursor_position: Point, - ) -> Option<Point> { + ) -> bool { if let Some(title_bar) = &self.title_bar { let mut children = layout.children(); let title_bar_layout = children.next().unwrap(); - if title_bar.is_over_draggable(title_bar_layout, cursor_position) { - let position = layout.position(); - - Some(cursor_position - Vector::new(position.x, position.y)) - } else { - None - } + title_bar.is_over_pick_area(title_bar_layout, cursor_position) } else { - None + false } } diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index cf5f0a59..775c8a8f 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -2,6 +2,10 @@ use crate::layout; use crate::pane_grid; use crate::{Clipboard, Element, Event, Layout, Point, Rectangle, Size}; +/// The title bar of a [`Pane`]. +/// +/// [`Pane`]: struct.Pane.html +#[allow(missing_debug_implementations)] pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> { title: String, title_size: Option<u16>, @@ -14,6 +18,9 @@ impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> where Renderer: pane_grid::Renderer, { + /// Cretes a new [`TitleBar`] with the given title. + /// + /// [`TitleBar`]: struct.TitleBar.html pub fn new(title: impl Into<String>) -> Self { Self { title: title.into(), @@ -26,7 +33,7 @@ where /// Sets the size of the title of the [`TitleBar`]. /// - /// [`TitleBar`]: struct.Text.html + /// [`TitleBar`]: struct.TitleBar.html pub fn title_size(mut self, size: u16) -> Self { self.title_size = Some(size); self @@ -64,6 +71,11 @@ impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> where Renderer: pane_grid::Renderer, { + /// Draws the [`TitleBar`] with the provided [`Renderer`] and [`Layout`]. + /// + /// [`TitleBar`]: struct.TitleBar.html + /// [`Renderer`]: trait.Renderer.html + /// [`Layout`]: ../layout/struct.Layout.html pub fn draw( &self, renderer: &mut Renderer, @@ -118,7 +130,13 @@ where } } - pub fn is_over_draggable( + /// Returns whether the mouse cursor is over the pick area of the + /// [`TitleBar`] or not. + /// + /// The whole [`TitleBar`] is a pick area, except its controls. + /// + /// [`TitleBar`]: struct.TitleBar.html + pub fn is_over_pick_area( &self, layout: Layout<'_>, cursor_position: Point, |