@@ -27,6 +27,7 @@ pub struct ScrollTable<'a> {
27
27
parent_area : Rect ,
28
28
block : Option < Block < ' a > > ,
29
29
requested_width : u16 ,
30
+ column_width : u16 ,
30
31
max_height : u16 ,
31
32
x_offset : u16 ,
32
33
y_offset : usize ,
@@ -42,6 +43,7 @@ impl<'a> ScrollTable<'a> {
42
43
parent_area : Rect :: new ( 0 , 0 , 0 , 0 ) ,
43
44
block : None ,
44
45
requested_width : 0 ,
46
+ column_width : 0 ,
45
47
max_height : 0 ,
46
48
x_offset : 0 ,
47
49
y_offset : 0 ,
@@ -50,9 +52,17 @@ impl<'a> ScrollTable<'a> {
50
52
}
51
53
}
52
54
53
- pub fn set_table ( & mut self , table : Box < Table < ' a > > , requested_width : u16 , row_count : usize ) -> & mut Self {
55
+ pub fn set_table (
56
+ & mut self ,
57
+ table : Box < Table < ' a > > ,
58
+ column_count : usize ,
59
+ row_count : usize ,
60
+ column_width : u16 ,
61
+ ) -> & mut Self {
62
+ let requested_width = column_width. saturating_mul ( column_count as u16 ) ;
54
63
let max_height = u16:: MAX . saturating_div ( requested_width) ;
55
64
self . table = * table;
65
+ self . column_width = column_width;
56
66
self . requested_width = requested_width;
57
67
self . max_height = max_height;
58
68
self . max_y_offset = row_count. saturating_sub ( 1 ) ;
@@ -66,14 +76,53 @@ impl<'a> ScrollTable<'a> {
66
76
67
77
pub fn scroll ( & mut self , direction : ScrollDirection ) -> & mut Self {
68
78
match direction {
69
- ScrollDirection :: Left => self . x_offset = self . x_offset . saturating_sub ( 1 ) ,
70
- ScrollDirection :: Right => self . x_offset = Ord :: min ( self . x_offset . saturating_add ( 1 ) , self . max_x_offset ) ,
79
+ ScrollDirection :: Left => self . x_offset = self . x_offset . saturating_sub ( 2 ) ,
80
+ ScrollDirection :: Right => self . x_offset = Ord :: min ( self . x_offset . saturating_add ( 2 ) , self . max_x_offset ) ,
71
81
ScrollDirection :: Up => self . y_offset = self . y_offset . saturating_sub ( 1 ) ,
72
82
ScrollDirection :: Down => self . y_offset = Ord :: min ( self . y_offset . saturating_add ( 1 ) , self . max_y_offset ) ,
73
83
}
74
84
self
75
85
}
76
86
87
+ pub fn next_column ( & mut self ) -> & mut Self {
88
+ let x_over = self . x_offset % self . column_width ;
89
+ self . x_offset = Ord :: min ( self . x_offset . saturating_add ( self . column_width ) . saturating_sub ( x_over) , self . max_x_offset ) ;
90
+ self
91
+ }
92
+
93
+ pub fn prev_column ( & mut self ) -> & mut Self {
94
+ let x_over = self . x_offset % self . column_width ;
95
+ match x_over {
96
+ 0 => {
97
+ self . x_offset = self . x_offset . saturating_sub ( self . column_width ) ;
98
+ } ,
99
+ x => {
100
+ self . x_offset = self . x_offset . saturating_sub ( x) ;
101
+ } ,
102
+ }
103
+ self
104
+ }
105
+
106
+ pub fn bottom_row ( & mut self ) -> & mut Self {
107
+ self . y_offset = self . max_y_offset ;
108
+ self
109
+ }
110
+
111
+ pub fn top_row ( & mut self ) -> & mut Self {
112
+ self . y_offset = 0 ;
113
+ self
114
+ }
115
+
116
+ pub fn last_column ( & mut self ) -> & mut Self {
117
+ self . x_offset = self . max_x_offset ;
118
+ self
119
+ }
120
+
121
+ pub fn first_column ( & mut self ) -> & mut Self {
122
+ self . x_offset = 0 ;
123
+ self
124
+ }
125
+
77
126
pub fn reset_scroll ( & mut self ) -> & mut Self {
78
127
self . x_offset = 0 ;
79
128
self . y_offset = 0 ;
0 commit comments