Skip to content

Commit 18f3bd9

Browse files
author
Stephan Dilly
committed
min rect size for commit popup (fixes #179)
1 parent dc5911d commit 18f3bd9

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- `add_to_ignore` failed on files without a newline at EOF ([#191](https://github.com/extrawurst/gitui/issues/191))
1717
- new tags were not picked up in revlog view ([#190](https://github.com/extrawurst/gitui/issues/190))
1818
- tags not shown in commit details popup ([#193](https://github.com/extrawurst/gitui/issues/193))
19+
- min size for relative popups on small terminals ([#179](https://github.com/extrawurst/gitui/issues/179))
1920

2021
## [0.8.1] - 2020-07-07
2122

src/components/filetree.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use crate::{
1616
use anyhow::Result;
1717
use asyncgit::{hash, StatusItem, StatusItemType};
1818
use crossterm::event::Event;
19-
use std::cell::Cell;
20-
use std::{borrow::Cow, convert::From, path::Path};
19+
use std::{borrow::Cow, cell::Cell, convert::From, path::Path};
2120
use tui::{backend::Backend, layout::Rect, widgets::Text, Frame};
2221

2322
///

src/components/textinput.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ impl DrawableComponent for TextInputComponent {
170170
};
171171

172172
let area = ui::centered_rect(60, 20, f.size());
173+
let area = ui::rect_min(10, 3, area);
174+
173175
f.render_widget(Clear, area);
174176
f.render_widget(
175177
popup_paragraph(

src/ui/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ pub fn centered_rect(
5757
.split(popup_layout[1])[1]
5858
}
5959

60+
/// makes sure Rect `r` at least stays as big as `width`/`height`
61+
pub fn rect_min(width: u16, height: u16, r: Rect) -> Rect {
62+
let new_width = r.width.max(width);
63+
let new_height = r.height.max(height);
64+
let diff_width = new_width.saturating_sub(r.width);
65+
let diff_height = new_height.saturating_sub(r.height);
66+
67+
Rect::new(
68+
r.x.saturating_sub(diff_width / 2),
69+
r.y.saturating_sub(diff_height / 2),
70+
new_width,
71+
new_height,
72+
)
73+
}
74+
6075
pub fn centered_rect_absolute(
6176
width: u16,
6277
height: u16,

0 commit comments

Comments
 (0)