SplitLayoutWidget

Struct SplitLayoutWidget 

Source
pub struct SplitLayoutWidget<'a> { /* private fields */ }
Expand description

A widget that wraps SplitLayout 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.

§Example

use ratatui_toolkit::widgets::split_layout::{SplitLayoutWidget, SplitLayoutWidgetState};
use ratatui_toolkit::primitives::split_layout::SplitLayout;

let mut layout = SplitLayout::new(0);
layout.split_pane_vertically(0);
let mut state = SplitLayoutWidgetState::default();

let widget = SplitLayoutWidget::new(&mut layout)
    .with_divider_width(1)
    .with_hit_threshold(2);

Implementations§

Source§

impl<'a> SplitLayoutWidget<'a>

Source

pub fn new(layout: &'a mut SplitLayout) -> Self

Create a new SplitLayoutWidget wrapping a SplitLayout.

Source

pub fn with_state(self, state: SplitLayoutWidgetState) -> Self

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

Source

pub fn state(&self) -> SplitLayoutWidgetState

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

Source

pub fn optimal_poll_duration(&self) -> Duration

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) -> &SplitLayout

Get a reference to the underlying layout.

Source

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

Get a mutable reference to the underlying layout.

Source

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

Set the width of divider lines.

Source

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

Set the hit detection threshold for dividers.

Source

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

Set the style for hovered dividers.

Source

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

Set the style for dragging dividers.

Source

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

Set the style for normal dividers.

Source

pub fn with_block(self, block: Block<'a>) -> Self

Set the block to render around the widget.

Source

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

Enable or disable pane borders.

Source

pub fn is_hovering(&self) -> bool

Check if currently hovering over any divider.

Source

pub fn is_dragging(&self) -> bool

Check if currently dragging any divider.

Source

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

Get the currently hovered divider index, if any.

Source

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

Get the currently dragging divider index, if any.

Source

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

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>

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<'a> Debug for SplitLayoutWidget<'a>

Source§

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

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

impl<'a> Widget for SplitLayoutWidget<'a>

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§

§

impl<'a> Freeze for SplitLayoutWidget<'a>

§

impl<'a> RefUnwindSafe for SplitLayoutWidget<'a>

§

impl<'a> Send for SplitLayoutWidget<'a>

§

impl<'a> Sync for SplitLayoutWidget<'a>

§

impl<'a> Unpin for SplitLayoutWidget<'a>

§

impl<'a> !UnwindSafe for SplitLayoutWidget<'a>

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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