improve styling in relation to windows theme
This commit is contained in:
+12
-1
@@ -1,6 +1,10 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
features,
|
features,
|
||||||
gui::{settings::Settings, tools, ui_ext::UiExt},
|
gui::{
|
||||||
|
settings::{Settings, Theme},
|
||||||
|
tools,
|
||||||
|
ui_ext::UiExt,
|
||||||
|
},
|
||||||
util::{consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState, win},
|
util::{consts::game::WINDOW_TITLE, meta::Meta, persistent_state::PersistentState, win},
|
||||||
};
|
};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
@@ -201,6 +205,13 @@ impl App {
|
|||||||
if selection != self.settings.theme {
|
if selection != self.settings.theme {
|
||||||
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
||||||
}
|
}
|
||||||
|
if ui
|
||||||
|
.add_visible(self.settings.theme == Theme::Auto, egui::Button::new("⟲"))
|
||||||
|
.on_hover_text("Refresh theme")
|
||||||
|
.clicked()
|
||||||
|
{
|
||||||
|
catppuccin_egui::set_theme(ctx, self.settings.theme.into());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
ui.checkbox(&mut self.settings.start_elevated, "Always start elevated");
|
ui.checkbox(&mut self.settings.start_elevated, "Always start elevated");
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -50,10 +50,12 @@ fn app_creator(
|
|||||||
app.sysinfo.refresh_all();
|
app.sysinfo.refresh_all();
|
||||||
// enable image loading support in egui
|
// enable image loading support in egui
|
||||||
egui_extras::install_image_loaders(&cc.egui_ctx);
|
egui_extras::install_image_loaders(&cc.egui_ctx);
|
||||||
// set our initial theme, from earlier loaded settings
|
// set our initial theme, from earlier loaded settings. we set the egui theme
|
||||||
|
// to dark here to work around system theme based switching of the egui style
|
||||||
|
cc.egui_ctx.set_theme(egui::Theme::Dark);
|
||||||
catppuccin_egui::set_theme(&cc.egui_ctx, app.settings.theme.into());
|
catppuccin_egui::set_theme(&cc.egui_ctx, app.settings.theme.into());
|
||||||
// apply some global styling that we like
|
// apply some global styling that we like
|
||||||
cc.egui_ctx.style_mut(|style| {
|
cc.egui_ctx.all_styles_mut(|style| {
|
||||||
style.spacing.item_spacing = egui::vec2(4.0, 4.0);
|
style.spacing.item_spacing = egui::vec2(4.0, 4.0);
|
||||||
style.interaction.selectable_labels = false;
|
style.interaction.selectable_labels = false;
|
||||||
});
|
});
|
||||||
|
|||||||
+11
-1
@@ -1,8 +1,11 @@
|
|||||||
|
use crate::util::win;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{Display, EnumIter};
|
use strum::{Display, EnumIter};
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
#[derive(Clone, Copy, Debug, Display, PartialEq, Eq, Serialize, Deserialize, EnumIter)]
|
||||||
pub enum Theme {
|
pub enum Theme {
|
||||||
|
#[strum(to_string = "Auto")]
|
||||||
|
Auto,
|
||||||
#[strum(to_string = "Catppuccin Latte")]
|
#[strum(to_string = "Catppuccin Latte")]
|
||||||
CatppuccinLatte,
|
CatppuccinLatte,
|
||||||
#[strum(to_string = "Catppuccin Frappe")]
|
#[strum(to_string = "Catppuccin Frappe")]
|
||||||
@@ -16,6 +19,13 @@ pub enum Theme {
|
|||||||
impl From<Theme> for catppuccin_egui::Theme {
|
impl From<Theme> for catppuccin_egui::Theme {
|
||||||
fn from(val: Theme) -> Self {
|
fn from(val: Theme) -> Self {
|
||||||
match val {
|
match val {
|
||||||
|
Theme::Auto => {
|
||||||
|
if win::is_system_theme_dark() {
|
||||||
|
catppuccin_egui::MOCHA
|
||||||
|
} else {
|
||||||
|
catppuccin_egui::LATTE
|
||||||
|
}
|
||||||
|
}
|
||||||
Theme::CatppuccinLatte => catppuccin_egui::LATTE,
|
Theme::CatppuccinLatte => catppuccin_egui::LATTE,
|
||||||
Theme::CatppuccinFrappe => catppuccin_egui::FRAPPE,
|
Theme::CatppuccinFrappe => catppuccin_egui::FRAPPE,
|
||||||
Theme::CatppuccinMacchiato => catppuccin_egui::MACCHIATO,
|
Theme::CatppuccinMacchiato => catppuccin_egui::MACCHIATO,
|
||||||
@@ -33,7 +43,7 @@ pub struct Settings {
|
|||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
theme: Theme::CatppuccinMocha,
|
theme: Theme::Auto,
|
||||||
start_elevated: false,
|
start_elevated: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,3 +83,17 @@ pub fn is_elevated() -> bool {
|
|||||||
result.is_ok() && elevation.TokenIsElevated != 0
|
result.is_ok() && elevation.TokenIsElevated != 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_system_theme_dark() -> bool {
|
||||||
|
use winreg::RegKey;
|
||||||
|
let hkcu = RegKey::predef(winreg::enums::HKEY_CURRENT_USER);
|
||||||
|
let Ok(subkey) =
|
||||||
|
hkcu.open_subkey("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize")
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let Ok(dword): Result<u32, std::io::Error> = subkey.get_value("AppsUseLightTheme") else {
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
dword != 1
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user