Skip to content

Commit

Permalink
Create LCD Theme using LazyStatic.
Browse files Browse the repository at this point in the history
Tweak the colors a little,
  • Loading branch information
shartrec committed Jun 16, 2024
1 parent ff054d5 commit e88259e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 33 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
lazy_static = "1.4.0"
palette = "0.7.6"

[dependencies.iced]
Expand Down
2 changes: 1 addition & 1 deletion src/ui/calculator_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Default for CalculatorApp {
Self {
main_window: CalcWindow::default(),
pick_window: None,
theme: ui::lcd_theme(),
theme: ui::lcd_theme().clone(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/func_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl FuncPopup {
fn get_all_themes() -> Vec<Theme> {
let mut themes: Vec<Theme> = Vec::new();

themes.insert(0, ui::lcd_theme());
themes.insert(0, ui::lcd_theme().clone());
for t in Theme::ALL {
themes.push(t.clone());
}
Expand Down
68 changes: 37 additions & 31 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use iced::{Color, Theme};
use iced::theme::Custom;
use iced::theme::Palette;
use iced::theme::palette::{Background, Danger, Extended, Pair, Primary, Secondary, Success};
use lazy_static::lazy_static;

pub(crate) mod calculator;
mod messages;
Expand All @@ -34,7 +35,7 @@ mod func_popup;
mod calc_window;

pub const PALETT_LCD: Palette = Palette {
background: Color::from_rgb(
background: Color::from_rgb( // LCD Green background
0xd4 as f32 / 255.0,
0xed as f32 / 255.0,
0xd4 as f32 / 255.0,
Expand All @@ -45,7 +46,7 @@ pub const PALETT_LCD: Palette = Palette {
0x40 as f32 / 255.0,
0x40 as f32 / 255.0,
),
success: Color::from_rgb(
success: Color::from_rgb( // Dark teal
0x12 as f32 / 255.0,
0x66 as f32 / 255.0,
0x4F as f32 / 255.0,
Expand All @@ -57,33 +58,38 @@ pub const PALETT_LCD: Palette = Palette {
),
};

fn lcd_theme() -> Theme {
Theme::Custom(Arc::new(Custom::with_fn(String::from("Lcd Calculator"), PALETT_LCD, |palette| -> Extended {
Extended {
background: Background{
weak: Pair::new(Color::from_rgb8(0x50,0x40,0x50), palette.text),
.. Background::new(palette.background, palette.text)
},
primary: Primary::generate (
palette.primary,
Color::BLACK,
Color::WHITE,
),
secondary: Secondary{
strong: Pair::new(Color::from_rgb8(0x04,0x04,0x04,), Color::WHITE),
.. Secondary::generate(Color::BLACK, Color::WHITE)
},
success: Success::generate(
palette.primary,
Color::BLACK,
Color::WHITE,
),
danger: Danger::generate(
palette.danger,
palette.background,
palette.text,
),
is_dark: false,
}
})))
lazy_static! {
static ref LCD_THEME: Theme =
Theme::Custom(Arc::new(Custom::with_fn(String::from("Lcd Calculator"), PALETT_LCD, |palette| -> Extended {
Extended {
background: Background{
weak: Pair::new(Color::from_rgb8(0x00,0x50,0x60), palette.text), // Grey Blue
.. Background::new(palette.background, palette.text)
},
primary: Primary::generate (
palette.primary,
Color::BLACK,
Color::WHITE,
),
secondary: Secondary{
strong: Pair::new(Color::from_rgb8(0x04,0x04,0x04,), Color::WHITE),
.. Secondary::generate(Color::BLACK, Color::WHITE)
},
success: Success::generate(
palette.primary,
Color::BLACK,
Color::WHITE,
),
danger: Danger::generate(
palette.danger,
palette.background,
palette.text,
),
is_dark: false,
}
})));
}

fn lcd_theme() -> &'static Theme {
&LCD_THEME
}

0 comments on commit e88259e

Please sign in to comment.