fix(chrono,timer): state text position

This commit is contained in:
Pihkaal
2024-03-23 03:09:48 +01:00
parent 02ff709718
commit f929b53ae6
2 changed files with 16 additions and 26 deletions

View File

@@ -195,13 +195,10 @@ fn render_frame(
// Display pause state // Display pause state
if chronometer.is_paused() { if chronometer.is_paused() {
let text = "[PAUSE]"; let text = "[PAUSE]";
let x = width / 2 - (text.len() as i16) / 2; let x = width / 2 - (text.len() as i16) / 2 - 1;
rendering::draw_text( let y = y - symbols::SYMBOL_HEIGHT as i16 + symbols::SYMBOL_HEIGHT as i16 / 2 + 1;
text,
x, rendering::draw_text(text, x, y, color)?;
y - symbols::SYMBOL_HEIGHT as i16 - symbols::SYMBOL_HEIGHT as i16 / 2,
color,
)?;
} }
return Ok(()); return Ok(());

View File

@@ -126,31 +126,24 @@ fn render_frame(config: &Config, timer: &Timer) -> io::Result<()> {
let remaining = utils::format_duration(timer.time_left()); let remaining = utils::format_duration(timer.time_left());
rendering::draw_time(&remaining, color)?; rendering::draw_time(&remaining, color)?;
// Display pause state
let (width, height) = rendering::get_terminal_size()?; let (width, height) = rendering::get_terminal_size()?;
let y = height / 2 + symbols::SYMBOL_HEIGHT as i16 / 2 + 2; let y = height / 2 + symbols::SYMBOL_HEIGHT as i16 / 2 + 2;
if timer.is_paused() {
let text = "[PAUSE]";
let x = width / 2 - (text.len() as i16) / 2;
rendering::draw_text(
text,
x,
y - symbols::SYMBOL_HEIGHT as i16 - symbols::SYMBOL_HEIGHT as i16 / 2,
color,
)?;
}
// Display finish state // Display finish state
else if timer.is_finished() { if timer.is_finished() {
let text = "[FINISHED]"; let text = "[FINISHED]";
let x = width / 2 - (text.len() as i16) / 2; let x = width / 2 - (text.len() as i16) / 2 - 1;
let y = y - symbols::SYMBOL_HEIGHT as i16 + symbols::SYMBOL_HEIGHT as i16 / 2 + 1;
rendering::draw_text( rendering::draw_text(text, x, y, color)?;
text, }
x, // Display pause state
y - symbols::SYMBOL_HEIGHT as i16 - symbols::SYMBOL_HEIGHT as i16 / 2, else if timer.is_paused() {
color, let text = "[PAUSE]";
)?; let x = width / 2 - (text.len() as i16) / 2 - 1;
let y = y - symbols::SYMBOL_HEIGHT as i16 + symbols::SYMBOL_HEIGHT as i16 / 2 + 1;
rendering::draw_text(text, x, y, color)?;
} }
return Ok(()); return Ok(());