Struct cursive::view::ScrollBase
[−]
[src]
pub struct ScrollBase { pub start_line: usize, pub content_height: usize, pub view_height: usize, pub scrollbar_offset: usize, pub right_padding: usize, }
Provide scrolling functionalities to a view.
You're not supposed to use this directly, but it can be helpful if you create your own Views.
Fields
start_line: usize
First line visible
content_height: usize
Content height
view_height: usize
Number of lines displayed
scrollbar_offset: usize
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
Blank between the text and the scrollbar.
Methods
impl ScrollBase
[src]
fn new() -> Self
Creates a new, uninitialized scrollbar.
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.
fn right_padding(self, padding: usize) -> Self
Sets the number of blank cells between the text and the scrollbar.
Defaults to 1.
fn set_heights(&mut self, view_height: usize, content_height: usize)
Call this method whem the content or the view changes.
fn scrollable(&self) -> bool
Returns TRUE
if the view needs to scroll.
fn can_scroll_up(&self) -> bool
Returns TRUE
unless we are at the top.
fn can_scroll_down(&self) -> bool
Returns TRUE
unless we are at the bottom.
fn scroll_top(&mut self)
Scroll to the top of the view.
fn scroll_to(&mut self, y: usize)
Makes sure that the given line is visible, scrolling if needed.
fn scroll_bottom(&mut self)
Scroll to the bottom of the view.
fn scroll_down(&mut self, n: usize)
Scroll down by the given number of line.
Never further than the bottom of the view.
fn scroll_up(&mut self, n: usize)
Scroll up by the given number of lines.
Never above the top of the view.
fn draw<F>(&self, printer: &Printer, line_drawer: F) where
F: Fn(&Printer, usize),
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]); });
Trait Implementations
impl Default for ScrollBase
[src]
fn default() -> ScrollBase
Returns the "default value" for a type. Read more