Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix issue #508 by calculating space manually
This commit improves the centering of the basic_view_widget and thus
fixeds the issue #508 by manually calculating the space between the top
and the bottom bezel of the terminal.
  • Loading branch information
OrangeFran committed Nov 14, 2020
commit d13f98383aa2657b68cae41a3d76dc7d0d78d8ef
31 changes: 17 additions & 14 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use tui::{
use util::{
create_artist_string, display_track_progress, get_artist_highlight_state, get_color,
get_percentage_width, get_search_results_highlight_state, get_track_progress_percentage,
millis_to_minutes, SMALL_TERMINAL_WIDTH,
millis_to_minutes, BASIC_VIEW_HEIGHT, SMALL_TERMINAL_WIDTH,
};

pub enum TableId {
Expand Down Expand Up @@ -831,20 +831,23 @@ pub fn draw_basic_view<B>(f: &mut Frame<B>, app: &App)
where
B: Backend,
{
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Percentage(44),
Constraint::Min(6),
Constraint::Percentage(44),
]
.as_ref(),
)
.margin(4)
.split(f.size());
// If space is negative, do nothing because the widget would not fit
if let Some(s) = app.size.height.checked_sub(BASIC_VIEW_HEIGHT) {
let space = s / 2;
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(
[
Constraint::Length(space),
Constraint::Length(BASIC_VIEW_HEIGHT),
Constraint::Length(space),
]
.as_ref(),
)
.split(f.size());

draw_playbar(f, app, chunks[1]);
draw_playbar(f, app, chunks[1]);
}
}

pub fn draw_playbar<B>(f: &mut Frame<B>, app: &App, layout_chunk: Rect)
Expand Down
1 change: 1 addition & 0 deletions src/ui/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::user_config::Theme;
use rspotify::model::artist::SimplifiedArtist;
use tui::style::Style;

pub const BASIC_VIEW_HEIGHT: u16 = 6;
pub const SMALL_TERMINAL_WIDTH: u16 = 150;
pub const SMALL_TERMINAL_HEIGHT: u16 = 45;

Expand Down