From 3b44ac5b06201a48e3b6b983ca775165839705c6 Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Sun, 25 Oct 2020 23:48:50 +0100 Subject: [PATCH] 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) --- src/cmdbar.rs | 2 +- src/components/help.rs | 3 +-- src/components/select_branch.rs | 32 ++++++++++---------------------- src/ui/mod.rs | 2 +- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/cmdbar.rs b/src/cmdbar.rs index 0a5d420b..dc227723 100644 --- a/src/cmdbar.rs +++ b/src/cmdbar.rs @@ -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( diff --git a/src/components/help.rs b/src/components/help.rs index e1b90cf0..bba6a8c2 100644 --- a/src/components/help.rs +++ b/src/components/help.rs @@ -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; /// diff --git a/src/components/select_branch.rs b/src/components/select_branch.rs index 1ef99017..4cc404b5 100644 --- a/src/components/select_branch.rs +++ b/src/components/select_branch.rs @@ -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( &self, f: &mut Frame, - _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, ); } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 9ec03804..606dad98 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -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);