1
0
mirror of https://github.com/danog/ytop.git synced 2024-11-26 12:04:50 +01:00

fix crash when window is too small on help menu

is related to #22
This commit is contained in:
Mario Reder 2020-04-23 12:50:27 +02:00
parent 74f697f6dc
commit a3d13cedf8

View File

@ -1,4 +1,5 @@
use once_cell::sync::Lazy;
use std::cmp;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::widgets::{Paragraph, Text, Widget};
@ -58,10 +59,10 @@ impl HelpMenu<'_> {
pub fn get_rect(&self, area: Rect) -> Rect {
Rect {
x: (area.width - TEXT_WIDTH) / 2,
y: (area.height - TEXT_HEIGHT) / 2,
width: TEXT_WIDTH,
height: TEXT_HEIGHT,
x: area.width.checked_sub(TEXT_WIDTH).unwrap_or_default() / 2,
y: area.height.checked_sub(TEXT_HEIGHT).unwrap_or_default() / 2,
width: cmp::min(TEXT_WIDTH, area.width),
height: cmp::min(TEXT_HEIGHT, area.height),
}
}
}