Hacker News new | ask | show | jobs
by Klonoar 5 days ago
Your example would read far easier on the eyes if you just set the state to be some generic blank struct (e.g `AppState`) than the tedious syntax of `()`.
1 comments

    use iced::widget::{column, *};
    use iced::{Center, Color, Fill, Theme, border, color};

    fn main() -> iced::Result {
        iced::application(new, update, view)
            .window_size((500, 500))
            .run()
    }

    // fill in your state and message types as needed
    pub type State = ();
    pub type Message = ();

    fn new() -> State {}

    fn update(state: &mut State, message: Message) {}

    fn view(state: &State) -> impl Widget<Message> {
        let swatch = |c: Color| {
            container("")
                .width(32)
                .height(32)
                .style(move |theme| container::background(c))
        };
        let colors = [
            color!(0xff0000),
            color!(0x00ff00),
            color!(0x0000ff),
            color!(0xffff00),
            Color::BLACK,
            Color::WHITE,
        ];

        container(
            column![
                text("Hello, World!").size(20).color(Color::WHITE),
                row(colors.map(swatch)).spacing(8),
            ]
            .spacing(12)
            .align_x(Center),
        )
        .center(Fill)
        .style(panel)
    }

    fn panel(theme: &Theme) -> container::Style {
        container::background(color!(0x505050)).border(border::color(color!(0x0000ff)).width(1))
    }

but you'll get warnings for unused variables