iced-widget-kit 0.1.0

Extra widgets for the Iced GUI library
Documentation
use iced::{
    Element, Length,
    widget::{button, center, column},
};

use iced_widget_kit::expander;
use iced_widget_kit::expander::Direction;

fn main() -> iced::Result {
    iced::run(App::update, App::view)
}

#[derive(Default)]
struct App {
    direction: Direction,
    is_expanded: bool,
}

#[derive(Clone, Debug)]
enum Message {
    DirectionButtonPressed,
    ExpanderPressed,
}

impl App {
    fn update(&mut self, message: Message) {
        match message {
            Message::DirectionButtonPressed => {
                self.direction = match self.direction {
                    Direction::Left => Direction::Up,
                    Direction::Up => Direction::Right,
                    Direction::Right => Direction::Down,
                    Direction::Down => Direction::Left,
                }
            }
            Message::ExpanderPressed => self.is_expanded = !self.is_expanded,
        }
    }

    fn view(&self) -> Element<'_, Message> {
        let direction_text = match self.direction {
            Direction::Left => "Left",
            Direction::Up => "Up",
            Direction::Right => "Right",
            Direction::Down => "Down",
        };

        let direction_button = button(direction_text).on_press(Message::DirectionButtonPressed);
        let header = button("Header").on_press(Message::ExpanderPressed);

        let content = column!["Item 1", "Item 2", "Item 3", "Item 4",];

        let expander = expander(header, content, self.is_expanded)
            .width(Length::Fill)
            .height(Length::Fill)
            .direction(self.direction);

        column![direction_button, center(expander),].into()
    }
}