2024-10-16 15:44:50 -05:00
|
|
|
use iced::{border::Radius, widget::{button, text}, Background, Border, Color, Shadow, Theme};
|
|
|
|
|
use super::super::cell::Cell;
|
|
|
|
|
use super::Message;
|
|
|
|
|
|
|
|
|
|
const LIGHT_GRAY: Color = Color {
|
|
|
|
|
r: 0.5,
|
|
|
|
|
g: 0.5,
|
|
|
|
|
b: 0.5,
|
|
|
|
|
a: 1.0,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub fn widget(cell: &Cell) -> iced::Element<Message> {
|
|
|
|
|
let display = match cell.value() {
|
|
|
|
|
Some(v) => v.to_string(),
|
|
|
|
|
None => "?".to_string(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
button(text(display))
|
|
|
|
|
.style(|theme: &Theme, status| {
|
2024-10-16 15:59:39 -05:00
|
|
|
// Get the current theme's palette
|
2024-10-16 15:44:50 -05:00
|
|
|
let palette = theme.palette();
|
2024-10-16 15:59:39 -05:00
|
|
|
|
|
|
|
|
// Create a default border, since we need to set off the cells
|
|
|
|
|
// TODO: Figure out how to get this out of the theme?
|
2024-10-16 15:44:50 -05:00
|
|
|
let mut border = Border::default().color(LIGHT_GRAY);
|
|
|
|
|
border.width = 1.0;
|
2024-10-16 15:59:39 -05:00
|
|
|
|
|
|
|
|
// Return a style based on the status
|
2024-10-16 15:44:50 -05:00
|
|
|
match status {
|
|
|
|
|
button::Status::Active => {
|
|
|
|
|
button::Style{
|
|
|
|
|
background: Some(Background::from(palette.background)),
|
|
|
|
|
text_color: palette.text,
|
|
|
|
|
border,
|
|
|
|
|
shadow: Shadow::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
let mut style = button::primary(theme, status);
|
|
|
|
|
style.border.radius = Radius::new(0);
|
|
|
|
|
style
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.height(50)
|
|
|
|
|
.width(50)
|
|
|
|
|
.on_press(Message::Pressed)
|
|
|
|
|
.into()
|
|
|
|
|
}
|