pub struct ScrollState {
pub offset: usize,
/* private fields */
}Expand description
State for a scrollable container.
Pass a mutable reference to Context::scrollable each frame. The context
updates offset and the internal bounds automatically based on mouse wheel
and drag events.
Fields§
§offset: usizeCurrent vertical scroll offset in rows.
Implementations§
Source§impl ScrollState
impl ScrollState
Sourcepub fn can_scroll_up(&self) -> bool
pub fn can_scroll_up(&self) -> bool
Check if scrolling upward is possible (offset is greater than 0).
Sourcepub fn can_scroll_down(&self) -> bool
pub fn can_scroll_down(&self) -> bool
Check if scrolling downward is possible (content extends below the viewport).
Sourcepub fn content_height(&self) -> u32
pub fn content_height(&self) -> u32
Get the total content height in rows.
Sourcepub fn viewport_height(&self) -> u32
pub fn viewport_height(&self) -> u32
Get the viewport height in rows.
Sourcepub fn scroll_up(&mut self, amount: usize)
pub fn scroll_up(&mut self, amount: usize)
Scroll up by the given number of rows, clamped to 0.
Sourcepub fn scroll_down(&mut self, amount: usize)
pub fn scroll_down(&mut self, amount: usize)
Scroll down by the given number of rows, clamped to the maximum offset.
Sourcepub fn set_highlights(&mut self, ranges: &[HighlightRange])
pub fn set_highlights(&mut self, ranges: &[HighlightRange])
Set the active highlight ranges. Replaces any previous highlights.
Selecting the first highlight automatically when the list is non-empty matches the behavior of search-result navigation in code editors.
Sourcepub fn highlights(&self) -> &[HighlightRange]
pub fn highlights(&self) -> &[HighlightRange]
Read-only access to the active highlight ranges.
Sourcepub fn current_highlight(&self) -> Option<usize>
pub fn current_highlight(&self) -> Option<usize>
Index of the currently focused highlight, if any.
Sourcepub fn clear_highlights(&mut self)
pub fn clear_highlights(&mut self)
Clear all highlights and reset the current index.
Sourcepub fn highlight_next(&mut self)
pub fn highlight_next(&mut self)
Advance to the next highlight, scrolling the viewport to show it. Wraps from last to first.
Sourcepub fn highlight_previous(&mut self)
pub fn highlight_previous(&mut self)
Move to the previous highlight, scrolling the viewport to show it. Wraps from first to last.
Sourcepub fn scroll_to_current_highlight(&mut self)
pub fn scroll_to_current_highlight(&mut self)
Scroll the viewport so the currently focused highlight is visible with one line of context above when possible.
Trait Implementations§
Source§impl Clone for ScrollState
impl Clone for ScrollState
Source§fn clone(&self) -> ScrollState
fn clone(&self) -> ScrollState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more