1
0
зеркало из https://github.com/glebtv/tui-textarea.git synced 2026-09-03 22:35:50 +03:00

implement scrolling down/up by half/full page

Этот коммит содержится в:
rhysd
2022-10-14 21:25:44 +09:00
родитель ce5dc54cd4
Коммит a4c51a4812
2 изменённых файлов: 31 добавлений и 4 удалений

Просмотреть файл

@@ -45,13 +45,36 @@ pub enum Scrolling {
/// textarea.scroll((1, 0));
/// assert_eq!(textarea.cursor(), (3, 0));
/// ```
Delta { rows: i16, cols: i16 },
Delta {
rows: i16,
cols: i16,
},
PageDown,
PageUp,
HalfPageDown,
HalfPageUp,
}
impl Scrolling {
fn scroll(self, viewport: &mut Viewport) {
let (rows, cols) = match self {
Self::Delta { rows, cols } => (rows, cols),
Self::PageDown => {
let (_, _, _, height) = viewport.rect();
(height as i16, 0)
}
Self::PageUp => {
let (_, _, _, height) = viewport.rect();
(-(height as i16), 0)
}
Self::HalfPageDown => {
let (_, _, _, height) = viewport.rect();
((height as i16) / 2, 0)
}
Self::HalfPageUp => {
let (_, _, _, height) = viewport.rect();
(-(height as i16) / 2, 0)
}
};
viewport.scroll(rows, cols);
}

Просмотреть файл

@@ -31,13 +31,17 @@ impl Viewport {
((u >> 16) as u16, u as u16)
}
pub fn position(&self) -> (u16, u16, u16, u16) {
pub fn rect(&self) -> (u16, u16, u16, u16) {
let u = self.0.load(Ordering::Relaxed);
let width = (u >> 48) as u16;
let height = (u >> 32) as u16;
let row_top = (u >> 16) as u16;
let col_top = u as u16;
let row = (u >> 16) as u16;
let col = u as u16;
(row, col, width, height)
}
pub fn position(&self) -> (u16, u16, u16, u16) {
let (row_top, col_top, width, height) = self.rect();
let row_bottom = row_top.saturating_add(height).saturating_sub(1);
let col_bottom = col_top.saturating_add(width).saturating_sub(1);