Skip to main content

ResizableGridWidget

Struct ResizableGridWidget 

Source
pub struct ResizableGridWidget { /* private fields */ }
Expand description

A widget that wraps ResizableGrid with mouse interaction support.

This widget manages hover state, drag state, and handles mouse events to resize dividers. It also provides styling options for visual feedback during interactions.

See the module-level docs for a minimal resizable split example.

§Example

use ratatui_toolkit::primitives::resizable_grid::{ResizableGridWidget, ResizableGrid};

let layout = ResizableGrid::new(0);
let state = ResizableGridWidgetState::default();

let widget = ResizableGridWidget::new(layout)
    .with_divider_width(1)
    .with_hit_threshold(2);

Implementations§

Source§

impl ResizableGridWidget

Source

pub fn new(layout: ResizableGrid) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Create a new ResizableGridWidget owning the given ResizableGrid.

Source

pub fn with_state(self, state: ResizableGridWidgetState) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Set the widget state (for preserving hover/drag across frames).

Source

pub fn state(&self) -> ResizableGridWidgetState

Available on crate feature resizable-grid only.

Get the current widget state (for saving after frame).

Source

pub fn optimal_poll_duration(&self) -> Duration

Available on crate feature resizable-grid only.

Get the recommended event poll duration based on interaction state.

Returns 8ms (~120fps) when dragging for smooth resizing, otherwise returns 50ms (normal rate).

§Example
let poll_timeout = widget.optimal_poll_duration();
if event::poll(poll_timeout)? { ... }
Source

pub fn layout(&self) -> &ResizableGrid

Available on crate feature resizable-grid only.

Get a reference to the underlying layout.

Source

pub fn layout_mut(&mut self) -> &mut ResizableGrid

Available on crate feature resizable-grid only.

Get a mutable reference to the underlying layout.

Source

pub fn with_divider_width(self, width: u16) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Set the width of divider lines.

Source

pub fn with_hit_threshold(self, threshold: u16) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Set the hit detection threshold for dividers.

Source

pub fn with_hover_style(self, style: Style) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Set the style for hovered dividers.

Source

pub fn with_drag_style(self, style: Style) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Set the style for dragging dividers.

Source

pub fn with_divider_style(self, style: Style) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Set the style for normal dividers.

Source

pub fn with_block(self, block: Block<'static>) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Set the block to render around the widget.

Source

pub fn with_pane_borders(self, show: bool) -> ResizableGridWidget

Available on crate feature resizable-grid only.

Enable or disable pane borders.

Source

pub fn is_hovering(&self) -> bool

Available on crate feature resizable-grid only.

Check if currently hovering over any divider.

Source

pub fn is_dragging(&self) -> bool

Available on crate feature resizable-grid only.

Check if currently dragging any divider.

Source

pub fn needs_fast_refresh(&self) -> bool

Available on crate feature resizable-grid only.

Check if the widget needs fast refresh (during drag operations).

Source

pub fn hovered_divider(&self) -> Option<usize>

Available on crate feature resizable-grid only.

Get the currently hovered divider index, if any.

Source

pub fn dragging_divider(&self) -> Option<usize>

Available on crate feature resizable-grid only.

Get the currently dragging divider index, if any.

Source

pub fn handle_mouse(&mut self, mouse: MouseEvent, area: Rect)

Available on crate feature resizable-grid only.

Handle a mouse event.

This method processes mouse events and updates the widget’s state:

  • Mouse move: Update hover state
  • Mouse down: Start dragging if on a divider
  • Mouse drag: Resize the divider
  • Mouse up: Stop dragging
§Arguments
  • mouse - The mouse event to handle
  • area - The area the widget is rendered in
Source

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

Available on crate feature resizable-grid only.

Get the layout rectangles for all panes.

This allows callers to render pane contents after the widget has drawn borders and overlays.

Trait Implementations§

Source§

impl Clone for ResizableGridWidget

Source§

fn clone(&self) -> ResizableGridWidget

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 ResizableGridWidget

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Widget for ResizableGridWidget

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.

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