pub struct ScrollViewState { /* private fields */ }Expand description
State for a ScrollView component.
Contains the scroll position, content dimensions, and display options.
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new()
.with_content_height(50)
.with_title("Preview");
assert_eq!(state.content_height(), 50);
assert_eq!(state.title(), Some("Preview"));
assert_eq!(state.scroll_offset(), 0);Implementations§
Source§impl ScrollViewState
impl ScrollViewState
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new scroll view state with default settings.
The content height starts at 0, with no title, scrollbar enabled, unfocused, and enabled.
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new();
assert_eq!(state.content_height(), 0);
assert_eq!(state.scroll_offset(), 0);
assert!(state.show_scrollbar());
assert_eq!(state.title(), None);Sourcepub fn with_content_height(self, height: u16) -> Self
pub fn with_content_height(self, height: u16) -> Self
Sets the total content height (builder pattern).
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new().with_content_height(100);
assert_eq!(state.content_height(), 100);Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Sets the title (builder pattern).
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new().with_title("Preview");
assert_eq!(state.title(), Some("Preview"));Sourcepub fn with_show_scrollbar(self, show: bool) -> Self
pub fn with_show_scrollbar(self, show: bool) -> Self
Sets whether the scrollbar is shown (builder pattern).
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new().with_show_scrollbar(false);
assert!(!state.show_scrollbar());Sourcepub fn content_height(&self) -> u16
pub fn content_height(&self) -> u16
Returns the total content height.
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new().with_content_height(50);
assert_eq!(state.content_height(), 50);Sourcepub fn set_content_height(&mut self, height: u16)
pub fn set_content_height(&mut self, height: u16)
Sets the total content height.
Updates the scroll state’s content length accordingly.
§Example
use envision::component::ScrollViewState;
let mut state = ScrollViewState::new();
state.set_content_height(75);
assert_eq!(state.content_height(), 75);Sourcepub fn title(&self) -> Option<&str>
pub fn title(&self) -> Option<&str>
Returns the title.
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new().with_title("Output");
assert_eq!(state.title(), Some("Output"));Sourcepub fn set_title(&mut self, title: Option<String>)
pub fn set_title(&mut self, title: Option<String>)
Sets the title.
§Example
use envision::component::ScrollViewState;
let mut state = ScrollViewState::new();
state.set_title(Some("Output".to_string()));
assert_eq!(state.title(), Some("Output"));
state.set_title(None);
assert_eq!(state.title(), None);Sourcepub fn show_scrollbar(&self) -> bool
pub fn show_scrollbar(&self) -> bool
Returns whether the scrollbar is shown.
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new();
assert!(state.show_scrollbar());Sourcepub fn set_show_scrollbar(&mut self, show: bool)
pub fn set_show_scrollbar(&mut self, show: bool)
Sets whether the scrollbar is shown.
§Example
use envision::component::ScrollViewState;
let mut state = ScrollViewState::new();
state.set_show_scrollbar(false);
assert!(!state.show_scrollbar());Sourcepub fn scroll_offset(&self) -> usize
pub fn scroll_offset(&self) -> usize
Returns the current scroll offset.
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new();
assert_eq!(state.scroll_offset(), 0);Sourcepub fn set_scroll_offset(&mut self, offset: usize)
pub fn set_scroll_offset(&mut self, offset: usize)
Sets the scroll offset directly.
The offset is clamped to the valid range based on the content height and viewport height.
§Example
use envision::component::ScrollViewState;
let mut state = ScrollViewState::new().with_content_height(100);
state.set_scroll_offset(50);
assert_eq!(state.scroll_offset(), 50);Sourcepub fn scroll_state(&self) -> &ScrollState
pub fn scroll_state(&self) -> &ScrollState
Returns a reference to the internal scroll state.
§Example
use envision::component::ScrollViewState;
let state = ScrollViewState::new().with_content_height(50);
assert_eq!(state.scroll_state().content_length(), 50);Sourcepub fn content_area(&self, area: Rect) -> Rect
pub fn content_area(&self, area: Rect) -> Rect
Returns the visible content Rect accounting for the scroll offset.
This is the area inside the border where the parent should render content.
The returned Rect has its y coordinate adjusted by the scroll offset,
so the parent can use it directly to position content.
The border uses 1 cell on each side (top, bottom, left, right), so the inner area is smaller than the provided area by 2 in each dimension.
§Example
use envision::component::ScrollViewState;
use ratatui::prelude::Rect;
let state = ScrollViewState::new().with_content_height(100);
let area = Rect::new(0, 0, 40, 20);
let content = state.content_area(area);
// Inner area: x+1, y+1, width-2, height-2 = (1, 1, 38, 18)
assert_eq!(content.x, 1);
assert_eq!(content.y, 1);
assert_eq!(content.width, 38);
assert_eq!(content.height, 18);Sourcepub fn viewport_height(&self, area: Rect) -> u16
pub fn viewport_height(&self, area: Rect) -> u16
Returns the viewport height for the given render area.
This is the number of visible lines inside the bordered area.
§Example
use envision::component::ScrollViewState;
use ratatui::prelude::Rect;
let state = ScrollViewState::new();
let area = Rect::new(0, 0, 40, 20);
assert_eq!(state.viewport_height(area), 18);Sourcepub fn update(&mut self, msg: ScrollViewMessage) -> Option<()>
pub fn update(&mut self, msg: ScrollViewMessage) -> Option<()>
Updates the state with a message, returning any output.
§Example
use envision::component::{ScrollViewMessage, ScrollViewState};
let mut state = ScrollViewState::new().with_content_height(100);
state.update(ScrollViewMessage::ScrollDown);
assert_eq!(state.scroll_offset(), 1);Trait Implementations§
Source§impl Clone for ScrollViewState
impl Clone for ScrollViewState
Source§fn clone(&self) -> ScrollViewState
fn clone(&self) -> ScrollViewState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ScrollViewState
impl Debug for ScrollViewState
Source§impl Default for ScrollViewState
impl Default for ScrollViewState
Source§impl<'de> Deserialize<'de> for ScrollViewState
impl<'de> Deserialize<'de> for ScrollViewState
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 ScrollViewState
impl PartialEq for ScrollViewState
Source§impl Serialize for ScrollViewState
impl Serialize for ScrollViewState
impl StructuralPartialEq for ScrollViewState
Auto Trait Implementations§
impl Freeze for ScrollViewState
impl RefUnwindSafe for ScrollViewState
impl Send for ScrollViewState
impl Sync for ScrollViewState
impl Unpin for ScrollViewState
impl UnsafeUnpin for ScrollViewState
impl UnwindSafe for ScrollViewState
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