-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
9 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |