mirror of
https://github.com/extrawurst/gitui.git
synced 2024-12-29 03:51:48 +03:00
fix branch list and cmd bar panicing on small terminal sizes (#369)
fix branch list and cmd bar panicing on small terminal sizes (closes #363)
This commit is contained in:
parent
42d4609c41
commit
3b44ac5b06
@ -186,7 +186,7 @@ impl CommandBar {
|
||||
r.width.saturating_sub(MORE_WIDTH),
|
||||
r.y + r.height.saturating_sub(1),
|
||||
MORE_WIDTH.min(r.width),
|
||||
1,
|
||||
1.min(r.height),
|
||||
);
|
||||
|
||||
f.render_widget(
|
||||
|
@ -3,6 +3,7 @@ use super::{
|
||||
DrawableComponent,
|
||||
};
|
||||
use crate::{keys::SharedKeyConfig, strings, ui, version::Version};
|
||||
use anyhow::Result;
|
||||
use asyncgit::hash;
|
||||
use crossterm::event::Event;
|
||||
use itertools::Itertools;
|
||||
@ -15,8 +16,6 @@ use tui::{
|
||||
widgets::{Block, BorderType, Borders, Clear, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
use anyhow::Result;
|
||||
use ui::style::SharedTheme;
|
||||
|
||||
///
|
||||
|
@ -17,7 +17,7 @@ use crossterm::event::Event;
|
||||
use std::{cmp, convert::TryFrom};
|
||||
use tui::{
|
||||
backend::Backend,
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
layout::{Alignment, Rect},
|
||||
text::{Span, Spans, Text},
|
||||
widgets::{Block, BorderType, Borders, Clear, Paragraph},
|
||||
Frame,
|
||||
@ -40,10 +40,8 @@ impl DrawableComponent for SelectBranchComponent {
|
||||
fn draw<B: Backend>(
|
||||
&self,
|
||||
f: &mut Frame<B>,
|
||||
_rect: Rect,
|
||||
rect: Rect,
|
||||
) -> Result<()> {
|
||||
// Render a scrolllist of branches inside a box
|
||||
|
||||
if self.visible {
|
||||
const PERCENT_SIZE: (u16, u16) = (60, 25);
|
||||
const MIN_SIZE: (u16, u16) = (50, 20);
|
||||
@ -54,36 +52,26 @@ impl DrawableComponent for SelectBranchComponent {
|
||||
f.size(),
|
||||
);
|
||||
let area = ui::rect_min(MIN_SIZE.0, MIN_SIZE.1, area);
|
||||
let area = area.intersection(rect);
|
||||
|
||||
let scroll_threshold = area.height / 3;
|
||||
let scroll =
|
||||
self.selection.saturating_sub(scroll_threshold);
|
||||
|
||||
f.render_widget(Clear, area);
|
||||
f.render_widget(
|
||||
Block::default()
|
||||
.title(strings::SELECT_BRANCH_POPUP_MSG)
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Thick),
|
||||
area,
|
||||
);
|
||||
|
||||
let chunk = Layout::default()
|
||||
.vertical_margin(1)
|
||||
.horizontal_margin(1)
|
||||
.direction(Direction::Vertical)
|
||||
.constraints(
|
||||
[Constraint::Min(1), Constraint::Length(1)]
|
||||
.as_ref(),
|
||||
)
|
||||
.split(area)[0];
|
||||
f.render_widget(
|
||||
Paragraph::new(
|
||||
self.get_text(&self.theme, area.width)?,
|
||||
)
|
||||
.block(
|
||||
Block::default()
|
||||
.title(strings::SELECT_BRANCH_POPUP_MSG)
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Thick),
|
||||
)
|
||||
.scroll((scroll, 0))
|
||||
.alignment(Alignment::Left),
|
||||
chunk,
|
||||
area,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ pub fn centered_rect(
|
||||
.split(popup_layout[1])[1]
|
||||
}
|
||||
|
||||
/// makes sure Rect `r` at least stays as big as `width`/`height`
|
||||
/// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user