Game rules screen functional

This commit is contained in:
2022-10-02 16:31:36 +02:00
parent a62ced4d3c
commit 46ab1fec9a
3 changed files with 30 additions and 8 deletions

View File

@ -1,13 +1,16 @@
use crate::ui_screens::utils::centered_rect_size;
use std::fmt::Display;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::widgets::*;
use crate::ui_screens::utils::centered_rect_size;
pub struct ButtonWidget {
is_hovered: bool,
label: String,
disabled: bool,
}
impl ButtonWidget {
@ -15,8 +18,14 @@ impl ButtonWidget {
Self {
label: label.to_string(),
is_hovered,
disabled: false,
}
}
pub fn set_disabled(mut self, disabled: bool) -> Self {
self.disabled = disabled;
self
}
}
impl Widget for ButtonWidget {
@ -25,9 +34,10 @@ impl Widget for ButtonWidget {
let area = centered_rect_size(label.len() as u16, 1, area);
let input = Paragraph::new(label.as_ref()).style(match &self.is_hovered {
false => Style::default().bg(Color::DarkGray),
true => Style::default().fg(Color::White).bg(Color::Yellow),
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(Color::Yellow),
});
input.render(area, buf);