@@ -119,6 +119,8 @@ pub mod view {
119119 } ,
120120 } ;
121121
122+ const BAR_WIDTH : u16 = 19 ;
123+
122124 fn tabs < ' a > ( selected : & SelectedTab ) -> Tabs < ' a > {
123125 Tabs :: new ( vec ! [ " color codes to specs " , " specs to color codes " ] )
124126 . padding ( " " , " " )
@@ -481,7 +483,15 @@ pub mod view {
481483 . collect :: < Vec < ( String , String , Color , String ) > > ( ) ;
482484 let specs = resistor. specs ( ) ;
483485 let chart = barchart ( & band_infos, specs. ohm , specs. tolerance , specs. tcr ) ;
484- frame. render_widget ( chart, main_rect) ;
486+ let chart_length: u16 = {
487+ let bands_len: u16 = bands. len ( ) as u16 ;
488+ let bands_widths = bands_len * BAR_WIDTH ;
489+ let bands_gaps = bands_len - 1 ;
490+ let border_plus_margin = 4 ;
491+ bands_widths + bands_gaps + border_plus_margin
492+ } ;
493+ let centered_main_rect = center_horizontal ( main_rect, chart_length) ;
494+ frame. render_widget ( chart, centered_main_rect) ;
485495 }
486496 if let Some ( e) = & model. specs_to_color . error {
487497 let text = Text :: from ( e. to_string ( ) ) ;
@@ -519,7 +529,7 @@ pub mod view {
519529 . title ( title)
520530 . borders ( Borders :: all ( ) ) ,
521531 )
522- . bar_width ( 19 )
532+ . bar_width ( BAR_WIDTH )
523533 . bar_gap ( 1 )
524534 }
525535
0 commit comments