diff options
author | Joris | 2025-02-07 14:36:58 +0100 |
---|---|---|
committer | Joris | 2025-02-07 14:36:58 +0100 |
commit | 9af9c844c9c481c2d8db21545d97f069552f40ec (patch) | |
tree | ae22f30721a5eb519ea9ab937d5335af1d3f3107 /src/gui | |
parent | 459c296daf64fa88e8cb5c64dfcbbb9d05c21a71 (diff) |
Adapt layout sizes
Prevent negative usize errors to stop the program.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/message.rs | 2 | ||||
-rw-r--r-- | src/gui/question.rs | 10 | ||||
-rw-r--r-- | src/gui/util.rs | 4 |
3 files changed, 8 insertions, 8 deletions
diff --git a/src/gui/message.rs b/src/gui/message.rs index 3273b31..0ae98a2 100644 --- a/src/gui/message.rs +++ b/src/gui/message.rs @@ -19,7 +19,7 @@ pub fn show<B: Backend>( let chunks = Layout::default() .direction(Direction::Vertical) .margin(2) - .constraints([Constraint::Length(1), Constraint::Percentage(50)].as_ref()) + .constraints([Constraint::Percentage(15), Constraint::Percentage(40)].as_ref()) .split(f.area()); let d1 = util::title(title); diff --git a/src/gui/question.rs b/src/gui/question.rs index 2a42e57..37ea43d 100644 --- a/src/gui/question.rs +++ b/src/gui/question.rs @@ -42,11 +42,11 @@ pub fn ask<B: Backend>(terminal: &mut Terminal<B>, title: &str, card: &Card) -> .margin(2) .constraints( [ - Constraint::Length(1), - Constraint::Percentage(30), - Constraint::Length(5), - Constraint::Percentage(30), - Constraint::Length(5), + Constraint::Percentage(15), + Constraint::Percentage(25), + Constraint::Percentage(15), + Constraint::Percentage(15), + Constraint::Percentage(15), ] .as_ref(), ) diff --git a/src/gui/util.rs b/src/gui/util.rs index c62c755..4503ed4 100644 --- a/src/gui/util.rs +++ b/src/gui/util.rs @@ -14,8 +14,8 @@ pub fn title(str: &str) -> Paragraph { pub fn center_vertically(chunk: Rect, text: &str) -> String { let text_lines = text.lines().count(); - let chunk_inner_lines: usize = (chunk.height - 2).into(); - let blank_lines = chunk_inner_lines - text_lines; + let chunk_inner_lines: usize = if chunk.height >= 2 { (chunk.height - 2).into() } else { 0 }; + let blank_lines = if chunk_inner_lines >= text_lines { chunk_inner_lines - text_lines } else { 0 }; let newlines = "\n".repeat(blank_lines / 2); format!("{newlines}{text}") } |