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