Write documentation for new pane_grid
API
This commit is contained in:
parent
2ab7341fa5
commit
230bd6f747
@ -1,12 +1,30 @@
|
|||||||
use crate::pane_grid::Axis;
|
use crate::pane_grid::Axis;
|
||||||
|
|
||||||
|
/// The content of a [`PaneGrid`].
|
||||||
|
///
|
||||||
|
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Content<T> {
|
pub enum Content<T> {
|
||||||
|
/// A split of the available space.
|
||||||
Split {
|
Split {
|
||||||
|
/// The direction of the split.
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
|
|
||||||
|
/// The ratio of the split in [0.0, 1.0].
|
||||||
ratio: f32,
|
ratio: f32,
|
||||||
|
|
||||||
|
/// The left/top [`Content`] of the split.
|
||||||
|
///
|
||||||
|
/// [`Content`]: enum.Node.html
|
||||||
a: Box<Content<T>>,
|
a: Box<Content<T>>,
|
||||||
|
|
||||||
|
/// The right/bottom [`Content`] of the split.
|
||||||
|
///
|
||||||
|
/// [`Content`]: enum.Node.html
|
||||||
b: Box<Content<T>>,
|
b: Box<Content<T>>,
|
||||||
},
|
},
|
||||||
|
/// A [`Pane`].
|
||||||
|
///
|
||||||
|
/// [`Pane`]: struct.Pane.html
|
||||||
Pane(T),
|
Pane(T),
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,49 @@ use crate::{
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
/// A layout node of a [`PaneGrid`].
|
||||||
|
///
|
||||||
|
/// [`PaneGrid`]: struct.PaneGrid.html
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Node {
|
pub enum Node {
|
||||||
|
/// The region of this [`Node`] is split into two.
|
||||||
|
///
|
||||||
|
/// [`Node`]: enum.Node.html
|
||||||
Split {
|
Split {
|
||||||
|
/// The [`Split`] of this [`Node`].
|
||||||
|
///
|
||||||
|
/// [`Split`]: struct.Split.html
|
||||||
|
/// [`Node`]: enum.Node.html
|
||||||
id: Split,
|
id: Split,
|
||||||
|
|
||||||
|
/// The direction of the split.
|
||||||
axis: Axis,
|
axis: Axis,
|
||||||
|
|
||||||
|
/// The ratio of the split in [0.0, 1.0].
|
||||||
ratio: f32,
|
ratio: f32,
|
||||||
|
|
||||||
|
/// The left/top [`Node`] of the split.
|
||||||
|
///
|
||||||
|
/// [`Node`]: enum.Node.html
|
||||||
a: Box<Node>,
|
a: Box<Node>,
|
||||||
|
|
||||||
|
/// The right/bottom [`Node`] of the split.
|
||||||
|
///
|
||||||
|
/// [`Node`]: enum.Node.html
|
||||||
b: Box<Node>,
|
b: Box<Node>,
|
||||||
},
|
},
|
||||||
|
/// The region of this [`Node`] is taken by a [`Pane`].
|
||||||
|
///
|
||||||
|
/// [`Pane`]: struct.Pane.html
|
||||||
Pane(Pane),
|
Pane(Pane),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
|
/// Returns the rectangular region for each [`Pane`] in the [`Node`] given
|
||||||
|
/// the spacing between panes and the total available space.
|
||||||
|
///
|
||||||
|
/// [`Pane`]: struct.Pane.html
|
||||||
|
/// [`Node`]: enum.Node.html
|
||||||
pub fn regions(
|
pub fn regions(
|
||||||
&self,
|
&self,
|
||||||
spacing: f32,
|
spacing: f32,
|
||||||
@ -39,6 +69,12 @@ impl Node {
|
|||||||
regions
|
regions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the axis, rectangular region, and ratio for each [`Split`] in
|
||||||
|
/// the [`Node`] given the spacing between panes and the total available
|
||||||
|
/// space.
|
||||||
|
///
|
||||||
|
/// [`Split`]: struct.Split.html
|
||||||
|
/// [`Node`]: enum.Node.html
|
||||||
pub fn splits(
|
pub fn splits(
|
||||||
&self,
|
&self,
|
||||||
spacing: f32,
|
spacing: f32,
|
||||||
|
@ -56,6 +56,10 @@ impl<T> State<T> {
|
|||||||
(Self::with_content(Content::Pane(first_pane_state)), Pane(0))
|
(Self::with_content(Content::Pane(first_pane_state)), Pane(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a new [`State`] with the given [`Content`].
|
||||||
|
///
|
||||||
|
/// [`State`]: struct.State.html
|
||||||
|
/// [`Content`]: enum.Content.html
|
||||||
pub fn with_content(content: impl Into<Content<T>>) -> Self {
|
pub fn with_content(content: impl Into<Content<T>>) -> Self {
|
||||||
let mut panes = HashMap::new();
|
let mut panes = HashMap::new();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user