ratatui_toolkit/primitives/split_layout/constructors/
new.rs

1use crate::primitives::split_layout::enums::layout_node::LayoutNode;
2use crate::primitives::split_layout::PaneId;
3use crate::primitives::split_layout::SplitLayout;
4
5impl SplitLayout {
6    /// Creates a layout with a single pane as the root.
7    ///
8    /// # Arguments
9    /// - `pane_id`: Identifier for the initial pane.
10    ///
11    /// # Returns
12    /// A new `SplitLayout` containing the provided pane ID.
13    ///
14    /// # Errors
15    /// - None.
16    ///
17    /// # Panics
18    /// - Does not panic.
19    ///
20    /// # Safety
21    /// - No safety requirements.
22    ///
23    /// # Performance
24    /// - O(1).
25    ///
26    /// # Example
27    /// ```rust
28    /// use ratatui_toolkit::primitives::split_layout::SplitLayout;
29    ///
30    /// let layout = SplitLayout::new(0);
31    /// ```
32    pub fn new(pane_id: PaneId) -> Self {
33        Self {
34            root_index: 0,
35            nodes: vec![LayoutNode::Pane { id: pane_id }],
36            next_pane_id: pane_id.saturating_add(1),
37        }
38    }
39}