Improve frame size
This commit is contained in:
		@@ -1,7 +1,7 @@
 | 
			
		||||
use std::io;
 | 
			
		||||
use std::time::{Duration, Instant};
 | 
			
		||||
 | 
			
		||||
use crate::ui_screens::utils::centered_rect;
 | 
			
		||||
use crate::ui_screens::utils::centered_rect_size;
 | 
			
		||||
use crossterm::event;
 | 
			
		||||
use crossterm::event::{Event, KeyCode};
 | 
			
		||||
use tui::backend::Backend;
 | 
			
		||||
@@ -80,7 +80,7 @@ pub fn select_play_mode<B: Backend>(
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn ui<B: Backend>(f: &mut Frame<B>, model: &mut SelectPlayModeScreen) {
 | 
			
		||||
    let area = centered_rect(60, 20, f.size());
 | 
			
		||||
    let area = centered_rect_size(50, 5, f.size());
 | 
			
		||||
 | 
			
		||||
    // Create a List from all list items and highlight the currently selected one
 | 
			
		||||
    let items = AVAILABLE_PLAY_MODES
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
use tui::layout::{Constraint, Direction, Layout, Rect};
 | 
			
		||||
 | 
			
		||||
/// helper function to create a centered rect using up certain percentage of the available rect `r`
 | 
			
		||||
pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
 | 
			
		||||
pub fn centered_rect_percentage(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
 | 
			
		||||
    let popup_layout = Layout::default()
 | 
			
		||||
        .direction(Direction::Vertical)
 | 
			
		||||
        .constraints(
 | 
			
		||||
@@ -26,3 +26,22 @@ pub fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
 | 
			
		||||
        )
 | 
			
		||||
        .split(popup_layout[1])[1]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// helper function to create a centered rect using up certain container size
 | 
			
		||||
pub fn centered_rect_size(width: u16, height: u16, parent: Rect) -> Rect {
 | 
			
		||||
    if parent.width < width || parent.height < height {
 | 
			
		||||
        return Rect {
 | 
			
		||||
            x: 0,
 | 
			
		||||
            y: 0,
 | 
			
		||||
            width: parent.width,
 | 
			
		||||
            height: parent.height,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Rect {
 | 
			
		||||
        x: (parent.width - width) / 2,
 | 
			
		||||
        y: (parent.height - height) / 2,
 | 
			
		||||
        width,
 | 
			
		||||
        height,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user