зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 16:35:49 +03:00
implement scrolling down/up by half/full page
Этот коммит содержится в:
@@ -45,13 +45,36 @@ pub enum Scrolling {
|
|||||||
/// textarea.scroll((1, 0));
|
/// textarea.scroll((1, 0));
|
||||||
/// assert_eq!(textarea.cursor(), (3, 0));
|
/// assert_eq!(textarea.cursor(), (3, 0));
|
||||||
/// ```
|
/// ```
|
||||||
Delta { rows: i16, cols: i16 },
|
Delta {
|
||||||
|
rows: i16,
|
||||||
|
cols: i16,
|
||||||
|
},
|
||||||
|
PageDown,
|
||||||
|
PageUp,
|
||||||
|
HalfPageDown,
|
||||||
|
HalfPageUp,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Scrolling {
|
impl Scrolling {
|
||||||
fn scroll(self, viewport: &mut Viewport) {
|
fn scroll(self, viewport: &mut Viewport) {
|
||||||
let (rows, cols) = match self {
|
let (rows, cols) = match self {
|
||||||
Self::Delta { rows, cols } => (rows, cols),
|
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);
|
viewport.scroll(rows, cols);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,17 @@ impl Viewport {
|
|||||||
((u >> 16) as u16, u as u16)
|
((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 u = self.0.load(Ordering::Relaxed);
|
||||||
let width = (u >> 48) as u16;
|
let width = (u >> 48) as u16;
|
||||||
let height = (u >> 32) as u16;
|
let height = (u >> 32) as u16;
|
||||||
let row_top = (u >> 16) as u16;
|
let row = (u >> 16) as u16;
|
||||||
let col_top = u 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 row_bottom = row_top.saturating_add(height).saturating_sub(1);
|
||||||
let col_bottom = col_top.saturating_add(width).saturating_sub(1);
|
let col_bottom = col_top.saturating_add(width).saturating_sub(1);
|
||||||
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user