1use serde::Deserialize;
2use ui::{px, Pixels};
3
4#[derive(Debug, Clone, PartialEq, Deserialize)]
5pub enum ScrollAmount {
6 // Scroll N lines (positive is towards the end of the document)
7 Line(f32),
8 // Scroll N pages (positive is towards the end of the document)
9 Page(f32),
10}
11
12impl ScrollAmount {
13 pub fn lines(&self, mut visible_line_count: f32) -> f32 {
14 match self {
15 Self::Line(count) => *count,
16 Self::Page(count) => {
17 // for full pages subtract one to leave an anchor line
18 if count.abs() == 1.0 {
19 visible_line_count -= 1.0
20 }
21 (visible_line_count * count).trunc()
22 }
23 }
24 }
25
26 pub fn pixels(&self, line_height: Pixels, height: Pixels) -> Pixels {
27 match self {
28 ScrollAmount::Line(x) => px(line_height.0 * x),
29 ScrollAmount::Page(x) => px(height.0 * x),
30 }
31 }
32}