diff --git a/rust/cli_player/src/ui_screens/set_boats_layout.rs b/rust/cli_player/src/ui_screens/set_boats_layout.rs index 4f8ee9a..b3433d0 100644 --- a/rust/cli_player/src/ui_screens/set_boats_layout.rs +++ b/rust/cli_player/src/ui_screens/set_boats_layout.rs @@ -81,7 +81,7 @@ fn ui(f: &mut Frame, model: &mut SetBotsLayoutScreen, rules: &Gam .set_default_empty_char(' ') .add_colored_cells(current_boat) .add_colored_cells(other_boats) - .set_title("Now, configure your boats") + .set_title("Choose your boat layout") .set_legend( "n next boat \n\ r rotate boat \n\n\ 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 30fcb14..de505c7 100644 --- a/rust/cli_player/src/ui_widgets/game_map_widget.rs +++ b/rust/cli_player/src/ui_widgets/game_map_widget.rs @@ -63,6 +63,10 @@ impl<'a> GameMapWidget<'a> { pub fn estimated_size(&self) -> (u16, u16) { let (w, mut h) = self.grid_size(); + if self.title.is_some() { + h += 2; + } + if let Some(l) = &self.legend { h += 1 + l.split('\n').count() as u16; } @@ -77,12 +81,19 @@ impl<'a> Widget for GameMapWidget<'a> { let symbols = BorderType::line_symbols(BorderType::Plain); - // TODO : render title + let mut start_y = area.y; + + // Render title + if let Some(title) = &self.title { + let x = centered_rect_size(title.len() as u16, 1, &area).x; + buf.set_string(x, start_y, title, Style::default()); + start_y += 2; + } // Paint game grid for y in 0..(self.rules.map_height + 1) { if y < self.rules.map_height { - buf.get_mut(area.x, area.y + 2 + (y as u16 * 2)) + buf.get_mut(area.x, start_y + 2 + (y as u16 * 2)) .set_char(alphabet.chars().nth(y).unwrap()); } @@ -90,14 +101,14 @@ impl<'a> Widget for GameMapWidget<'a> { if x < self.rules.map_width { buf.set_string( area.x + 2 + (x as u16 * 2) - (x as u16) / 10, - area.y, + start_y, x.to_string(), Style::default(), ); } let o_x = 1 + area.x + (x as u16 * 2); - let o_y = 1 + area.y + (y as u16 * 2); + let o_y = 1 + start_y + (y as u16 * 2); buf.get_mut(o_x, o_y).set_symbol(match (x, y) { (0, 0) => symbols.top_left, @@ -142,16 +153,16 @@ impl<'a> Widget for GameMapWidget<'a> { } } + start_y += self.grid_size().1; + // Paint legend (if any) if let Some(legend) = &self.legend { - let (_, mut y) = self.grid_size(); - y += area.y + 1; - + start_y += 1; for line in legend.split('\n') { let center_rect = centered_rect_size(line.len() as u16, 1, &area); let x = center_rect.x; - buf.set_string(x, y, line, Style::default()); - y += 1; + buf.set_string(x, start_y, line, Style::default()); + start_y += 1; } } }