pub struct SplitPanelState { /* private fields */ }Expand description
State for a SplitPanel component.
Manages the split ratio, orientation, and which pane has focus. The parent is responsible for rendering content into each pane.
Implementations§
Source§impl SplitPanelState
impl SplitPanelState
Sourcepub fn new(orientation: SplitOrientation) -> Self
pub fn new(orientation: SplitOrientation) -> Self
Creates a new split panel with the given orientation and a 50/50 split.
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Horizontal);
assert_eq!(state.ratio(), 0.5);
assert_eq!(state.orientation(), &SplitOrientation::Horizontal);Sourcepub fn with_ratio(self, ratio: f32) -> Self
pub fn with_ratio(self, ratio: f32) -> Self
Sets the split ratio (builder pattern).
The ratio is clamped to [min_ratio, max_ratio].
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Vertical).with_ratio(0.3);
assert!((state.ratio() - 0.3).abs() < f32::EPSILON);Sourcepub fn orientation(&self) -> &SplitOrientation
pub fn orientation(&self) -> &SplitOrientation
Returns the current orientation.
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Horizontal);
assert_eq!(state.orientation(), &SplitOrientation::Horizontal);Sourcepub fn set_orientation(&mut self, orientation: SplitOrientation)
pub fn set_orientation(&mut self, orientation: SplitOrientation)
Sets the orientation.
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let mut state = SplitPanelState::new(SplitOrientation::Vertical);
state.set_orientation(SplitOrientation::Horizontal);
assert_eq!(state.orientation(), &SplitOrientation::Horizontal);Sourcepub fn ratio(&self) -> f32
pub fn ratio(&self) -> f32
Returns the current split ratio.
0.5 means equal split. Values closer to 1.0 give more space to the first pane.
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Vertical).with_ratio(0.4);
assert!((state.ratio() - 0.4).abs() < f32::EPSILON);Sourcepub fn set_ratio(&mut self, ratio: f32)
pub fn set_ratio(&mut self, ratio: f32)
Sets the split ratio, clamped to [min_ratio, max_ratio].
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let mut state = SplitPanelState::new(SplitOrientation::Vertical);
state.set_ratio(0.7);
assert!((state.ratio() - 0.7).abs() < f32::EPSILON);Sourcepub fn is_first_pane_focused(&self) -> bool
pub fn is_first_pane_focused(&self) -> bool
Returns true if the first pane has focus.
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Vertical);
assert!(state.is_first_pane_focused());
assert!(!state.is_second_pane_focused());Sourcepub fn is_second_pane_focused(&self) -> bool
pub fn is_second_pane_focused(&self) -> bool
Returns true if the second pane has focus.
§Example
use envision::component::{SplitPanelState, SplitPanelMessage, SplitOrientation};
let mut state = SplitPanelState::new(SplitOrientation::Vertical);
state.update(SplitPanelMessage::FocusSecond);
assert!(state.is_second_pane_focused());Sourcepub fn resize_step(&self) -> f32
pub fn resize_step(&self) -> f32
Returns the resize step size (default 0.1 = 10%).
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Vertical).with_resize_step(0.05);
assert!((state.resize_step() - 0.05).abs() < f32::EPSILON);Sourcepub fn with_resize_step(self, step: f32) -> Self
pub fn with_resize_step(self, step: f32) -> Self
Sets the resize step size.
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Vertical)
.with_resize_step(0.05);
assert!((state.resize_step() - 0.05).abs() < f32::EPSILON);Sourcepub fn with_bounds(self, min: f32, max: f32) -> Self
pub fn with_bounds(self, min: f32, max: f32) -> Self
Sets the minimum and maximum ratio bounds.
§Example
use envision::component::{SplitPanelState, SplitOrientation};
let state = SplitPanelState::new(SplitOrientation::Vertical)
.with_bounds(0.2, 0.8);Sourcepub fn update(&mut self, msg: SplitPanelMessage) -> Option<SplitPanelOutput>
pub fn update(&mut self, msg: SplitPanelMessage) -> Option<SplitPanelOutput>
Updates the state with a message, returning any output.
§Example
use envision::component::{SplitPanelState, SplitPanelMessage, SplitPanelOutput, SplitOrientation};
let mut state = SplitPanelState::new(SplitOrientation::Vertical);
let output = state.update(SplitPanelMessage::FocusSecond);
assert_eq!(output, Some(SplitPanelOutput::FocusedSecond));Sourcepub fn layout(&self, area: Rect) -> (Rect, Rect)
pub fn layout(&self, area: Rect) -> (Rect, Rect)
Computes the layout areas for the two panes.
Returns (first_pane_area, second_pane_area).
§Example
use envision::component::{SplitPanelState, SplitOrientation};
use ratatui::prelude::Rect;
let state = SplitPanelState::new(SplitOrientation::Vertical);
let area = Rect::new(0, 0, 80, 24);
let (first, second) = state.layout(area);
assert_eq!(first.width + second.width, 80);Trait Implementations§
Source§impl Clone for SplitPanelState
impl Clone for SplitPanelState
Source§fn clone(&self) -> SplitPanelState
fn clone(&self) -> SplitPanelState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SplitPanelState
impl Debug for SplitPanelState
Source§impl Default for SplitPanelState
impl Default for SplitPanelState
Source§impl<'de> Deserialize<'de> for SplitPanelState
impl<'de> Deserialize<'de> for SplitPanelState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for SplitPanelState
impl PartialEq for SplitPanelState
Auto Trait Implementations§
impl Freeze for SplitPanelState
impl RefUnwindSafe for SplitPanelState
impl Send for SplitPanelState
impl Sync for SplitPanelState
impl Unpin for SplitPanelState
impl UnsafeUnpin for SplitPanelState
impl UnwindSafe for SplitPanelState
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> 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