Skip to content

Commit

Permalink
Clean up and update
Browse files Browse the repository at this point in the history
  • Loading branch information
akaneboy committed Oct 28, 2024
1 parent cff8dc6 commit c41066b
Showing 1 changed file with 9 additions and 114 deletions.
123 changes: 9 additions & 114 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,124 +1,19 @@
#![allow(unused_imports)] // temporary

use iced::widget::{
column,
container,
radio,
row,
text,
};

use iced::{
Alignment,
Element,
Length,
Sandbox,
Settings
};

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

mod fonts;

use crate::fonts::{
BLACK,
BOLD,
EXTRA_BOLD,
EXTRA_LIGHT,
LIGHT,
MEDIUM,
REGULAR,
SEMI_BOLD,
THIN
};
use iced::{widget::column, Element};

pub fn main() -> iced::Result {
Toolkit::run(Settings::default()) // run program
}

struct Toolkit {
theme: Theme
}

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

// interactions
#[derive(Debug, Clone, Copy)]
enum Message {
ThemeChanged(UITheme)
iced::application("Avdan GUI Toolkit", Toolkit::update, Toolkit::view).run()
}

impl Sandbox for Toolkit {
type Message = Message;
#[derive(Default)]
struct Toolkit {}

// store interactions
fn new() -> Self {
Toolkit { theme: Theme::Light }
}
#[derive(Debug, Clone)]
enum Message {}

// window title
fn title(&self) -> String {
String::from("AvdanOS UI Toolkit Demo")
}

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

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

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);

container(content)
.width(Length::Fill)
.height(Length::Fill)
.padding(20)
.into()
}

fn theme(&self) -> Theme {
self.theme.clone()
column![].into()
}
}

0 comments on commit c41066b

Please sign in to comment.