This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user