Skip to content

Commit b33829b

Browse files
authored
Merge pull request #9 from dawedawe/center_tab2
Center color codes on tab 2
2 parents 1baa693 + 52a6106 commit b33829b

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository = "https://github.com/dawedawe/tusistor"
88

99
[package]
1010
name = "tusistor"
11-
version = "0.5.0"
11+
version = "0.6.0"
1212
authors.workspace = true
1313
license.workspace = true
1414
edition.workspace = true

src/app.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tusistor2.png

-414 Bytes
Loading

0 commit comments

Comments
 (0)