Fix appearance issues of game maps
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		@@ -20,7 +20,9 @@ use crate::constants::*;
 | 
			
		||||
use crate::ui_screens::confirm_dialog_screen::confirm;
 | 
			
		||||
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::utils::{
 | 
			
		||||
    centered_rect_size, centered_rect_size_horizontally, centered_text,
 | 
			
		||||
};
 | 
			
		||||
use crate::ui_screens::ScreenResult;
 | 
			
		||||
use crate::ui_widgets::button_widget::ButtonWidget;
 | 
			
		||||
use crate::ui_widgets::game_map_widget::{ColoredCells, GameMapWidget};
 | 
			
		||||
@@ -576,11 +578,11 @@ impl GameScreen {
 | 
			
		||||
 | 
			
		||||
            f.render_widget(
 | 
			
		||||
                player_map,
 | 
			
		||||
                centered_rect_size(player_map_size.0, player_map_size.1, &maps_chunks[0]),
 | 
			
		||||
                centered_rect_size_horizontally(player_map_size.0, &maps_chunks[0]),
 | 
			
		||||
            );
 | 
			
		||||
            f.render_widget(
 | 
			
		||||
                opponent_map,
 | 
			
		||||
                centered_rect_size(opponent_map_size.0, opponent_map_size.1, &maps_chunks[1]),
 | 
			
		||||
                centered_rect_size_horizontally(opponent_map_size.0, &maps_chunks[1]),
 | 
			
		||||
            );
 | 
			
		||||
        } else {
 | 
			
		||||
            // Render a single map
 | 
			
		||||
 
 | 
			
		||||
@@ -46,6 +46,25 @@ pub fn centered_rect_size(width: u16, height: u16, parent: &Rect) -> Rect {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// helper function to create a centered rect using up certain container size, only horizontally
 | 
			
		||||
pub fn centered_rect_size_horizontally(width: u16, parent: &Rect) -> Rect {
 | 
			
		||||
    if parent.width < width {
 | 
			
		||||
        return Rect {
 | 
			
		||||
            x: parent.x,
 | 
			
		||||
            y: parent.y,
 | 
			
		||||
            width: parent.width,
 | 
			
		||||
            height: parent.height,
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Rect {
 | 
			
		||||
        x: parent.x + (parent.width - width) / 2,
 | 
			
		||||
        y: parent.y,
 | 
			
		||||
        width,
 | 
			
		||||
        height: parent.height,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get coordinates to render centered text
 | 
			
		||||
pub fn centered_text(text: &str, container: &Rect) -> Rect {
 | 
			
		||||
    if text.len() > container.width as usize {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user