pub struct ScrollbarState {
pub content_length: usize,
pub position: usize,
pub viewport_length: usize,
pub drag_anchor: Option<usize>,
}Expand description
Mutable state for a Scrollbar widget.
Fields§
§content_length: usizeTotal number of scrollable content units.
position: usizeCurrent scroll position within the content.
viewport_length: usizeNumber of content units visible in the viewport.
drag_anchor: Option<usize>Drag anchor point (offset from thumb top) to prevent jumping.
Implementations§
Source§impl ScrollbarState
impl ScrollbarState
Sourcepub fn new(
content_length: usize,
position: usize,
viewport_length: usize,
) -> Self
pub fn new( content_length: usize, position: usize, viewport_length: usize, ) -> Self
Create a new scrollbar state with given content, position, and viewport sizes.
Sourcepub fn handle_mouse(
&mut self,
event: &MouseEvent,
hit: Option<(HitId, HitRegion, u64)>,
expected_id: HitId,
) -> MouseResult
pub fn handle_mouse( &mut self, event: &MouseEvent, hit: Option<(HitId, HitRegion, u64)>, expected_id: HitId, ) -> MouseResult
Handle a mouse event for this scrollbar.
§Hit data convention
The hit data (u64) is encoded as:
[8: part] [28: track_len] [28: track_pos]
part: One ofSCROLLBAR_PART_*.track_len: The effective length of the track (excluding buttons).track_pos: The position within the effective track (0-based).
§Arguments
event— the mouse event from the terminalhit— result offrame.hit_test(event.x, event.y), if availableexpected_id— theHitIdthis scrollbar was rendered with
Sourcepub fn scroll_down(&mut self, lines: usize)
pub fn scroll_down(&mut self, lines: usize)
Scroll the content down by the given number of lines.
Clamps so that the viewport stays within content bounds.
Trait Implementations§
Source§impl Clone for ScrollbarState
impl Clone for ScrollbarState
Source§fn clone(&self) -> ScrollbarState
fn clone(&self) -> ScrollbarState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ScrollbarState
impl Debug for ScrollbarState
Source§impl Default for ScrollbarState
impl Default for ScrollbarState
Source§fn default() -> ScrollbarState
fn default() -> ScrollbarState
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ScrollbarState
impl RefUnwindSafe for ScrollbarState
impl Send for ScrollbarState
impl Sync for ScrollbarState
impl Unpin for ScrollbarState
impl UnsafeUnpin for ScrollbarState
impl UnwindSafe for ScrollbarState
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
Mutably borrows from an owned value. Read more