Skip to content

Commit

Permalink
Update main.rs
Browse files Browse the repository at this point in the history
Added radio buttons that change theme
The theme is the default one used by iced
Soon i'll update it by adding custom AvdanOS themes
  • Loading branch information
mrakane7 committed May 11, 2023
1 parent 0e04bc1 commit a33b652
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
use iced::widget::{
column,
container,
text
radio,
row,
text,
};

use iced::{
Expand All @@ -14,6 +16,11 @@ use iced::{
Settings
};

use iced::theme::{
self,
Theme
};

mod fonts;

use crate::fonts::{
Expand All @@ -32,18 +39,28 @@ pub fn main() -> iced::Result {
Toolkit::run(Settings::default()) // run program
}

struct Toolkit {}
struct Toolkit {
theme: Theme
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
enum UITheme {
Light,
Dark
}

// interactions
#[derive(Debug, Clone, Copy)]
enum Message {}
enum Message {
ThemeChanged(UITheme)
}

impl Sandbox for Toolkit {
type Message = Message;

// store interactions
fn new() -> Self {
Self {}
Toolkit { theme: Theme::Light }
}

// window title
Expand All @@ -53,15 +70,44 @@ impl Sandbox for Toolkit {

// update state
fn update(&mut self, message: Message) {
match message {}
match message {
Message::ThemeChanged(theme) => {
self.theme = match theme {
UITheme::Light => Theme::Light,
UITheme::Dark => Theme::Dark
}
}
}
}

// show things on screen
fn view(&self) -> Element<Message> {
let title = text("AvdanOS UI Toolkit Demo")
.font(REGULAR);

let content = column![title]
let choose_theme =
[UITheme::Light, UITheme::Dark]
.iter()
.fold (
row![text("Choose a theme:")].spacing(10),
|row, theme| {
row.push(radio (
format!("{theme:?}"),
*theme,
Some(match self.theme {
Theme::Light => UITheme::Light,
Theme::Dark => UITheme::Dark,
Theme::Custom(..) => todo!()
}),
Message::ThemeChanged)
)
});

let content = column![
title,
choose_theme
]
.spacing(20)
.padding(20)
.align_items(Alignment::Start);

Expand All @@ -71,4 +117,8 @@ impl Sandbox for Toolkit {
.padding(20)
.into()
}

fn theme(&self) -> Theme {
self.theme.clone()
}
}

0 comments on commit a33b652

Please sign in to comment.