Skip to content

Commit a2b33e9

Browse files
committed
center tabs and help message
1 parent 6b6d857 commit a2b33e9

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/app.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use color_eyre::Result;
22
use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind};
33
use ratatui::{
4-
layout::{Constraint, Direction, Layout},
4+
layout::{Constraint, Direction, Flex, Layout, Rect},
55
style::{Color, Modifier, Style},
6+
symbols,
67
text::{Line, Span, Text},
78
widgets::{
89
Bar, BarChart, BarGroup, Block, Borders, List, ListDirection, ListItem, ListState,
@@ -119,6 +120,7 @@ impl Default for Model {
119120
fn tabs<'a>(selected: &SelectedTab) -> Tabs<'a> {
120121
Tabs::new(vec![" color codes to specs ", " specs to color codes "])
121122
.padding(" ", " ")
123+
.divider(symbols::DOT)
122124
.select(selected)
123125
}
124126

@@ -208,6 +210,15 @@ fn band_list<'a>(band_idx: usize, bands: usize, is_focused: bool) -> List<'a> {
208210
}
209211

210212
pub fn view(model: &Model, frame: &mut Frame) {
213+
fn center_horizontal(area: Rect, width: u16) -> Rect {
214+
let [area] = Layout::horizontal([Constraint::Length(width)])
215+
.flex(Flex::Center)
216+
.areas(area);
217+
area
218+
}
219+
220+
let tabs_width = 49;
221+
211222
match model.selected_tab {
212223
SelectedTab::ColorCodesToSpecs => {
213224
let chunks = Layout::default()
@@ -223,8 +234,8 @@ pub fn view(model: &Model, frame: &mut Frame) {
223234
.as_ref(),
224235
)
225236
.split(frame.area());
226-
let tabs_rect = chunks[0];
227-
let help_msg_rect = chunks[3];
237+
let tabs_rect = center_horizontal(chunks[0], tabs_width);
238+
let help_msg_rect = center_horizontal(chunks[3], 89);
228239

229240
let spec_chuncks = Layout::default()
230241
.direction(Direction::Horizontal)
@@ -360,8 +371,8 @@ pub fn view(model: &Model, frame: &mut Frame) {
360371
])
361372
.split(chunks[2]);
362373

363-
let tabs_rect = chunks[0];
364-
let help_msg_rect = chunks[3];
374+
let tabs_rect = center_horizontal(chunks[0], tabs_width);
375+
let help_msg_rect = center_horizontal(chunks[3], 76);
365376
let resistance_rect = input_rects[0];
366377
let tolerance_rect = input_rects[1];
367378
let tcr_rect = input_rects[2];

tusistor.png

742 Bytes
Loading

0 commit comments

Comments
 (0)