Enum tui_textarea::Scrolling

source ·
#[non_exhaustive]
pub enum Scrolling { Delta { rows: i16, cols: i16, }, PageDown, PageUp, HalfPageDown, HalfPageUp, }
Expand description

Specify how to scroll the textarea.

This type is marked as #[non_exhaustive] since more variations may be supported in the future. Note that the cursor will not move until it goes out the viewport. See also: TextArea::scroll

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Delta

Scroll the textarea by rows (vertically) and columns (horizontally). Passing positive scroll amounts to rows and cols scolls it to down and right. Negative integers means the opposite directions. (i16, i16) pair can be converted into Scrolling::Delta where 1st element means rows and 2nd means columns.

use tui_textarea::{TextArea, Scrolling};

// Let's say terminal height is 8.

// Create textarea with 20 lines "0", "1", "2", "3", ...
let mut textarea: TextArea = (0..20).into_iter().map(|i| i.to_string()).collect();

// Scroll down by 2 lines.
textarea.scroll(Scrolling::Delta{rows: 2, cols: 0});
assert_eq!(textarea.cursor(), (2, 0));

// (1, 0) is converted into Scrolling::Delta{rows: 1, cols: 0}
textarea.scroll((1, 0));
assert_eq!(textarea.cursor(), (3, 0));

Fields

§rows: i16
§cols: i16
§

PageDown

Scroll down the textarea by one page.

use tui_textarea::{TextArea, Scrolling};

// Let's say terminal height is 8.

// Create textarea with 20 lines "0", "1", "2", "3", ...
let mut textarea: TextArea = (0..20).into_iter().map(|i| i.to_string()).collect();

// Scroll down by one page (8 lines)
textarea.scroll(Scrolling::PageDown);
assert_eq!(textarea.cursor(), (8, 0));
textarea.scroll(Scrolling::PageDown);
assert_eq!(textarea.cursor(), (16, 0));
textarea.scroll(Scrolling::PageDown);
assert_eq!(textarea.cursor(), (19, 0)); // Reached bottom of the textarea
§

PageUp

Scroll up the textarea by one page.

use tui_textarea::{TextArea, Scrolling, CursorMove};

// Let's say terminal height is 8.

// Create textarea with 20 lines "0", "1", "2", "3", ...
let mut textarea: TextArea = (0..20).into_iter().map(|i| i.to_string()).collect();

// Go to the last line at first
textarea.move_cursor(CursorMove::Bottom);
assert_eq!(textarea.cursor(), (19, 0));

// Scroll up by one page (8 lines)
textarea.scroll(Scrolling::PageUp);
assert_eq!(textarea.cursor(), (11, 0));
textarea.scroll(Scrolling::PageUp);
assert_eq!(textarea.cursor(), (7, 0)); // Reached top of the textarea
§

HalfPageDown

Scroll down the textarea by half of the page.

use tui_textarea::{TextArea, Scrolling};

// Let's say terminal height is 8.

// Create textarea with 10 lines "0", "1", "2", "3", ...
let mut textarea: TextArea = (0..10).into_iter().map(|i| i.to_string()).collect();

// Scroll down by half-page (4 lines)
textarea.scroll(Scrolling::HalfPageDown);
assert_eq!(textarea.cursor(), (4, 0));
textarea.scroll(Scrolling::HalfPageDown);
assert_eq!(textarea.cursor(), (8, 0));
textarea.scroll(Scrolling::HalfPageDown);
assert_eq!(textarea.cursor(), (9, 0)); // Reached bottom of the textarea
§

HalfPageUp

Scroll up the textarea by half of the page.

use tui_textarea::{TextArea, Scrolling, CursorMove};

// Let's say terminal height is 8.

// Create textarea with 20 lines "0", "1", "2", "3", ...
let mut textarea: TextArea = (0..20).into_iter().map(|i| i.to_string()).collect();

// Go to the last line at first
textarea.move_cursor(CursorMove::Bottom);
assert_eq!(textarea.cursor(), (19, 0));

// Scroll up by half-page (4 lines)
textarea.scroll(Scrolling::HalfPageUp);
assert_eq!(textarea.cursor(), (15, 0));
textarea.scroll(Scrolling::HalfPageUp);
assert_eq!(textarea.cursor(), (11, 0));

Trait Implementations§

source§

impl Clone for Scrolling

source§

fn clone(&self) -> Scrolling

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Scrolling

source§

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

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Scrolling

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<(i16, i16)> for Scrolling

source§

fn from((rows, cols): (i16, i16)) -> Self

Converts to this type from the input type.
source§

impl PartialEq for Scrolling

source§

fn eq(&self, other: &Scrolling) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Scrolling

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Copy for Scrolling

source§

impl Eq for Scrolling

source§

impl StructuralPartialEq for Scrolling

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> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,