@@ -21,9 +21,11 @@ use crossterm::event::Event;
21
21
use std:: { cell:: Cell , convert:: TryInto } ;
22
22
use tui:: {
23
23
backend:: Backend ,
24
- layout:: { Alignment , Rect } ,
24
+ layout:: {
25
+ Alignment , Constraint , Direction , Layout , Margin , Rect ,
26
+ } ,
25
27
text:: { Span , Spans , Text } ,
26
- widgets:: { Block , BorderType , Borders , Clear , Paragraph } ,
28
+ widgets:: { Block , BorderType , Borders , Clear , Paragraph , Tabs } ,
27
29
Frame ,
28
30
} ;
29
31
use ui:: style:: SharedTheme ;
@@ -49,7 +51,7 @@ impl DrawableComponent for BranchListComponent {
49
51
rect : Rect ,
50
52
) -> Result < ( ) > {
51
53
if self . visible {
52
- const PERCENT_SIZE : Size = Size :: new ( 80 , 25 ) ;
54
+ const PERCENT_SIZE : Size = Size :: new ( 80 , 50 ) ;
53
55
const MIN_SIZE : Size = Size :: new ( 60 , 20 ) ;
54
56
55
57
let area = ui:: centered_rect (
@@ -61,41 +63,32 @@ impl DrawableComponent for BranchListComponent {
61
63
ui:: rect_inside ( MIN_SIZE , f. size ( ) . into ( ) , area) ;
62
64
let area = area. intersection ( rect) ;
63
65
64
- let height_in_lines =
65
- ( area. height as usize ) . saturating_sub ( 2 ) ;
66
-
67
- self . scroll_top . set ( calc_scroll_top (
68
- self . scroll_top . get ( ) ,
69
- height_in_lines,
70
- self . selection as usize ,
71
- ) ) ;
72
-
73
66
f. render_widget ( Clear , area) ;
67
+
74
68
f. render_widget (
75
- Paragraph :: new ( self . get_text (
76
- & self . theme ,
77
- area. width ,
78
- height_in_lines,
79
- ) )
80
- . block (
81
- Block :: default ( )
82
- . title ( strings:: title_branches ( self . local ) )
83
- . border_type ( BorderType :: Thick )
84
- . borders ( Borders :: ALL ) ,
85
- )
86
- . alignment ( Alignment :: Left ) ,
69
+ Block :: default ( )
70
+ . title ( strings:: title_branches ( ) )
71
+ . border_type ( BorderType :: Thick )
72
+ . borders ( Borders :: ALL ) ,
87
73
area,
88
74
) ;
89
75
90
- ui:: draw_scrollbar (
91
- f,
92
- area,
93
- & self . theme ,
94
- self . branches . len ( ) ,
95
- self . scroll_top . get ( ) ,
96
- ) ;
76
+ let area = area. inner ( & Margin {
77
+ vertical : 1 ,
78
+ horizontal : 1 ,
79
+ } ) ;
80
+
81
+ let chunks = Layout :: default ( )
82
+ . direction ( Direction :: Vertical )
83
+ . constraints (
84
+ [ Constraint :: Length ( 2 ) , Constraint :: Min ( 1 ) ]
85
+ . as_ref ( ) ,
86
+ )
87
+ . split ( area) ;
88
+
89
+ self . draw_tabs ( f, chunks[ 0 ] ) ;
97
90
98
- self . current_height . set ( height_in_lines . try_into ( ) ? ) ;
91
+ self . draw_list ( f , chunks [ 1 ] ) ? ;
99
92
}
100
93
101
94
Ok ( ( ) )
@@ -123,6 +116,15 @@ impl Component for BranchListComponent {
123
116
true ,
124
117
) ) ;
125
118
119
+ out. push ( CommandInfo :: new (
120
+ strings:: commands:: toggle_branch_popup (
121
+ & self . key_config ,
122
+ self . local ,
123
+ ) ,
124
+ true ,
125
+ true ,
126
+ ) ) ;
127
+
126
128
out. push ( CommandInfo :: new (
127
129
strings:: commands:: select_branch_popup (
128
130
& self . key_config ,
@@ -154,15 +156,6 @@ impl Component for BranchListComponent {
154
156
true ,
155
157
self . local ,
156
158
) ) ;
157
-
158
- out. push ( CommandInfo :: new (
159
- strings:: commands:: toggle_branch_popup (
160
- & self . key_config ,
161
- self . local ,
162
- ) ,
163
- true ,
164
- true ,
165
- ) ) ;
166
159
}
167
160
visibility_blocking ( self )
168
161
}
@@ -215,8 +208,7 @@ impl Component for BranchListComponent {
215
208
) ,
216
209
) ,
217
210
) ;
218
- } else if e == self . key_config . toggle_remote_branches
219
- {
211
+ } else if e == self . key_config . tab_toggle {
220
212
self . local = !self . local ;
221
213
self . update_branches ( ) ?;
222
214
}
@@ -462,4 +454,65 @@ impl BranchListComponent {
462
454
463
455
Ok ( ( ) )
464
456
}
457
+
458
+ fn draw_tabs < B : Backend > ( & self , f : & mut Frame < B > , r : Rect ) {
459
+ let tabs = [ Span :: raw ( "Local" ) , Span :: raw ( "Remote" ) ]
460
+ . iter ( )
461
+ . cloned ( )
462
+ . map ( Spans :: from)
463
+ . collect ( ) ;
464
+
465
+ f. render_widget (
466
+ Tabs :: new ( tabs)
467
+ . block (
468
+ Block :: default ( )
469
+ . borders ( Borders :: BOTTOM )
470
+ . border_style ( self . theme . block ( false ) ) ,
471
+ )
472
+ . style ( self . theme . tab ( false ) )
473
+ . highlight_style ( self . theme . tab ( true ) )
474
+ . divider ( strings:: tab_divider ( & self . key_config ) )
475
+ . select ( if self . local { 0 } else { 1 } ) ,
476
+ r,
477
+ ) ;
478
+ }
479
+
480
+ fn draw_list < B : Backend > (
481
+ & self ,
482
+ f : & mut Frame < B > ,
483
+ r : Rect ,
484
+ ) -> Result < ( ) > {
485
+ let height_in_lines = r. height as usize ;
486
+
487
+ self . scroll_top . set ( calc_scroll_top (
488
+ self . scroll_top . get ( ) ,
489
+ height_in_lines,
490
+ self . selection as usize ,
491
+ ) ) ;
492
+
493
+ f. render_widget (
494
+ Paragraph :: new ( self . get_text (
495
+ & self . theme ,
496
+ r. width ,
497
+ height_in_lines,
498
+ ) )
499
+ . alignment ( Alignment :: Left ) ,
500
+ r,
501
+ ) ;
502
+
503
+ let mut r = r;
504
+ r. width += 1 ;
505
+
506
+ ui:: draw_scrollbar (
507
+ f,
508
+ r,
509
+ & self . theme ,
510
+ self . branches . len ( ) ,
511
+ self . scroll_top . get ( ) ,
512
+ ) ;
513
+
514
+ self . current_height . set ( height_in_lines. try_into ( ) ?) ;
515
+
516
+ Ok ( ( ) )
517
+ }
465
518
}
0 commit comments