feat(tui): scale clockw font dynamically #11
cargo devel CI / cargo CI (push) Successful in 1m50s Details

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

View File

@ -324,12 +324,6 @@ impl Clock {
terminal: &mut Terminal<CrosstermBackend<Stdout>>, terminal: &mut Terminal<CrosstermBackend<Stdout>>,
data: &UiData, data: &UiData,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let clockw = tui_big_text::BigText::builder()
.style(Style::new().red())
.lines(vec![data.ftime().into()])
.alignment(Alignment::Center)
.build()
.expect("could not render time widget");
terminal.draw(|frame| { terminal.draw(|frame| {
debug!("rendering the ui"); debug!("rendering the ui");
let root = frame.size(); let root = frame.size();
@ -348,6 +342,20 @@ impl Clock {
frame.render_widget(space, root); frame.render_widget(space, root);
let parts = Self::partition(a); let parts = Self::partition(a);
let mut clockw = tui_big_text::BigText::builder();
if a.width > 80 {
clockw.pixel_size(tui_big_text::PixelSize::Full);
} else {
clockw.pixel_size(tui_big_text::PixelSize::Quadrant);
}
let clockw = clockw
.style(Style::new().red())
.lines(vec![data.ftime().into()])
.alignment(Alignment::Center)
.build()
.expect("could not render time widget");
// render the timebar which counts up to the full minute and so on // render the timebar which counts up to the full minute and so on
// //
// Will not be rendered if it is None // Will not be rendered if it is None
@ -377,10 +385,10 @@ impl Clock {
Style::default().blue() Style::default().blue()
}) })
.unfilled_style(Style::default()) .unfilled_style(Style::default())
.block(Block::default().padding(Padding::right(if root.width > 80 { .block(Block::default().padding(Padding::right(if a.width > 80 {
(f32::from(parts[2].width) * 0.43) as u16 (f32::from(parts[2].width) * 0.43) as u16
} else { } else {
2 (f32::from(parts[2].width) * 0.25) as u16
}))) })))
.ratio(ratio); .ratio(ratio);
Some(timebarw) Some(timebarw)
@ -476,7 +484,10 @@ 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::Length(3)]) .constraints([
Constraint::Length(if r.width > 80 { 8 } else { 5 }),
Constraint::Length(3),
])
.split(r); .split(r);
let hlen_date: u16 = (f32::from(part[1].width) * 0.35) as u16; let hlen_date: u16 = (f32::from(part[1].width) * 0.35) as u16;
let subparts = Layout::default() let subparts = Layout::default()