@@ -21,9 +21,11 @@ use crossterm::event::Event;
2121use std:: { cell:: Cell , convert:: TryInto } ;
2222use tui:: {
2323 backend:: Backend ,
24- layout:: { Alignment , Rect } ,
24+ layout:: {
25+ Alignment , Constraint , Direction , Layout , Margin , Rect ,
26+ } ,
2527 text:: { Span , Spans , Text } ,
26- widgets:: { Block , BorderType , Borders , Clear , Paragraph } ,
28+ widgets:: { Block , BorderType , Borders , Clear , Paragraph , Tabs } ,
2729 Frame ,
2830} ;
2931use ui:: style:: SharedTheme ;
@@ -49,7 +51,7 @@ impl DrawableComponent for BranchListComponent {
4951 rect : Rect ,
5052 ) -> Result < ( ) > {
5153 if self . visible {
52- const PERCENT_SIZE : Size = Size :: new ( 80 , 25 ) ;
54+ const PERCENT_SIZE : Size = Size :: new ( 80 , 50 ) ;
5355 const MIN_SIZE : Size = Size :: new ( 60 , 20 ) ;
5456
5557 let area = ui:: centered_rect (
@@ -61,41 +63,32 @@ impl DrawableComponent for BranchListComponent {
6163 ui:: rect_inside ( MIN_SIZE , f. size ( ) . into ( ) , area) ;
6264 let area = area. intersection ( rect) ;
6365
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-
7366 f. render_widget ( Clear , area) ;
67+
7468 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 ) ,
8773 area,
8874 ) ;
8975
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 ] ) ;
9790
98- self . current_height . set ( height_in_lines . try_into ( ) ? ) ;
91+ self . draw_list ( f , chunks [ 1 ] ) ? ;
9992 }
10093
10194 Ok ( ( ) )
@@ -123,6 +116,15 @@ impl Component for BranchListComponent {
123116 true ,
124117 ) ) ;
125118
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+
126128 out. push ( CommandInfo :: new (
127129 strings:: commands:: select_branch_popup (
128130 & self . key_config ,
@@ -154,15 +156,6 @@ impl Component for BranchListComponent {
154156 true ,
155157 self . local ,
156158 ) ) ;
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- ) ) ;
166159 }
167160 visibility_blocking ( self )
168161 }
@@ -215,8 +208,7 @@ impl Component for BranchListComponent {
215208 ) ,
216209 ) ,
217210 ) ;
218- } else if e == self . key_config . toggle_remote_branches
219- {
211+ } else if e == self . key_config . tab_toggle {
220212 self . local = !self . local ;
221213 self . update_branches ( ) ?;
222214 }
@@ -462,4 +454,65 @@ impl BranchListComponent {
462454
463455 Ok ( ( ) )
464456 }
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+ }
465518}
0 commit comments