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));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 textareaPageUp
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 textareaHalfPageDown
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 textareaHalfPageUp
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
Auto Trait Implementations
impl RefUnwindSafe for Scrolling
impl Send for Scrolling
impl Sync for Scrolling
impl Unpin for Scrolling
impl UnwindSafe for Scrolling
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more