Struct cursive_core::view::ScrollBase
source · pub struct ScrollBase {
pub start_line: usize,
pub content_height: usize,
pub view_height: usize,
pub scrollbar_offset: usize,
pub right_padding: usize,
pub thumb_grab: Option<usize>,
}
ScrollBase
is being deprecated in favor of the view::scroll module.Expand description
Provide scrolling functionalities to a view.
This is a legacy helper utility to define scrollable views.
The scroll
module is the preferred way to achieve that.
Fields§
§start_line: usize
ScrollBase
is being deprecated in favor of the view::scroll module.First line visible
content_height: usize
ScrollBase
is being deprecated in favor of the view::scroll module.Content height
view_height: usize
ScrollBase
is being deprecated in favor of the view::scroll module.Number of lines displayed
scrollbar_offset: usize
ScrollBase
is being deprecated in favor of the view::scroll module.Padding for the scrollbar
If present, the scrollbar will be shifted
scrollbar_offset
columns to the left.
(Useful when each item includes its own side borders, to draw the scrollbar inside.)
right_padding: usize
ScrollBase
is being deprecated in favor of the view::scroll module.Blank between the text and the scrollbar.
thumb_grab: Option<usize>
ScrollBase
is being deprecated in favor of the view::scroll module.Initial position of the cursor when dragging.
Implementations§
source§impl ScrollBase
impl ScrollBase
sourcepub fn scrollbar_offset(self, offset: usize) -> Self
pub fn scrollbar_offset(self, offset: usize) -> Self
Shifts the scrollbar toward the inside of the view.
Used by views that draw their side borders in the children. Pushing the scrollbar to the left allows it to stay inside the borders.
sourcepub fn right_padding(self, padding: usize) -> Self
pub fn right_padding(self, padding: usize) -> Self
Sets the number of blank cells between the text and the scrollbar.
Defaults to 1.
sourcepub fn set_heights(&mut self, view_height: usize, content_height: usize)
pub fn set_heights(&mut self, view_height: usize, content_height: usize)
Call this method whem the content or the view changes.
sourcepub fn scrollable(&self) -> bool
pub fn scrollable(&self) -> bool
Returns TRUE
if the view needs to scroll.
sourcepub fn can_scroll_up(&self) -> bool
pub fn can_scroll_up(&self) -> bool
Returns TRUE
unless we are at the top.
sourcepub fn can_scroll_down(&self) -> bool
pub fn can_scroll_down(&self) -> bool
Returns TRUE
unless we are at the bottom.
sourcepub fn scroll_top(&mut self)
pub fn scroll_top(&mut self)
Scroll to the top of the view.
sourcepub fn scroll_to(&mut self, y: usize)
pub fn scroll_to(&mut self, y: usize)
Makes sure that the given line is visible, scrolling if needed.
sourcepub fn scroll_bottom(&mut self)
pub fn scroll_bottom(&mut self)
Scroll to the bottom of the view.
sourcepub fn scroll_down(&mut self, n: usize)
pub fn scroll_down(&mut self, n: usize)
Scroll down by the given number of line.
Never further than the bottom of the view.
sourcepub fn scroll_to_thumb(&mut self, thumb_y: usize, thumb_height: usize)
pub fn scroll_to_thumb(&mut self, thumb_y: usize, thumb_height: usize)
Scrolls down until the scrollbar thumb is at the given location.
sourcepub fn scroll_up(&mut self, n: usize)
pub fn scroll_up(&mut self, n: usize)
Scroll up by the given number of lines.
Never above the top of the view.
sourcepub fn start_drag(&mut self, position: Vec2, width: usize) -> bool
pub fn start_drag(&mut self, position: Vec2, width: usize) -> bool
Starts scrolling from the given cursor position.
sourcepub fn is_dragging(&self) -> bool
pub fn is_dragging(&self) -> bool
Returns true
if we are in the process of dragging the scroll thumb.
sourcepub fn release_grab(&mut self)
pub fn release_grab(&mut self)
Stops grabbing the scrollbar.
sourcepub fn draw<F>(&self, printer: &Printer<'_, '_>, line_drawer: F)where
F: Fn(&Printer<'_, '_>, usize),
pub fn draw<F>(&self, printer: &Printer<'_, '_>, line_drawer: F)where
F: Fn(&Printer<'_, '_>, usize),
Draws the scroll bar and the content using the given drawer.
line_drawer
will be called once for each line that needs to be drawn.
It will be given the absolute ID of the item to draw..
It will also be given a printer with the correct offset,
so it should only print on the first line.
Examples
let lines = ["Line 1", "Line number 2"];
scrollbase.draw(printer, |printer, i| {
printer.print((0, 0), lines[i]);
});
sourcepub fn scrollbar_x(&self, total_size: usize) -> usize
pub fn scrollbar_x(&self, total_size: usize) -> usize
Returns the X position of the scrollbar, given the size available.
Note that this does not depend whether or not a scrollbar will actually be present.
sourcepub fn scrollbar_thumb_height(&self) -> usize
pub fn scrollbar_thumb_height(&self) -> usize
Returns the height of the scrollbar thumb.
sourcepub fn scrollbar_thumb_y(&self, scrollbar_thumb_height: usize) -> usize
pub fn scrollbar_thumb_y(&self, scrollbar_thumb_height: usize) -> usize
Returns the y position of the scrollbar thumb.