Skip to main content

ResizableGrid

Struct ResizableGrid 

Source
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,
}
Available on crate feature resizable-grid only.
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: u16

Implementations§

Source§

impl ResizableGrid

Source

pub fn new(pane_id: u32) -> ResizableGrid

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);
Source

pub fn from_pane(pane_id: u32) -> ResizableGrid

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

Source

pub fn layout_panes(&self, area: Rect) -> Vec<PaneLayout>

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));
Source

pub fn layout_dividers(&self, area: Rect) -> Vec<SplitDividerLayout>

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));
Source

pub fn calculate_split_area(&self, area: Rect, split_percent: u16) -> SplitAreas

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);
Source

pub fn get_panes(&self, area: Rect) -> Vec<PaneInfo>

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

Source

pub fn split_pane_horizontally(&mut self, pane_id: u32) -> Option<u32>

Source

pub fn split_pane_vertically(&mut self, pane_id: u32) -> Option<u32>

Source

pub fn resize_split(&mut self, split_index: usize, percent: u16) -> bool

Source

pub fn resize_divider(&mut self, pane_id: u32, percent: u16) -> bool

Source

pub fn move_pane(&mut self, pane_id: u32, target_pane_id: u32) -> bool

Source

pub fn remove_pane(&mut self, pane_id: u32) -> bool

Source

pub fn get_split_ratio(&self, split_index: usize) -> Option<u16>

Source

pub fn split_percent(&self) -> u16

Source

pub fn min_percent(&self) -> u16

Source

pub fn max_percent(&self) -> u16

Source

pub fn set_split_percent(&mut self, percent: u16)

Source

pub fn is_hovering(&self) -> bool

Source

pub fn is_dragging(&self) -> bool

Source

pub fn start_drag(&mut self)

Source

pub fn stop_drag(&mut self)

Source

pub fn update_divider_position(&mut self, _area: Rect)

Source

pub fn is_on_divider( &self, mouse_column: u16, mouse_row: u16, area: Rect, ) -> bool

Source

pub fn find_divider_at( &self, column: u16, row: u16, area: Rect, ) -> Option<usize>

Source

pub fn update_from_mouse( &mut self, mouse_column: u16, mouse_row: u16, area: Rect, )

Trait Implementations§

Source§

impl Clone for ResizableGrid

Source§

fn clone(&self) -> ResizableGrid

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ResizableGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more