This commit is contained in:
parent
e88d64ff63
commit
df1d678ab9
@ -283,10 +283,10 @@ impl GameRulesConfigurationScreen {
|
|||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)])
|
||||||
.split(chunks[EditingField::OK as usize]);
|
.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]);
|
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());
|
.set_disabled(!self.rules.is_valid());
|
||||||
f.render_widget(button, buttons_chunk[1]);
|
f.render_widget(button, buttons_chunk[1]);
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ pub struct ConfirmDialogScreen<'a> {
|
|||||||
impl<'a> ConfirmDialogScreen<'a> {
|
impl<'a> ConfirmDialogScreen<'a> {
|
||||||
pub fn new(msg: &'a str) -> Self {
|
pub fn new(msg: &'a str) -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: "Confirmation Request",
|
title: "❔ Confirmation Request",
|
||||||
msg,
|
msg,
|
||||||
is_confirm: true,
|
is_confirm: true,
|
||||||
can_escape: false,
|
can_escape: false,
|
||||||
@ -123,10 +123,10 @@ impl<'a> ConfirmDialogScreen<'a> {
|
|||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(chunks[1]);
|
.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]);
|
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]);
|
f.render_widget(ok_button, buttons_area[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,12 +163,12 @@ impl<'a> InputScreen<'a> {
|
|||||||
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
.constraints([Constraint::Percentage(50), Constraint::Percentage(50)].as_ref())
|
||||||
.split(*chunks.last().unwrap());
|
.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_disabled(!self.can_cancel)
|
||||||
.set_min_width(8);
|
.set_min_width(8);
|
||||||
f.render_widget(cancel_button, buttons_area[0]);
|
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_min_width(8)
|
||||||
.set_disabled(error.is_some());
|
.set_disabled(error.is_some());
|
||||||
f.render_widget(ok_button, buttons_area[1]);
|
f.render_widget(ok_button, buttons_area[1]);
|
||||||
|
@ -202,7 +202,7 @@ impl<'a> SetBoatsLayoutScreen<'a> {
|
|||||||
.add_colored_cells(current_boat)
|
.add_colored_cells(current_boat)
|
||||||
.add_colored_cells(invalid_boats)
|
.add_colored_cells(invalid_boats)
|
||||||
.add_colored_cells(other_boats)
|
.add_colored_cells(other_boats)
|
||||||
.set_title("Choose your boat layout")
|
.set_title("🛥 Set your boats layout")
|
||||||
.set_yield_func(|c, r| {
|
.set_yield_func(|c, r| {
|
||||||
for i in 0..r.width {
|
for i in 0..r.width {
|
||||||
for j in 0..r.height {
|
for j in 0..r.height {
|
||||||
|
@ -13,6 +13,7 @@ pub struct ButtonWidget {
|
|||||||
label: String,
|
label: String,
|
||||||
disabled: bool,
|
disabled: bool,
|
||||||
min_width: usize,
|
min_width: usize,
|
||||||
|
hover_bg_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ButtonWidget {
|
impl ButtonWidget {
|
||||||
@ -22,9 +23,18 @@ impl ButtonWidget {
|
|||||||
is_hovered,
|
is_hovered,
|
||||||
disabled: false,
|
disabled: false,
|
||||||
min_width: 0,
|
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 {
|
pub fn set_disabled(mut self, disabled: bool) -> Self {
|
||||||
self.disabled = disabled;
|
self.disabled = disabled;
|
||||||
self
|
self
|
||||||
@ -35,6 +45,11 @@ impl ButtonWidget {
|
|||||||
self
|
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) {
|
pub fn estimated_size(&self) -> (u16, u16) {
|
||||||
((self.label.len() + 2).max(self.min_width) as u16, 1)
|
((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) {
|
let input = Paragraph::new(label.as_ref()).style(match (self.disabled, self.is_hovered) {
|
||||||
(true, _) => Style::default(),
|
(true, _) => Style::default(),
|
||||||
(_, false) => Style::default().bg(Color::DarkGray),
|
(_, 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);
|
input.render(area, buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user