Add more emojies
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2022-10-18 10:05:43 +02:00
parent e88d64ff63
commit df1d678ab9
5 changed files with 24 additions and 9 deletions

View File

@ -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]);

View File

@ -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]);
}
}

View File

@ -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]);

View File

@ -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 {

View File

@ -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);