widget/policycheck: intoduce os dependent theme handling
* theme_fluent: only makes sense in windows environment Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -3,7 +3,10 @@ Theme (
|
||||
"container_form": (
|
||||
base: "container",
|
||||
properties: {
|
||||
"border": 1,
|
||||
"padding": 14,
|
||||
"border_width": 2,
|
||||
"border_radius": 0,
|
||||
"border_brush": "#A5A5A5",
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
//use chrono::{Local, DateTime};
|
||||
use dotenv::dotenv;
|
||||
use locales::t;
|
||||
use cfg_if::cfg_if;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
//use std::process;
|
||||
@@ -21,15 +22,15 @@ use tracing::{info, trace, Level};
|
||||
|
||||
use orbtk::{
|
||||
prelude::*,
|
||||
theme_default::{THEME_DEFAULT, THEME_DEFAULT_COLORS_DARK, THEME_DEFAULT_FONTS},
|
||||
theming::config::ThemeConfig,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
use orbtk::theme_fluent::{THEME_FLUENT, THEME_FLUENT_COLORS_DARK, THEME_FLUENT_FONTS};
|
||||
|
||||
// The Main view
|
||||
use advotracker::{
|
||||
widgets::{
|
||||
main_view,
|
||||
//policycheck::policycheck_state::PolicyCheckState,
|
||||
}
|
||||
};
|
||||
use advotracker::widgets::main_view;
|
||||
|
||||
mod parse_args;
|
||||
|
||||
@@ -44,8 +45,13 @@ struct Environment {
|
||||
}
|
||||
|
||||
// Style extension
|
||||
//static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/fluent_dark.ron");
|
||||
//static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/fluent_light.ron");
|
||||
static DEFAULT_DARK_EXT: &str = include_str!("../assets/advotracker/default_dark.ron");
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
static FLUENT_DARK_EXT: &str = include_str!("../assets/advotracker/fluent_dark.ron");
|
||||
static FLUENT_LIGHT_EXT: &str = include_str!("../assets/advotracker/fluent_light.ron");
|
||||
}
|
||||
}
|
||||
|
||||
// German localization file.
|
||||
static ADVOTRACKER_DE_DE: &str = include_str!("../assets/advotracker/advotracker_de_DE.ron");
|
||||
@@ -67,19 +73,42 @@ fn get_lang() -> String {
|
||||
lang
|
||||
}
|
||||
|
||||
// /// Extend and register theme assets.
|
||||
// fn theme() -> Theme {
|
||||
// register_default_fonts(Theme::from_config(
|
||||
// ThemeConfig::from(FLUENT_DARK_EXT)
|
||||
// .extend(ThemeConfig::from(THEME_FLUENT))
|
||||
// .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK))
|
||||
// .extend(ThemeConfig::from(THEME_FLUENT_FONTS)),
|
||||
// // ThemeConfig::from(FLUENT_LIGHT_EXT)
|
||||
// // .extend(ThemeConfig::from(THEME_FLUENT))
|
||||
// // .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK))
|
||||
// // .extend(ThemeConfig::from(THEME_FLUENT_FONTS)),
|
||||
// ))
|
||||
// }
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
/// Extend and register theme assets.
|
||||
fn theme() -> Theme {
|
||||
register_default_fonts(Theme::from_config(
|
||||
ThemeConfig::from(DEFAULT_DARK_EXT)
|
||||
.extend(ThemeConfig::from(THEME_DEFAULT))
|
||||
.extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK))
|
||||
.extend(ThemeConfig::from(THEME_DEFAULT_FONTS)),
|
||||
))
|
||||
}
|
||||
fn theme_fluent() -> Theme {
|
||||
register_fluent_fonts(Theme::from_config(
|
||||
ThemeConfig::from(FLUENT_DARK_EXT)
|
||||
.extend(ThemeConfig::from(THEME_FLUENT))
|
||||
.extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK))
|
||||
.extend(ThemeConfig::from(THEME_FLUENT_FONTS)),
|
||||
))
|
||||
// register_fluent_fonts(Theme::from_config(
|
||||
// ThemeConfig::from(FLUENT_LIGHT_EXT)
|
||||
// .extend(ThemeConfig::from(THEME_FLUENT))
|
||||
// .extend(ThemeConfig::from(THEME_FLUENT_COLORS_DARK))
|
||||
// .extend(ThemeConfig::from(THEME_FLUENT_FONTS)),
|
||||
}
|
||||
} else {
|
||||
/// Extend and register theme assets.
|
||||
fn theme() -> Theme {
|
||||
register_default_fonts(Theme::from_config(
|
||||
ThemeConfig::from(DEFAULT_DARK_EXT)
|
||||
.extend(ThemeConfig::from(THEME_DEFAULT))
|
||||
.extend(ThemeConfig::from(THEME_DEFAULT_COLORS_DARK))
|
||||
.extend(ThemeConfig::from(THEME_DEFAULT_FONTS)),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use parse_args::parse_args;
|
||||
@@ -152,6 +181,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
Application::from_name("nwx.advotracker")
|
||||
.localization(localization)
|
||||
.theme(theme())
|
||||
.window(|ctx| {
|
||||
Window::new()
|
||||
.title("AdvoTracker - DirectCall")
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* SPDX-License-Identifier: (0BSD or MIT)
|
||||
*/
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
use locales::t;
|
||||
use orbtk::prelude::*;
|
||||
use orbtk::shell::event::Key;
|
||||
@@ -506,13 +507,24 @@ impl State for PolicycheckState {
|
||||
PolicycheckAction::ChangeTheme() => {
|
||||
let theme_index = *PolicycheckView::selected_index_ref(&ctx.widget());
|
||||
|
||||
match theme_index {
|
||||
0 => ctx.switch_theme(theme_default_dark()),
|
||||
1 => ctx.switch_theme(theme_default_light()),
|
||||
2 => ctx.switch_theme(theme_redox()),
|
||||
//3 => ctx.switch_theme(theme_fluent_dark()),
|
||||
//4 => ctx.switch_theme(theme_fluent_light()),
|
||||
_ => {}
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
match theme_index {
|
||||
0 => ctx.switch_theme(theme_default_dark()),
|
||||
1 => ctx.switch_theme(theme_default_light()),
|
||||
2 => ctx.switch_theme(theme_redox()),
|
||||
3 => ctx.switch_theme(theme_fluent_dark()),
|
||||
4 => ctx.switch_theme(theme_fluent_light()),
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
match theme_index {
|
||||
0 => ctx.switch_theme(theme_default_dark()),
|
||||
1 => ctx.switch_theme(theme_default_light()),
|
||||
2 => ctx.switch_theme(theme_redox()),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
PolicycheckAction::AddProgress(increment) => {
|
||||
@@ -724,13 +736,17 @@ fn create_menu(menu: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
/// Create a popup submenu to toogle the active theme
|
||||
fn create_menu_toggle_theme(menu_toggle_theme: Entity, ctx: &mut BuildContext<'_>) -> Entity {
|
||||
// define the list of supported themes
|
||||
let themes = vec![
|
||||
let mut themes = vec![
|
||||
"default_dark".to_string(),
|
||||
"default_light".to_string(),
|
||||
"redox".to_string(),
|
||||
"fluent_dark".to_string(),
|
||||
"fluent_light".to_string(),
|
||||
];
|
||||
cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
themes.push("fluent_dark".to_string());
|
||||
themes.push("fluent_light".to_string());
|
||||
}
|
||||
}
|
||||
let themes_count = themes.len();
|
||||
|
||||
Popup::new()
|
||||
|
||||
Reference in New Issue
Block a user