@@ -50,58 +50,22 @@ impl MainWindow {
5050 state,
5151 } = props. borrow ( ) ;
5252
53- let ( entries_style, help_style, mark_style) = {
54- let grey = Style {
55- fg : Color :: DarkGray . into ( ) ,
56- bg : Color :: Reset . into ( ) ,
57- add_modifier : Modifier :: empty ( ) ,
58- ..Style :: default ( )
59- } ;
60- let bold = Style :: default ( ) . add_modifier ( Modifier :: BOLD ) ;
61- match state. focussed {
62- Main => ( bold, grey, grey) ,
63- Help => ( grey, bold, grey) ,
64- Mark => ( grey, grey, bold) ,
65- }
66- } ;
53+ let ( entries_style, help_style, mark_style) = pane_border_style ( state. focussed ) ;
54+ let ( header_area, content_area, footer_area) = main_window_layout ( area) ;
55+
56+ let header_bg_color = header_background_color ( self . is_anything_marked ( ) , state. focussed ) ;
57+ Header . render ( header_bg_color, header_area, buf) ;
6758
68- let ( header_area, entries_area, footer_area) = {
69- let regions = Layout :: default ( )
70- . direction ( Direction :: Vertical )
71- . constraints ( [ Length ( 1 ) , Max ( 256 ) , Length ( 1 ) ] . as_ref ( ) )
72- . split ( area) ;
73- ( regions[ 0 ] , regions[ 1 ] , regions[ 2 ] )
74- } ;
75- {
76- let marked = self . mark_pane . as_ref ( ) . map ( |p| p. marked ( ) ) ;
77- let bg_color = match ( marked. map_or ( true , |m| m. is_empty ( ) ) , state. focussed ) {
78- ( false , FocussedPane :: Mark ) => Color :: LightRed ,
79- ( false , _) => COLOR_MARKED ,
80- ( _, _) => Color :: White ,
81- } ;
82- Header . render ( bg_color, header_area, buf) ;
83- }
8459 let ( entries_area, help_pane, mark_pane) = {
85- let regions = Layout :: default ( )
86- . direction ( Direction :: Horizontal )
87- . constraints ( [ Percentage ( 50 ) , Percentage ( 50 ) ] . as_ref ( ) )
88- . split ( entries_area) ;
89- let ( left_pane, right_pane) = ( regions[ 0 ] , regions[ 1 ] ) ;
60+ let ( left_pane, right_pane) = content_layout ( content_area) ;
9061 match ( & mut self . help_pane , & mut self . mark_pane ) {
9162 ( Some ( ref mut pane) , None ) => ( left_pane, Some ( ( right_pane, pane) ) , None ) ,
9263 ( None , Some ( ref mut pane) ) => ( left_pane, None , Some ( ( right_pane, pane) ) ) ,
9364 ( Some ( ref mut help) , Some ( ref mut mark) ) => {
94- let regions = Layout :: default ( )
95- . direction ( Direction :: Vertical )
96- . constraints ( [ Percentage ( 50 ) , Percentage ( 50 ) ] . as_ref ( ) )
97- . split ( right_pane) ;
98- (
99- left_pane,
100- Some ( ( regions[ 0 ] , help) ) ,
101- Some ( ( regions[ 1 ] , mark) ) ,
102- )
65+ let ( top_area, bottom_area) = right_pane_layout ( right_pane) ;
66+ ( left_pane, Some ( ( top_area, help) ) , Some ( ( bottom_area, mark) ) )
10367 }
104- ( None , None ) => ( entries_area , None , None ) ,
68+ ( None , None ) => ( content_area , None , None ) ,
10569 }
10670 } ;
10771
@@ -149,4 +113,58 @@ impl MainWindow {
149113 buf,
150114 ) ;
151115 }
116+
117+ fn is_anything_marked ( & self ) -> bool {
118+ self . mark_pane
119+ . as_ref ( )
120+ . map ( |p| p. marked ( ) )
121+ . map_or ( true , |m| m. is_empty ( ) )
122+ }
123+ }
124+
125+ fn right_pane_layout ( right_pane : Rect ) -> ( Rect , Rect ) {
126+ let regions = Layout :: default ( )
127+ . direction ( Direction :: Vertical )
128+ . constraints ( [ Percentage ( 50 ) , Percentage ( 50 ) ] . as_ref ( ) )
129+ . split ( right_pane) ;
130+ ( regions[ 0 ] , regions[ 1 ] )
131+ }
132+
133+ fn content_layout ( content_area : Rect ) -> ( Rect , Rect ) {
134+ let regions = Layout :: default ( )
135+ . direction ( Direction :: Horizontal )
136+ . constraints ( [ Percentage ( 50 ) , Percentage ( 50 ) ] . as_ref ( ) )
137+ . split ( content_area) ;
138+ ( regions[ 0 ] , regions[ 1 ] )
139+ }
140+
141+ fn header_background_color ( is_marked : bool , focused_pane : FocussedPane ) -> Color {
142+ match ( is_marked, focused_pane) {
143+ ( false , Mark ) => Color :: LightRed ,
144+ ( false , _) => COLOR_MARKED ,
145+ ( _, _) => Color :: White ,
146+ }
147+ }
148+
149+ fn main_window_layout ( area : Rect ) -> ( Rect , Rect , Rect ) {
150+ let regions = Layout :: default ( )
151+ . direction ( Direction :: Vertical )
152+ . constraints ( [ Length ( 1 ) , Max ( 256 ) , Length ( 1 ) ] . as_ref ( ) )
153+ . split ( area) ;
154+ ( regions[ 0 ] , regions[ 1 ] , regions[ 2 ] )
155+ }
156+
157+ fn pane_border_style ( focused_pane : FocussedPane ) -> ( Style , Style , Style ) {
158+ let grey = Style {
159+ fg : Color :: DarkGray . into ( ) ,
160+ bg : Color :: Reset . into ( ) ,
161+ add_modifier : Modifier :: empty ( ) ,
162+ ..Style :: default ( )
163+ } ;
164+ let bold = Style :: default ( ) . add_modifier ( Modifier :: BOLD ) ;
165+ match focused_pane {
166+ Main => ( bold, grey, grey) ,
167+ Help => ( grey, bold, grey) ,
168+ Mark => ( grey, grey, bold) ,
169+ }
152170}
0 commit comments