settings gui PoC

This commit is contained in:
Aleksander
2025-11-05 22:37:07 +01:00
parent 33955498cc
commit e087eb3743
18 changed files with 285 additions and 29 deletions

View File

@@ -14,7 +14,7 @@ use wgui::{
};
use crate::{
assets,
assets, settings,
tab::{
Tab, TabParams, TabType, apps::TabApps, games::TabGames, home::TabHome, monado::TabMonado, processes::TabProcesses,
settings::TabSettings,
@@ -25,6 +25,8 @@ pub struct Frontend {
pub layout: RcLayout,
globals: WguiGlobals,
settings: settings::Settings,
#[allow(dead_code)]
state: ParserState,
@@ -37,6 +39,10 @@ pub struct Frontend {
label_time_id: WidgetID,
}
pub struct InitParams {
pub settings: settings::Settings,
}
pub type RcFrontend = Rc<RefCell<Frontend>>;
pub enum FrontendTask {
@@ -44,7 +50,7 @@ pub enum FrontendTask {
}
impl Frontend {
pub fn new() -> anyhow::Result<(RcFrontend, RcLayout)> {
pub fn new(params: InitParams) -> anyhow::Result<(RcFrontend, RcLayout)> {
let globals = WguiGlobals::new(Box::new(assets::Asset {}), wgui::globals::Defaults::default())?;
let (layout, state) = wgui::parser::new_layout_from_assets(
@@ -71,6 +77,7 @@ impl Frontend {
tasks,
ticks: 0,
label_time_id,
settings: params.settings,
}));
Frontend::register_widgets(&res)?;

View File

@@ -1,5 +1,6 @@
mod assets;
pub mod frontend;
pub mod settings;
mod tab;
mod util;
mod various;

View File

@@ -0,0 +1,41 @@
use serde::{Deserialize, Serialize};
#[derive(Default, Serialize, Deserialize)]
pub struct HomeScreen {
pub hide_username: bool,
}
#[derive(Default, Serialize, Deserialize)]
pub struct General {
pub am_pm_clock: bool,
pub opaque_background: bool,
}
#[derive(Default, Serialize, Deserialize)]
pub enum ApplicationRunMode {
#[default]
Native, /* use Smithay compositor */
XWaylandCage,
}
#[derive(Default, Serialize, Deserialize)]
pub struct Tweaks {
pub default_run_mode: ApplicationRunMode,
}
#[derive(Default, Serialize, Deserialize)]
pub struct Settings {
pub home_screen: HomeScreen,
pub general: General,
pub tweaks: Tweaks,
}
impl Settings {
pub fn save(&self) -> String {
serde_json::to_string(&self).unwrap() /* want panic */
}
pub fn load(input: &str) -> anyhow::Result<Settings> {
Ok(serde_json::from_str::<Settings>(input)?)
}
}