Handle better small screens
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2022-10-17 09:42:24 +02:00
parent ccb3d36fae
commit e760bcbe33
5 changed files with 23 additions and 8 deletions

View File

@ -17,6 +17,7 @@ use tui::{Frame, Terminal};
use sea_battle_backend::data::GameRules;
use crate::constants::{HIGHLIGHT_COLOR, TICK_RATE};
use crate::ui_screens::popup_screen::show_screen_too_small_popup;
use crate::ui_screens::select_bot_type_screen::SelectBotTypeScreen;
use crate::ui_screens::utils::centered_rect_size;
use crate::ui_screens::ScreenResult;
@ -179,7 +180,14 @@ impl GameRulesConfigurationScreen {
}
fn ui<B: Backend>(&mut self, f: &mut Frame<B>) {
let area = centered_rect_size(50, 23, &f.size());
let (w, h) = (50, 23);
if f.size().width < w || f.size().height < h {
show_screen_too_small_popup(f);
return;
}
let area = centered_rect_size(w, h, &f.size());
let block = Block::default().title("Game rules").borders(Borders::ALL);
f.render_widget(block, area);

View File

@ -18,7 +18,7 @@ use sea_battle_backend::utils::time_utils::time;
use crate::client::Client;
use crate::constants::*;
use crate::ui_screens::confirm_dialog_screen::confirm;
use crate::ui_screens::popup_screen::PopupScreen;
use crate::ui_screens::popup_screen::{show_screen_too_small_popup, PopupScreen};
use crate::ui_screens::set_boats_layout_screen::SetBoatsLayoutScreen;
use crate::ui_screens::utils::{centered_rect_size, centered_text};
use crate::ui_screens::ScreenResult;
@ -544,7 +544,7 @@ impl GameScreen {
// Check if frame is too small
if max_width > f.size().width || total_height > f.size().height {
PopupScreen::new("Screen too small!").show_in_frame(f);
show_screen_too_small_popup(f);
return HashMap::default();
}

View File

@ -14,6 +14,12 @@ use crate::ui_screens::utils::centered_rect_size;
use crate::ui_screens::ScreenResult;
use crate::ui_widgets::button_widget::ButtonWidget;
/// Convenience function to inform user that his terminal window is too small to display the current
/// screen
pub fn show_screen_too_small_popup<B: Backend>(f: &mut Frame<B>) {
PopupScreen::new("Screen too small!").show_in_frame(f)
}
pub struct PopupScreen<'a> {
title: &'a str,
msg: &'a str,

View File

@ -14,7 +14,7 @@ use sea_battle_backend::data::*;
use crate::constants::*;
use crate::ui_screens::confirm_dialog_screen::confirm;
use crate::ui_screens::popup_screen::PopupScreen;
use crate::ui_screens::popup_screen::show_screen_too_small_popup;
use crate::ui_screens::utils::{centered_rect_size, centered_text};
use crate::ui_screens::ScreenResult;
use crate::ui_widgets::game_map_widget::{ColoredCells, GameMapWidget};
@ -229,8 +229,9 @@ impl<'a> SetBoatsLayoutScreen<'a> {
let (w, h) = game_map_widget.estimated_size();
if f.size().width < w || f.size().height + 3 < h {
PopupScreen::new("Screen too small!").show_in_frame(f);
if f.size().width < w || f.size().height < h + 3 {
// +3 = for errors
show_screen_too_small_popup(f);
drop(game_map_widget);
return coordinates_mapper;
}

View File

@ -77,8 +77,8 @@ impl<'a> GameMapWidget<'a> {
}
pub fn grid_size(&self) -> (u16, u16) {
let w = self.rules.map_width as u16 * 2 + 1;
let h = self.rules.map_height as u16 * 2 + 1;
let w = (self.rules.map_width as u16 * 2) + 2;
let h = (self.rules.map_height as u16 * 2) + 2;
(w, h)
}