refactor: popup() use saturating_x() rather than checked_x()

This commit is contained in:
Jack Wills
2023-03-30 02:28:53 +00:00
parent b9c125da46
commit d628e80299
+2 -4
View File
@@ -11,7 +11,7 @@ use ratatui::{
}, },
Frame, Frame,
}; };
use std::default::Default; use std::{default::Default, ops::Sub};
use std::{fmt::Display, sync::Arc}; use std::{fmt::Display, sync::Arc};
use crate::app_data::{Header, SortedOrder}; use crate::app_data::{Header, SortedOrder};
@@ -898,9 +898,7 @@ pub fn info<B: Backend>(f: &mut Frame<'_, B>, text: String) {
fn popup(text_lines: usize, text_width: usize, r: Rect, box_location: BoxLocation) -> Rect { fn popup(text_lines: usize, text_width: usize, r: Rect, box_location: BoxLocation) -> Rect {
// Make sure blank_space can't be an negative, as will crash // Make sure blank_space can't be an negative, as will crash
let calc = |x: u16, y: usize| { let calc = |x: u16, y: usize| {
(usize::from(x).checked_sub(y).map_or(1usize, |f| f)) usize::from(x).saturating_sub(y).saturating_div(2)
.checked_div(2)
.map_or(1usize, |f| f)
}; };
let blank_vertical = calc(r.height, text_lines); let blank_vertical = calc(r.height, text_lines);