mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-27 00:14:52 +03:00
fix: panic on small terminal when textinput for stash name is open
This commit is contained in:
parent
a75f43de77
commit
603fd75703
@ -23,6 +23,7 @@ use tui::{
|
||||
Frame,
|
||||
};
|
||||
|
||||
use crate::ui::Size;
|
||||
use anyhow::Result;
|
||||
use ui::style::SharedTheme;
|
||||
|
||||
@ -43,15 +44,16 @@ impl DrawableComponent for SelectBranchComponent {
|
||||
rect: Rect,
|
||||
) -> Result<()> {
|
||||
if self.visible {
|
||||
const PERCENT_SIZE: (u16, u16) = (60, 25);
|
||||
const MIN_SIZE: (u16, u16) = (50, 20);
|
||||
const PERCENT_SIZE: Size = Size::new(60, 25);
|
||||
const MIN_SIZE: Size = Size::new(50, 20);
|
||||
|
||||
let area = ui::centered_rect(
|
||||
PERCENT_SIZE.0,
|
||||
PERCENT_SIZE.1,
|
||||
PERCENT_SIZE.width,
|
||||
PERCENT_SIZE.height,
|
||||
f.size(),
|
||||
);
|
||||
let area = ui::rect_min(MIN_SIZE.0, MIN_SIZE.1, area);
|
||||
let area =
|
||||
ui::rect_inside(&MIN_SIZE, &f.size().into(), area);
|
||||
let area = area.intersection(rect);
|
||||
|
||||
let scroll_threshold = area.height / 3;
|
||||
|
@ -1,3 +1,4 @@
|
||||
use crate::ui::Size;
|
||||
use crate::{
|
||||
components::{
|
||||
popup_paragraph, visibility_blocking, CommandBlocking,
|
||||
@ -200,7 +201,11 @@ impl DrawableComponent for TextInputComponent {
|
||||
let area = match self.input_type {
|
||||
InputType::Multiline => {
|
||||
let area = ui::centered_rect(60, 20, f.size());
|
||||
ui::rect_min(10, 3, area)
|
||||
ui::rect_inside(
|
||||
&Size::new(10, 3),
|
||||
&f.size().into(),
|
||||
area,
|
||||
)
|
||||
}
|
||||
_ => ui::centered_rect_absolute(32, 3, f.size()),
|
||||
};
|
||||
|
@ -21,6 +21,24 @@ pub const fn calc_scroll_top(
|
||||
}
|
||||
}
|
||||
|
||||
/// ui component size representation
|
||||
pub struct Size {
|
||||
pub width: u16,
|
||||
pub height: u16,
|
||||
}
|
||||
|
||||
impl Size {
|
||||
pub const fn new(width: u16, height: u16) -> Self {
|
||||
Self { width, height }
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Size> for Rect {
|
||||
fn into(self) -> Size {
|
||||
Size::new(self.width, self.height)
|
||||
}
|
||||
}
|
||||
|
||||
/// use layouts to create a rects that
|
||||
/// centers inside `r` and sizes `percent_x`/`percent_x` of `r`
|
||||
pub fn centered_rect(
|
||||
@ -53,10 +71,10 @@ pub fn centered_rect(
|
||||
.split(popup_layout[1])[1]
|
||||
}
|
||||
|
||||
/// makes sure Rect `r` at least stays as big as `width` & `height`
|
||||
pub fn rect_min(width: u16, height: u16, r: Rect) -> Rect {
|
||||
let new_width = r.width.max(width);
|
||||
let new_height = r.height.max(height);
|
||||
/// makes sure Rect `r` at least stays as big as min and not bigger than max
|
||||
pub fn rect_inside(min: &Size, max: &Size, r: Rect) -> Rect {
|
||||
let new_width = r.width.max(min.width).min(max.width);
|
||||
let new_height = r.height.max(min.height).min(max.height);
|
||||
let diff_width = new_width.saturating_sub(r.width);
|
||||
let diff_height = new_height.saturating_sub(r.height);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user