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

rename parameters of TextArea::scroll

Этот коммит содержится в:
rhysd
2022-07-24 10:37:15 +09:00
родитель 4d6ad3d76b
Коммит be6eed684d
2 изменённых файлов: 10 добавлений и 9 удалений

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

@@ -481,6 +481,7 @@ impl<'a> TextArea<'a> {
} }
/// Handle a key input without default key mappings. This method handles only /// Handle a key input without default key mappings. This method handles only
///
/// - Single character input without modifier keys /// - Single character input without modifier keys
/// - Tab /// - Tab
/// - Enter /// - Enter
@@ -1492,10 +1493,10 @@ impl<'a> TextArea<'a> {
self.search.style = style; self.search.style = style;
} }
/// Scroll the textarea by `delta_row` rows (vertically) and `delta_col` columns (horizontally). Positive scroll /// Scroll the textarea by `rows` lines (vertically) and `cols` columns (horizontally). Positive scroll amount means
/// amount means scrolling down or right. And negative scroll amount means scrolling up or left. The cursor will not /// scrolling down or right. And negative scroll amount means scrolling up or left. The cursor will not move until
/// move until it goes out the viewport. When the cursor position is outside the viewport after scroll, the cursor /// it goes out the viewport. When the cursor position is outside the viewport after scroll, the cursor position will
/// position will be adjusted to stay in the viewport using the same logic as [`CursorMove::InViewport`]. /// be adjusted to stay in the viewport using the same logic as [`CursorMove::InViewport`].
/// ///
/// ``` /// ```
/// # use tui::buffer::Buffer; /// # use tui::buffer::Buffer;
@@ -1531,8 +1532,8 @@ impl<'a> TextArea<'a> {
/// textarea.scroll(-5, 0); /// textarea.scroll(-5, 0);
/// assert_eq!(textarea.cursor(), (12, 0)); /// assert_eq!(textarea.cursor(), (12, 0));
/// ``` /// ```
pub fn scroll(&mut self, delta_row: i16, delta_col: i16) { pub fn scroll(&mut self, rows: i16, cols: i16) {
self.viewport.scroll(delta_row, delta_col); self.viewport.scroll(rows, cols);
self.move_cursor(CursorMove::InViewport); self.move_cursor(CursorMove::InViewport);
} }
} }

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

@@ -56,7 +56,7 @@ impl Viewport {
self.0.store(u, Ordering::Relaxed); self.0.store(u, Ordering::Relaxed);
} }
pub fn scroll(&mut self, delta_row: i16, delta_col: i16) { pub fn scroll(&mut self, rows: i16, cols: i16) {
fn apply_scroll(pos: u16, delta: i16) -> u16 { fn apply_scroll(pos: u16, delta: i16) -> u16 {
if delta >= 0 { if delta >= 0 {
pos.saturating_add(delta as u16) pos.saturating_add(delta as u16)
@@ -66,8 +66,8 @@ impl Viewport {
} }
let u = self.0.get_mut(); let u = self.0.get_mut();
let row = apply_scroll((*u >> 16) as u16, delta_row); let row = apply_scroll((*u >> 16) as u16, rows);
let col = apply_scroll(*u as u16, delta_col); let col = apply_scroll(*u as u16, cols);
*u = (*u & 0xffff_ffff_0000_0000) | ((row as u64) << 16) | (col as u64); *u = (*u & 0xffff_ffff_0000_0000) | ((row as u64) << 16) | (col as u64);
} }
} }