Struct 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>,
}
๐Ÿ‘ŽDeprecated since 0.16.0: 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
๐Ÿ‘ŽDeprecated since 0.16.0: ScrollBase is being deprecated in favor of the view::scroll module.

First line visible

ยงcontent_height: usize
๐Ÿ‘ŽDeprecated since 0.16.0: ScrollBase is being deprecated in favor of the view::scroll module.

Content height

ยงview_height: usize
๐Ÿ‘ŽDeprecated since 0.16.0: ScrollBase is being deprecated in favor of the view::scroll module.

Number of lines displayed

ยงscrollbar_offset: usize
๐Ÿ‘ŽDeprecated since 0.16.0: 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
๐Ÿ‘ŽDeprecated since 0.16.0: ScrollBase is being deprecated in favor of the view::scroll module.

Blank between the text and the scrollbar.

ยงthumb_grab: Option<usize>
๐Ÿ‘ŽDeprecated since 0.16.0: ScrollBase is being deprecated in favor of the view::scroll module.

Initial position of the cursor when dragging.

Implementationsยง

Sourceยง

impl ScrollBase

Source

pub fn new() -> Self

Creates a new, uninitialized scrollbar.

Source

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.

Source

pub fn right_padding(self, padding: usize) -> Self

Sets the number of blank cells between the text and the scrollbar.

Defaults to 1.

Source

pub fn set_heights(&mut self, view_height: usize, content_height: usize)

Call this method when the content or the view changes.

Source

pub fn scrollable(&self) -> bool

Returns TRUE if the view needs to scroll.

Source

pub fn can_scroll_up(&self) -> bool

Returns TRUE unless we are at the top.

Source

pub fn can_scroll_down(&self) -> bool

Returns TRUE unless we are at the bottom.

Source

pub fn scroll_top(&mut self)

Scroll to the top of the view.

Source

pub fn scroll_to(&mut self, y: usize)

Makes sure that the given line is visible, scrolling if needed.

Source

pub fn scroll_bottom(&mut self)

Scroll to the bottom of the view.

Source

pub fn scroll_down(&mut self, n: usize)

Scroll down by the given number of line.

Never further than the bottom of the view.

Source

pub fn scroll_to_thumb(&mut self, thumb_y: usize, thumb_height: usize)

Scrolls down until the scrollbar thumb is at the given location.

Source

pub fn scroll_up(&mut self, n: usize)

Scroll up by the given number of lines.

Never above the top of the view.

Source

pub fn start_drag(&mut self, position: Vec2, width: usize) -> bool

Starts scrolling from the given cursor position.

Source

pub fn drag(&mut self, position: Vec2)

Keeps scrolling by dragging the cursor.

Source

pub fn is_dragging(&self) -> bool

Returns true if we are in the process of dragging the scroll thumb.

Source

pub fn release_grab(&mut self)

Stops grabbing the scrollbar.

Source

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]);
});
Source

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.

Source

pub fn scrollbar_thumb_height(&self) -> usize

Returns the height of the scrollbar thumb.

Source

pub fn scrollbar_thumb_y(&self, scrollbar_thumb_height: usize) -> usize

Returns the y position of the scrollbar thumb.

Trait Implementationsยง

Sourceยง

impl Debug for ScrollBase

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl Default for ScrollBase

Sourceยง

fn default() -> ScrollBase

Returns the โ€œdefault valueโ€ for a type. Read more

Auto Trait Implementationsยง

Blanket Implementationsยง

Sourceยง

impl<T> Any for T
where T: 'static + ?Sized,

Sourceยง

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Sourceยง

impl<T> Borrow<T> for T
where T: ?Sized,

Sourceยง

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Sourceยง

impl<T> BorrowMut<T> for T
where T: ?Sized,

Sourceยง

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Sourceยง

impl<T> From<T> for T

Sourceยง

fn from(t: T) -> T

Returns the argument unchanged.

Sourceยง

impl<T, U> Into<U> for T
where U: From<T>,

Sourceยง

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Sourceยง

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Sourceยง

type Error = Infallible

The type returned in the event of a conversion error.
Sourceยง

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Sourceยง

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Sourceยง

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Sourceยง

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Sourceยง

impl<T> With for T

Sourceยง

fn wrap_with<U, F: FnOnce(Self) -> U>(self, f: F) -> U

Calls the given closure and return the result. Read more
Sourceยง

fn with<F: FnOnce(&mut Self)>(self, f: F) -> Self

Calls the given closure on self.
Sourceยง

fn try_with<E, F>(self, f: F) -> Result<Self, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Calls the given closure on self.
Sourceยง

fn with_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure if condition == true.