commit popup centered

This commit is contained in:
Stephan Dilly 2020-03-18 10:45:57 +01:00
parent 7b289ab71b
commit 472bec5db3
4 changed files with 31 additions and 2 deletions

View File

@ -19,7 +19,7 @@ Over the last 2 years my go to GUI tool for this was [fork](https://git-fork.com
* [x] support staging
* [x] show added files on working dir changes
* [x] support committing
* [ ] popup centered
* [x] popup centered
* [ ] crash: adding a pic to index crashes
* [ ] crash: renamed files cannot be added to index
* [ ] allow selecting/diff index items

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 166 KiB

View File

@ -186,7 +186,7 @@ impl App {
.block(Block::default().title("Commit").borders(Borders::ALL))
.alignment(Alignment::Left),
)
.render(f, Rect::new(20, 0, 100, 10));
.render(f, git_utils::centered_rect(60, 20, f.size()));
}
}

View File

@ -1,5 +1,6 @@
use git2::{DiffFormat, DiffOptions, Repository};
use std::path::Path;
use tui::layout::{Constraint, Direction, Layout, Rect};
///
#[derive(Copy, Clone, PartialEq)]
@ -103,3 +104,31 @@ pub fn commit(msg: &String) {
)
.unwrap();
}
/// use layouts to create a rects that
/// centers inside `r` and sizes `percent_x`/`percent_x` of `r`
pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
let popup_layout = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Percentage((100 - percent_y) / 2),
Constraint::Percentage(percent_y),
Constraint::Percentage((100 - percent_y) / 2),
]
.as_ref(),
)
.split(r);
Layout::default()
.direction(Direction::Horizontal)
.constraints(
[
Constraint::Percentage((100 - percent_x) / 2),
Constraint::Percentage(percent_x),
Constraint::Percentage((100 - percent_x) / 2),
]
.as_ref(),
)
.split(popup_layout[1])[1]
}