@@ -27,19 +27,13 @@ pub struct HelpComponent {
27
27
impl DrawableComponent for HelpComponent {
28
28
fn draw < B : Backend > ( & mut self , f : & mut Frame < B > , _rect : Rect ) {
29
29
if self . visible {
30
- let ( txt, selected_line) = self . get_text ( ) ;
31
-
32
- let height = 24 ;
33
- let scroll_threshold = height / 3 ;
34
-
35
- let scroll = if selected_line > scroll_threshold {
36
- self . selection - scroll_threshold
37
- } else {
38
- 0
39
- } ;
30
+ const SIZE : ( u16 , u16 ) = ( 65 , 24 ) ;
31
+ let scroll_threshold = SIZE . 1 / 3 ;
32
+ let scroll =
33
+ self . selection . saturating_sub ( scroll_threshold) ;
40
34
41
35
let area =
42
- ui:: centered_rect_absolute ( 65 , height , f. size ( ) ) ;
36
+ ui:: centered_rect_absolute ( SIZE . 0 , SIZE . 1 , f. size ( ) ) ;
43
37
44
38
f. render_widget ( Clear , area) ;
45
39
f. render_widget (
@@ -60,7 +54,7 @@ impl DrawableComponent for HelpComponent {
60
54
. split ( area) ;
61
55
62
56
f. render_widget (
63
- Paragraph :: new ( txt . iter ( ) )
57
+ Paragraph :: new ( self . get_text ( ) . iter ( ) )
64
58
. scroll ( scroll)
65
59
. alignment ( Alignment :: Left ) ,
66
60
chunks[ 0 ] ,
@@ -182,16 +176,17 @@ impl HelpComponent {
182
176
} ;
183
177
new_selection = cmp:: max ( new_selection, 0 ) ;
184
178
185
- if let Ok ( max) = u16:: try_from ( self . cmds . len ( ) - 1 ) {
179
+ if let Ok ( max) =
180
+ u16:: try_from ( self . cmds . len ( ) . saturating_sub ( 1 ) )
181
+ {
186
182
self . selection = cmp:: min ( new_selection, max) ;
187
183
}
188
184
}
189
185
190
- fn get_text < ' a > ( & self ) -> ( Vec < Text < ' a > > , u16 ) {
186
+ fn get_text < ' a > ( & self ) -> Vec < Text < ' a > > {
191
187
let mut txt = Vec :: new ( ) ;
192
188
193
189
let mut processed = 0_u16 ;
194
- let mut selected_line = 0_u16 ;
195
190
196
191
for ( key, group) in
197
192
& self . cmds . iter ( ) . group_by ( |e| e. text . group )
@@ -206,9 +201,7 @@ impl HelpComponent {
206
201
. sorted_by_key ( |e| e. order )
207
202
. map ( |e| {
208
203
let is_selected = self . selection == processed;
209
- if is_selected {
210
- selected_line = processed;
211
- }
204
+
212
205
processed += 1 ;
213
206
214
207
let mut out = String :: from ( if is_selected {
@@ -236,6 +229,6 @@ impl HelpComponent {
236
229
) ;
237
230
}
238
231
239
- ( txt, selected_line )
232
+ txt
240
233
}
241
234
}
0 commit comments