Below is an app that sets the theme and displays some buttons with custom styling:
use iced::widget::{button, row, Column};
use iced::{Color, Element, Theme};
#[derive(Default)]
struct App {}
#[derive(Debug, Clone)]
enum Message { Button }
fn update(_st: &mut App, _m: Message) {}
fn view2(_st: &App) -> Element<Message> {
row![["Alpha", "Beta", "Gamma", "Delta", "Epsilon"]
.into_iter()
.fold(Column::new().spacing(4), |c, s| c.push(
button(s)
.on_press(Message::Button)
.style(|theme: &Theme, status| {
use button::Catalog;
let mut sty = theme.style(&<Theme as button::Catalog>::default(), status);
if status == button::Status::Hovered {
sty.border.color = Color::from_rgba(1.0, 1.0, 1.0, 0.5);
sty.border.width = 2.0;
}
sty
})
))]
.padding(16)
.spacing(8)
.into()
}
fn main() -> iced::Result {
iced::application("App", update, view2)
.theme(|_st| Theme::Dark)
.run()
}
Two questions:
- The
theme.style(&<Theme as button::Catalog>::default(), status);
code is clumsy. Is there a better way to get the current styling of a widget? - This only changes the styling of buttons where I explicitly apply the styling code. Is there a way to change the styling of all buttons in the app?