Write documentation for new PaneGrid API
This commit is contained in:
parent
733ec6b2ea
commit
e3cd947437
5 changed files with 66 additions and 22 deletions
|
|
@ -148,8 +148,8 @@ where
|
||||||
|
|
||||||
if let Some((title_bar, title_bar_layout)) = title_bar {
|
if let Some((title_bar, title_bar_layout)) = title_bar {
|
||||||
let show_controls = bounds.contains(cursor_position);
|
let show_controls = bounds.contains(cursor_position);
|
||||||
let is_over_draggable =
|
let is_over_pick_area =
|
||||||
title_bar.is_over_draggable(title_bar_layout, cursor_position);
|
title_bar.is_over_pick_area(title_bar_layout, cursor_position);
|
||||||
|
|
||||||
let (title_bar_primitive, title_bar_interaction) = title_bar.draw(
|
let (title_bar_primitive, title_bar_interaction) = title_bar.draw(
|
||||||
self,
|
self,
|
||||||
|
|
@ -167,7 +167,7 @@ where
|
||||||
body_primitive,
|
body_primitive,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
if is_over_draggable {
|
if is_over_pick_area {
|
||||||
mouse::Interaction::Grab
|
mouse::Interaction::Grab
|
||||||
} else if title_bar_interaction > body_interaction {
|
} else if title_bar_interaction > body_interaction {
|
||||||
title_bar_interaction
|
title_bar_interaction
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@
|
||||||
//! [`Widget`]: widget/trait.Widget.html
|
//! [`Widget`]: widget/trait.Widget.html
|
||||||
//! [`UserInterface`]: struct.UserInterface.html
|
//! [`UserInterface`]: struct.UserInterface.html
|
||||||
//! [renderer]: renderer/index.html
|
//! [renderer]: renderer/index.html
|
||||||
//#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
//#![deny(missing_debug_implementations)]
|
#![deny(missing_debug_implementations)]
|
||||||
#![deny(unused_results)]
|
#![deny(unused_results)]
|
||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
#![forbid(rust_2018_idioms)]
|
#![forbid(rust_2018_idioms)]
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ pub use title_bar::TitleBar;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
container, keyboard, layout, mouse, row, text, Clipboard, Element, Event,
|
container, keyboard, layout, mouse, row, text, Clipboard, Element, Event,
|
||||||
Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
Hasher, Layout, Length, Point, Rectangle, Size, Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A collection of panes distributed using either vertical or horizontal splits
|
/// A collection of panes distributed using either vertical or horizontal splits
|
||||||
|
|
@ -273,9 +273,12 @@ where
|
||||||
if let Some(((pane, content), layout)) = clicked_region.next() {
|
if let Some(((pane, content), layout)) = clicked_region.next() {
|
||||||
match &self.on_drag {
|
match &self.on_drag {
|
||||||
Some(on_drag) => {
|
Some(on_drag) => {
|
||||||
if let Some(origin) =
|
if content.can_be_picked_at(layout, cursor_position) {
|
||||||
content.drag_origin(layout, cursor_position)
|
let pane_position = layout.position();
|
||||||
{
|
|
||||||
|
let origin = cursor_position
|
||||||
|
- Vector::new(pane_position.x, pane_position.y);
|
||||||
|
|
||||||
self.state.pick_pane(pane, origin);
|
self.state.pick_pane(pane, origin);
|
||||||
|
|
||||||
messages
|
messages
|
||||||
|
|
@ -693,6 +696,17 @@ pub trait Renderer:
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
) -> Self::Output;
|
) -> Self::Output;
|
||||||
|
|
||||||
|
/// Draws a [`TitleBar`].
|
||||||
|
///
|
||||||
|
/// 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 cursor position
|
||||||
|
///
|
||||||
|
/// [`TitleBar`]: struct.TitleBar.html
|
||||||
|
/// [`Layout`]: ../layout/struct.Layout.html
|
||||||
fn draw_title_bar<Message>(
|
fn draw_title_bar<Message>(
|
||||||
&mut self,
|
&mut self,
|
||||||
defaults: &Self::Defaults,
|
defaults: &Self::Defaults,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
use crate::container;
|
use crate::container;
|
||||||
use crate::layout;
|
use crate::layout;
|
||||||
use crate::pane_grid::{self, TitleBar};
|
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`].
|
/// The content of a [`Pane`].
|
||||||
///
|
///
|
||||||
/// [`Pane`]: struct.Pane.html
|
/// [`Pane`]: struct.Pane.html
|
||||||
|
#[allow(missing_debug_implementations)]
|
||||||
pub struct Content<'a, Message, Renderer: pane_grid::Renderer> {
|
pub struct Content<'a, Message, Renderer: pane_grid::Renderer> {
|
||||||
title_bar: Option<TitleBar<'a, Message, Renderer>>,
|
title_bar: Option<TitleBar<'a, Message, Renderer>>,
|
||||||
body: Element<'a, Message, Renderer>,
|
body: Element<'a, Message, Renderer>,
|
||||||
|
|
@ -16,6 +17,9 @@ impl<'a, Message, Renderer> Content<'a, Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: pane_grid::Renderer,
|
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 {
|
pub fn new(body: impl Into<Element<'a, Message, Renderer>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title_bar: None,
|
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(
|
pub fn title_bar(
|
||||||
mut self,
|
mut self,
|
||||||
title_bar: TitleBar<'a, Message, Renderer>,
|
title_bar: TitleBar<'a, Message, Renderer>,
|
||||||
|
|
@ -45,6 +53,11 @@ impl<'a, Message, Renderer> Content<'a, Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: pane_grid::Renderer,
|
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(
|
pub fn draw(
|
||||||
&self,
|
&self,
|
||||||
renderer: &mut Renderer,
|
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,
|
&self,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
) -> Option<Point> {
|
) -> bool {
|
||||||
if let Some(title_bar) = &self.title_bar {
|
if let Some(title_bar) = &self.title_bar {
|
||||||
let mut children = layout.children();
|
let mut children = layout.children();
|
||||||
let title_bar_layout = children.next().unwrap();
|
let title_bar_layout = children.next().unwrap();
|
||||||
|
|
||||||
if title_bar.is_over_draggable(title_bar_layout, cursor_position) {
|
title_bar.is_over_pick_area(title_bar_layout, cursor_position)
|
||||||
let position = layout.position();
|
|
||||||
|
|
||||||
Some(cursor_position - Vector::new(position.x, position.y))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@ use crate::layout;
|
||||||
use crate::pane_grid;
|
use crate::pane_grid;
|
||||||
use crate::{Clipboard, Element, Event, Layout, Point, Rectangle, Size};
|
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> {
|
pub struct TitleBar<'a, Message, Renderer: pane_grid::Renderer> {
|
||||||
title: String,
|
title: String,
|
||||||
title_size: Option<u16>,
|
title_size: Option<u16>,
|
||||||
|
|
@ -14,6 +18,9 @@ impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: pane_grid::Renderer,
|
Renderer: pane_grid::Renderer,
|
||||||
{
|
{
|
||||||
|
/// Cretes a new [`TitleBar`] with the given title.
|
||||||
|
///
|
||||||
|
/// [`TitleBar`]: struct.TitleBar.html
|
||||||
pub fn new(title: impl Into<String>) -> Self {
|
pub fn new(title: impl Into<String>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: title.into(),
|
title: title.into(),
|
||||||
|
|
@ -26,7 +33,7 @@ where
|
||||||
|
|
||||||
/// Sets the size of the title of the [`TitleBar`].
|
/// 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 {
|
pub fn title_size(mut self, size: u16) -> Self {
|
||||||
self.title_size = Some(size);
|
self.title_size = Some(size);
|
||||||
self
|
self
|
||||||
|
|
@ -64,6 +71,11 @@ impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer>
|
||||||
where
|
where
|
||||||
Renderer: pane_grid::Renderer,
|
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(
|
pub fn draw(
|
||||||
&self,
|
&self,
|
||||||
renderer: &mut Renderer,
|
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,
|
&self,
|
||||||
layout: Layout<'_>,
|
layout: Layout<'_>,
|
||||||
cursor_position: Point,
|
cursor_position: Point,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue