Most widgets support style
method to change their styles.
These methods take parameters from enums of theme module.
For example, widget::Text takes theme::Text as the parameter of its style method, and widget::Button takes theme::Button as the parameter of its style method.
Since theme::Text implements From<Color>, we can also use Color struct directly for the style method of widget::Text.
use iced::{
theme,
widget::{button, column, row, text},
Color, Sandbox, Settings,
};
fn main() -> iced::Result {
MyApp::run(Settings::default())
}
#[derive(Debug, Clone)]
enum MyAppMessage {
DummyMessage,
}
struct MyApp;
impl Sandbox for MyApp {
type Message = MyAppMessage;
fn new() -> Self {
Self
}
fn title(&self) -> String {
String::from("My App")
}
fn update(&mut self, _message: Self::Message) {}
fn view(&self) -> iced::Element<Self::Message> {
column![
text("Ready?").style(Color::from_rgb(1., 0.6, 0.2)),
row![
button("Cancel")
.style(theme::Button::Secondary)
.on_press(MyAppMessage::DummyMessage),
button("Go!~~")
.style(theme::Button::Primary)
.on_press(MyAppMessage::DummyMessage),
],
]
.into()
}
}
➡️ Next: Custom Styles
📘 Back: Table of contents