pub struct ResizableGrid {
pub root_index: usize,
pub nodes: Vec<LayoutNode>,
pub next_pane_id: u32,
pub hovered_split: Option<usize>,
pub dragging_split: Option<usize>,
pub hit_threshold: u16,
}Expand description
A grid-based layout for arranging multiple resizable panes.
Grid layouts support hierarchical splits in both horizontal and vertical directions, enabling complex multi-pane arrangements.
§Example
use ratatui_toolkit::primitives::resizable_grid::ResizableGrid;
let mut grid = ResizableGrid::new(0);Fields§
§root_index: usize§nodes: Vec<LayoutNode>§next_pane_id: u32§hovered_split: Option<usize>§dragging_split: Option<usize>§hit_threshold: u16Implementations§
Source§impl ResizableGrid
impl ResizableGrid
Sourcepub fn new(pane_id: u32) -> ResizableGrid
Available on crate feature resizable-grid only.
pub fn new(pane_id: u32) -> ResizableGrid
resizable-grid only.Creates a new grid with a single pane as the root.
§Arguments
pane_id: Identifier for the initial pane.
§Returns
A new ResizableGrid containing the provided pane ID.
§Errors
- None.
§Panics
- Does not panic.
§Safety
- No safety requirements.
§Performance
- O(1).
§Example
use ratatui_toolkit::primitives::resizable_grid::ResizableGrid;
let grid = ResizableGrid::new(0);Sourcepub fn from_pane(pane_id: u32) -> ResizableGrid
Available on crate feature resizable-grid only.
pub fn from_pane(pane_id: u32) -> ResizableGrid
resizable-grid only.Creates a new grid from a single pane.
This is equivalent to Self::new() but provides a more semantic
name when constructing a grid that will be populated with panes.
§Arguments
pane_id: Identifier for the initial pane.
§Returns
A new ResizableGrid containing the provided pane ID.
§Errors
- None.
§Panics
- Does not panic.
§Safety
- No safety requirements.
§Performance
- O(1).
§Example
use ratatui_toolkit::primitives::resizable_grid::ResizableGrid;
let grid = ResizableGrid::from_pane(0);Source§impl ResizableGrid
impl ResizableGrid
Sourcepub fn layout_panes(&self, area: Rect) -> Vec<PaneLayout>
Available on crate feature resizable-grid only.
pub fn layout_panes(&self, area: Rect) -> Vec<PaneLayout>
resizable-grid only.Calculates pane rectangles for the current split tree.
§Arguments
area: The available rectangle to divide among panes.
§Returns
A vector of PaneLayout values for each leaf pane.
§Errors
- None.
§Panics
- Does not panic.
§Safety
- No safety requirements.
§Performance
- O(n) where n is the number of nodes.
§Example
use ratatui::layout::Rect;
use ratatui_toolkit::primitives::resizable_grid::ResizableGrid;
let grid = ResizableGrid::new(0);
let panes = grid.layout_panes(Rect::new(0, 0, 120, 40));Sourcepub fn layout_dividers(&self, area: Rect) -> Vec<SplitDividerLayout>
Available on crate feature resizable-grid only.
pub fn layout_dividers(&self, area: Rect) -> Vec<SplitDividerLayout>
resizable-grid only.Calculates divider metadata for the current split tree.
§Arguments
area: The available rectangle to divide among panes.
§Returns
A vector of SplitDividerLayout values for each split node.
§Errors
- None.
§Panics
- Does not panic.
§Safety
- No safety requirements.
§Performance
- O(n) where n is the number of split nodes.
§Example
use ratatui::layout::Rect;
use ratatui_toolkit::primitives::resizable_grid::ResizableGrid;
let grid = ResizableGrid::new(0);
let dividers = grid.layout_dividers(Rect::new(0, 0, 120, 40));Sourcepub fn calculate_split_area(&self, area: Rect, split_percent: u16) -> SplitAreas
Available on crate feature resizable-grid only.
pub fn calculate_split_area(&self, area: Rect, split_percent: u16) -> SplitAreas
resizable-grid only.Calculates simple two-pane split areas for basic layouts.
This is a convenience method for common two-pane layouts that calculates left and right (or top and bottom) pane rectangles based on a split percentage.
§Arguments
area: The total area to split.split_percent: The percentage for the left/top pane (0-100).
§Returns
A SplitAreas struct containing the left/top and right/bottom
pane rectangles.
§Example
use ratatui::layout::Rect;
use ratatui_toolkit::primitives::resizable_grid::ResizableGrid;
let grid = ResizableGrid::new(0);
let area = Rect::new(0, 0, 100, 50);
let split_areas = grid.calculate_split_area(area, 40);Sourcepub fn get_panes(&self, area: Rect) -> Vec<PaneInfo>
Available on crate feature resizable-grid only.
pub fn get_panes(&self, area: Rect) -> Vec<PaneInfo>
resizable-grid only.Returns pane information for all leaf panes in the grid.
This is a convenience method that extracts pane information suitable for use by widgets and rendering code.
§Arguments
area: The available rectangle to divide among panes.
§Returns
A vector of PaneInfo for each pane in the layout.
§Example
use ratatui::layout::Rect;
use ratatui_toolkit::primitives::resizable_grid::ResizableGrid;
let grid = ResizableGrid::new(0);
let area = Rect::new(0, 0, 100, 50);
let panes = grid.get_panes(area);
for pane in panes {
println!("Pane {}: {:?}", pane.id, pane.area);
}Source§impl ResizableGrid
impl ResizableGrid
pub fn split_pane_horizontally(&mut self, pane_id: u32) -> Option<u32>
resizable-grid only.pub fn split_pane_vertically(&mut self, pane_id: u32) -> Option<u32>
resizable-grid only.pub fn resize_split(&mut self, split_index: usize, percent: u16) -> bool
resizable-grid only.pub fn resize_divider(&mut self, pane_id: u32, percent: u16) -> bool
resizable-grid only.pub fn move_pane(&mut self, pane_id: u32, target_pane_id: u32) -> bool
resizable-grid only.pub fn remove_pane(&mut self, pane_id: u32) -> bool
resizable-grid only.pub fn get_split_ratio(&self, split_index: usize) -> Option<u16>
resizable-grid only.pub fn split_percent(&self) -> u16
resizable-grid only.pub fn min_percent(&self) -> u16
resizable-grid only.pub fn max_percent(&self) -> u16
resizable-grid only.pub fn set_split_percent(&mut self, percent: u16)
resizable-grid only.pub fn is_hovering(&self) -> bool
resizable-grid only.pub fn is_dragging(&self) -> bool
resizable-grid only.pub fn start_drag(&mut self)
resizable-grid only.pub fn stop_drag(&mut self)
resizable-grid only.pub fn update_divider_position(&mut self, _area: Rect)
resizable-grid only.pub fn is_on_divider( &self, mouse_column: u16, mouse_row: u16, area: Rect, ) -> bool
resizable-grid only.pub fn find_divider_at( &self, column: u16, row: u16, area: Rect, ) -> Option<usize>
resizable-grid only.pub fn update_from_mouse( &mut self, mouse_column: u16, mouse_row: u16, area: Rect, )
resizable-grid only.Trait Implementations§
Source§impl Clone for ResizableGrid
impl Clone for ResizableGrid
Source§fn clone(&self) -> ResizableGrid
fn clone(&self) -> ResizableGrid
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ResizableGrid
impl RefUnwindSafe for ResizableGrid
impl Send for ResizableGrid
impl Sync for ResizableGrid
impl Unpin for ResizableGrid
impl UnsafeUnpin for ResizableGrid
impl UnwindSafe for ResizableGrid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more