diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e777b1f..da1e8f0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `add_to_ignore` failed on files without a newline at EOF ([#191](https://github.com/extrawurst/gitui/issues/191)) - new tags were not picked up in revlog view ([#190](https://github.com/extrawurst/gitui/issues/190)) - tags not shown in commit details popup ([#193](https://github.com/extrawurst/gitui/issues/193)) +- min size for relative popups on small terminals ([#179](https://github.com/extrawurst/gitui/issues/179)) ## [0.8.1] - 2020-07-07 diff --git a/src/components/filetree.rs b/src/components/filetree.rs index 1f46f906..b7c77c23 100644 --- a/src/components/filetree.rs +++ b/src/components/filetree.rs @@ -16,8 +16,7 @@ use crate::{ use anyhow::Result; use asyncgit::{hash, StatusItem, StatusItemType}; use crossterm::event::Event; -use std::cell::Cell; -use std::{borrow::Cow, convert::From, path::Path}; +use std::{borrow::Cow, cell::Cell, convert::From, path::Path}; use tui::{backend::Backend, layout::Rect, widgets::Text, Frame}; /// diff --git a/src/components/textinput.rs b/src/components/textinput.rs index d5de6b2c..67c8b98f 100644 --- a/src/components/textinput.rs +++ b/src/components/textinput.rs @@ -170,6 +170,8 @@ impl DrawableComponent for TextInputComponent { }; let area = ui::centered_rect(60, 20, f.size()); + let area = ui::rect_min(10, 3, area); + f.render_widget(Clear, area); f.render_widget( popup_paragraph( diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 26721ffe..5c8ad32a 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -57,6 +57,21 @@ 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); + let diff_width = new_width.saturating_sub(r.width); + let diff_height = new_height.saturating_sub(r.height); + + Rect::new( + r.x.saturating_sub(diff_width / 2), + r.y.saturating_sub(diff_height / 2), + new_width, + new_height, + ) +} + pub fn centered_rect_absolute( width: u16, height: u16,