From 230bd6f7475752352ca9985802db0633e3508d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 22 May 2020 22:15:44 +0200 Subject: [PATCH] Write documentation for new `pane_grid` API --- native/src/widget/pane_grid/content.rs | 18 +++++++++++++ native/src/widget/pane_grid/node.rs | 36 ++++++++++++++++++++++++++ native/src/widget/pane_grid/state.rs | 4 +++ 3 files changed, 58 insertions(+) diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 6b0bd99a..8822083e 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -1,12 +1,30 @@ use crate::pane_grid::Axis; +/// The content of a [`PaneGrid`]. +/// +/// [`PaneGrid`]: struct.PaneGrid.html #[derive(Debug, Clone)] pub enum Content { + /// A split of the available space. Split { + /// The direction of the split. axis: Axis, + + /// The ratio of the split in [0.0, 1.0]. ratio: f32, + + /// The left/top [`Content`] of the split. + /// + /// [`Content`]: enum.Node.html a: Box>, + + /// The right/bottom [`Content`] of the split. + /// + /// [`Content`]: enum.Node.html b: Box>, }, + /// A [`Pane`]. + /// + /// [`Pane`]: struct.Pane.html Pane(T), } diff --git a/native/src/widget/pane_grid/node.rs b/native/src/widget/pane_grid/node.rs index 1b6633fa..723ec393 100644 --- a/native/src/widget/pane_grid/node.rs +++ b/native/src/widget/pane_grid/node.rs @@ -5,19 +5,49 @@ use crate::{ use std::collections::HashMap; +/// A layout node of a [`PaneGrid`]. +/// +/// [`PaneGrid`]: struct.PaneGrid.html #[derive(Debug, Clone)] pub enum Node { + /// The region of this [`Node`] is split into two. + /// + /// [`Node`]: enum.Node.html Split { + /// The [`Split`] of this [`Node`]. + /// + /// [`Split`]: struct.Split.html + /// [`Node`]: enum.Node.html id: Split, + + /// The direction of the split. axis: Axis, + + /// The ratio of the split in [0.0, 1.0]. ratio: f32, + + /// The left/top [`Node`] of the split. + /// + /// [`Node`]: enum.Node.html a: Box, + + /// The right/bottom [`Node`] of the split. + /// + /// [`Node`]: enum.Node.html b: Box, }, + /// The region of this [`Node`] is taken by a [`Pane`]. + /// + /// [`Pane`]: struct.Pane.html Pane(Pane), } 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( &self, spacing: f32, @@ -39,6 +69,12 @@ impl Node { 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( &self, spacing: f32, diff --git a/native/src/widget/pane_grid/state.rs b/native/src/widget/pane_grid/state.rs index 41f3cffd..4b13fb8e 100644 --- a/native/src/widget/pane_grid/state.rs +++ b/native/src/widget/pane_grid/state.rs @@ -56,6 +56,10 @@ impl State { (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>) -> Self { let mut panes = HashMap::new();