refactor(tui): widgets (besides clockw) are now visible in small horizontal terminals #11
cargo devel CI / cargo CI (push) Successful in 1m46s Details

This commit is contained in:
Christoph J. Scherr 2024-07-12 16:23:26 +02:00
parent 9a2629c273
commit 83e318559e
1 changed files with 20 additions and 24 deletions

View File

@ -325,7 +325,7 @@ impl Clock {
data: &UiData, data: &UiData,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let clockw = tui_big_text::BigText::builder() let clockw = tui_big_text::BigText::builder()
.style(Style::new().red().on_light_blue()) .style(Style::new().red())
.lines(vec![data.ftime().into()]) .lines(vec![data.ftime().into()])
.alignment(Alignment::Center) .alignment(Alignment::Center)
.build() .build()
@ -335,10 +335,10 @@ impl Clock {
let root = frame.size(); let root = frame.size();
let space = Block::bordered() let space = Block::bordered()
.padding(Padding::new( .padding(Padding::new(
root.width / 8, root.width / 16,
root.width / 8, root.width / 16,
root.height / 8, root.height / 16,
root.height / 8, root.height / 16,
)) ))
.title(env!("CARGO_PKG_NAME")) .title(env!("CARGO_PKG_NAME"))
.title_bottom(env!("CARGO_PKG_VERSION")) .title_bottom(env!("CARGO_PKG_VERSION"))
@ -365,7 +365,7 @@ impl Clock {
} }
} }
let tmp = LineGauge::default() let timebarw = LineGauge::default()
.filled_style(if self.did_notify { .filled_style(if self.did_notify {
Style::default() Style::default()
.slow_blink() .slow_blink()
@ -376,16 +376,14 @@ impl Clock {
} else { } else {
Style::default().blue() Style::default().blue()
}) })
.on_cyan()
.unfilled_style(Style::default()) .unfilled_style(Style::default())
.block(Block::new().padding(Padding::new( .block(Block::default().padding(Padding::right(if root.width > 80 {
parts[2].left() / 10, (f32::from(parts[2].width) * 0.43) as u16
parts[2].right() / 6, } else {
0, 2
0, })))
)))
.ratio(ratio); .ratio(ratio);
Some(tmp) Some(timebarw)
} else { } else {
None None
}; };
@ -393,14 +391,8 @@ impl Clock {
// render the small date // render the small date
let datew = Paragraph::new(data.fdate()) let datew = Paragraph::new(data.fdate())
.blue() .blue()
.alignment(Alignment::Left) .block(Block::default().padding(Padding::right(2)))
.on_gray() .alignment(Alignment::Right);
.block(Block::new().padding(Padding::new(
parts[1].left(),
parts[1].right() / 3,
0,
0,
)));
frame.render_widget(&timebarw, parts[2]); frame.render_widget(&timebarw, parts[2]);
frame.render_widget(datew, parts[1]); frame.render_widget(datew, parts[1]);
// render the clock // render the clock
@ -484,11 +476,15 @@ impl Clock {
fn partition(r: Rect) -> Vec<Rect> { fn partition(r: Rect) -> Vec<Rect> {
let part = Layout::default() let part = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
.constraints([Constraint::Length(8), Constraint::Min(0)]) .constraints([Constraint::Length(8), Constraint::Length(3)])
.split(r); .split(r);
let hlen_date: u16 = (f32::from(part[1].width) * 0.35) as u16;
let subparts = Layout::default() let subparts = Layout::default()
.direction(Direction::Horizontal) .direction(Direction::Horizontal)
.constraints([Constraint::Min(10), Constraint::Ratio(1, 2)]) .constraints([
Constraint::Length(hlen_date),
Constraint::Length(part[1].width - hlen_date),
])
.split(part[1]); .split(part[1]);
vec![part[0], subparts[0], subparts[1]] vec![part[0], subparts[0], subparts[1]]