From df1d678ab9d89d85b613bd08a7f41d638f5e8e23 Mon Sep 17 00:00:00 2001 From: Pierre Hubert Date: Tue, 18 Oct 2022 10:05:43 +0200 Subject: [PATCH] Add more emojies --- .../src/ui_screens/configure_game_rules.rs | 4 ++-- .../src/ui_screens/confirm_dialog_screen.rs | 6 +++--- .../src/ui_screens/input_screen.rs | 4 ++-- .../src/ui_screens/set_boats_layout_screen.rs | 2 +- .../src/ui_widgets/button_widget.rs | 17 ++++++++++++++++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/rust/sea_battle_cli_player/src/ui_screens/configure_game_rules.rs b/rust/sea_battle_cli_player/src/ui_screens/configure_game_rules.rs index 73d6629..9fa4bad 100644 --- a/rust/sea_battle_cli_player/src/ui_screens/configure_game_rules.rs +++ b/rust/sea_battle_cli_player/src/ui_screens/configure_game_rules.rs @@ -283,10 +283,10 @@ impl GameRulesConfigurationScreen { .constraints([Constraint::Percentage(50), Constraint::Percentage(50)]) .split(chunks[EditingField::OK as usize]); - let button = ButtonWidget::new("Cancel", self.curr_field == EditingField::Cancel); + let button = ButtonWidget::cancel(self.curr_field == EditingField::Cancel); f.render_widget(button, buttons_chunk[0]); - let button = ButtonWidget::new("OK", self.curr_field == EditingField::OK) + let button = ButtonWidget::ok(self.curr_field == EditingField::OK) .set_disabled(!self.rules.is_valid()); f.render_widget(button, buttons_chunk[1]); diff --git a/rust/sea_battle_cli_player/src/ui_screens/confirm_dialog_screen.rs b/rust/sea_battle_cli_player/src/ui_screens/confirm_dialog_screen.rs index efdc993..b9dca56 100644 --- a/rust/sea_battle_cli_player/src/ui_screens/confirm_dialog_screen.rs +++ b/rust/sea_battle_cli_player/src/ui_screens/confirm_dialog_screen.rs @@ -35,7 +35,7 @@ pub struct ConfirmDialogScreen<'a> { impl<'a> ConfirmDialogScreen<'a> { pub fn new(msg: &'a str) -> Self { Self { - title: "Confirmation Request", + title: "❔ Confirmation Request", msg, is_confirm: true, can_escape: false, @@ -123,10 +123,10 @@ impl<'a> ConfirmDialogScreen<'a> { .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) .split(chunks[1]); - let cancel_button = ButtonWidget::new("Cancel", true).set_disabled(self.is_confirm); + let cancel_button = ButtonWidget::cancel(true).set_disabled(self.is_confirm); f.render_widget(cancel_button, buttons_area[0]); - let ok_button = ButtonWidget::new("Confirm", true).set_disabled(!self.is_confirm); + let ok_button = ButtonWidget::new("✅ Confirm", true).set_disabled(!self.is_confirm); f.render_widget(ok_button, buttons_area[1]); } } diff --git a/rust/sea_battle_cli_player/src/ui_screens/input_screen.rs b/rust/sea_battle_cli_player/src/ui_screens/input_screen.rs index 40c1562..eaa73e5 100644 --- a/rust/sea_battle_cli_player/src/ui_screens/input_screen.rs +++ b/rust/sea_battle_cli_player/src/ui_screens/input_screen.rs @@ -163,12 +163,12 @@ impl<'a> InputScreen<'a> { .constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref()) .split(*chunks.last().unwrap()); - let cancel_button = ButtonWidget::new("Cancel", self.is_cancel_hovered) + let cancel_button = ButtonWidget::cancel(self.is_cancel_hovered) .set_disabled(!self.can_cancel) .set_min_width(8); f.render_widget(cancel_button, buttons_area[0]); - let ok_button = ButtonWidget::new("OK", !self.is_cancel_hovered) + let ok_button = ButtonWidget::ok(!self.is_cancel_hovered) .set_min_width(8) .set_disabled(error.is_some()); f.render_widget(ok_button, buttons_area[1]); diff --git a/rust/sea_battle_cli_player/src/ui_screens/set_boats_layout_screen.rs b/rust/sea_battle_cli_player/src/ui_screens/set_boats_layout_screen.rs index ac7eabf..34b0ae4 100644 --- a/rust/sea_battle_cli_player/src/ui_screens/set_boats_layout_screen.rs +++ b/rust/sea_battle_cli_player/src/ui_screens/set_boats_layout_screen.rs @@ -202,7 +202,7 @@ impl<'a> SetBoatsLayoutScreen<'a> { .add_colored_cells(current_boat) .add_colored_cells(invalid_boats) .add_colored_cells(other_boats) - .set_title("Choose your boat layout") + .set_title("🛥 Set your boats layout") .set_yield_func(|c, r| { for i in 0..r.width { for j in 0..r.height { diff --git a/rust/sea_battle_cli_player/src/ui_widgets/button_widget.rs b/rust/sea_battle_cli_player/src/ui_widgets/button_widget.rs index a004999..a1334bb 100644 --- a/rust/sea_battle_cli_player/src/ui_widgets/button_widget.rs +++ b/rust/sea_battle_cli_player/src/ui_widgets/button_widget.rs @@ -13,6 +13,7 @@ pub struct ButtonWidget { label: String, disabled: bool, min_width: usize, + hover_bg_color: Color, } impl ButtonWidget { @@ -22,9 +23,18 @@ impl ButtonWidget { is_hovered, disabled: false, min_width: 0, + hover_bg_color: HIGHLIGHT_COLOR, } } + pub fn cancel(is_hovered: bool) -> Self { + Self::new("❌ Cancel", is_hovered).set_hover_bg_color(Color::Red) + } + + pub fn ok(is_hovered: bool) -> Self { + Self::new("✅ OK", is_hovered) + } + pub fn set_disabled(mut self, disabled: bool) -> Self { self.disabled = disabled; self @@ -35,6 +45,11 @@ impl ButtonWidget { self } + pub fn set_hover_bg_color(mut self, v: Color) -> Self { + self.hover_bg_color = v; + self + } + pub fn estimated_size(&self) -> (u16, u16) { ((self.label.len() + 2).max(self.min_width) as u16, 1) } @@ -55,7 +70,7 @@ impl Widget for ButtonWidget { let input = Paragraph::new(label.as_ref()).style(match (self.disabled, self.is_hovered) { (true, _) => Style::default(), (_, false) => Style::default().bg(Color::DarkGray), - (_, true) => Style::default().fg(Color::White).bg(HIGHLIGHT_COLOR), + (_, true) => Style::default().fg(Color::White).bg(self.hover_bg_color), }); input.render(area, buf);