diff --git a/rust/cli_player/src/ui_screens/configure_game_rules.rs b/rust/cli_player/src/ui_screens/configure_game_rules.rs index ab13e1f..1c5c436 100644 --- a/rust/cli_player/src/ui_screens/configure_game_rules.rs +++ b/rust/cli_player/src/ui_screens/configure_game_rules.rs @@ -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(&mut self, f: &mut Frame) { - 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); diff --git a/rust/cli_player/src/ui_screens/game_screen.rs b/rust/cli_player/src/ui_screens/game_screen.rs index 4d1dbe7..1224532 100644 --- a/rust/cli_player/src/ui_screens/game_screen.rs +++ b/rust/cli_player/src/ui_screens/game_screen.rs @@ -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(); } diff --git a/rust/cli_player/src/ui_screens/popup_screen.rs b/rust/cli_player/src/ui_screens/popup_screen.rs index 4b15b85..bfe90e6 100644 --- a/rust/cli_player/src/ui_screens/popup_screen.rs +++ b/rust/cli_player/src/ui_screens/popup_screen.rs @@ -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(f: &mut Frame) { + PopupScreen::new("Screen too small!").show_in_frame(f) +} + pub struct PopupScreen<'a> { title: &'a str, msg: &'a str, diff --git a/rust/cli_player/src/ui_screens/set_boats_layout_screen.rs b/rust/cli_player/src/ui_screens/set_boats_layout_screen.rs index bd371fa..e8993bc 100644 --- a/rust/cli_player/src/ui_screens/set_boats_layout_screen.rs +++ b/rust/cli_player/src/ui_screens/set_boats_layout_screen.rs @@ -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; } diff --git a/rust/cli_player/src/ui_widgets/game_map_widget.rs b/rust/cli_player/src/ui_widgets/game_map_widget.rs index 32b0ac9..4f680f2 100644 --- a/rust/cli_player/src/ui_widgets/game_map_widget.rs +++ b/rust/cli_player/src/ui_widgets/game_map_widget.rs @@ -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) }