remember checked settings in memory
This commit is contained in:
@@ -25,7 +25,7 @@ pub struct Frontend {
|
||||
pub layout: RcLayout,
|
||||
globals: WguiGlobals,
|
||||
|
||||
settings: settings::Settings,
|
||||
pub settings: settings::Settings,
|
||||
|
||||
#[allow(dead_code)]
|
||||
state: ParserState,
|
||||
@@ -99,19 +99,15 @@ impl Frontend {
|
||||
fn tick(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
|
||||
let mut layout = self.layout.borrow_mut();
|
||||
|
||||
let mut alterables = EventAlterables::default();
|
||||
let mut common = CallbackDataCommon {
|
||||
alterables: &mut alterables,
|
||||
state: &layout.state,
|
||||
};
|
||||
let mut c = layout.start_common();
|
||||
|
||||
// fixme: timer events instead of this thing
|
||||
if self.ticks.is_multiple_of(1000) {
|
||||
self.update_time(&mut common);
|
||||
self.update_time(&mut c.common());
|
||||
}
|
||||
|
||||
c.finish()?;
|
||||
layout.update(Vec2::new(width, height), timestep_alpha)?;
|
||||
layout.process_alterables(alterables)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -154,6 +150,7 @@ impl Frontend {
|
||||
layout: &mut layout,
|
||||
parent_id: widget_content.id,
|
||||
frontend: rc_this,
|
||||
settings: &mut self.settings,
|
||||
};
|
||||
|
||||
let tab: Box<dyn Tab> = match tab_type {
|
||||
|
||||
@@ -11,16 +11,9 @@ pub struct General {
|
||||
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,
|
||||
pub xwayland_by_default: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::rc::Rc;
|
||||
|
||||
use wgui::{
|
||||
components::button::ComponentButton,
|
||||
event::CallbackDataCommon,
|
||||
globals::WguiGlobals,
|
||||
layout::{Layout, WidgetID},
|
||||
};
|
||||
@@ -30,6 +31,7 @@ pub struct TabParams<'a> {
|
||||
pub layout: &'a mut Layout,
|
||||
pub parent_id: WidgetID,
|
||||
pub frontend: &'a RcFrontend,
|
||||
pub settings: &'a mut crate::settings::Settings,
|
||||
}
|
||||
|
||||
pub trait Tab {
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
parser::{ParseDocumentParams, ParserState},
|
||||
components::checkbox::ComponentCheckbox,
|
||||
event::CallbackDataCommon,
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
use crate::tab::{Tab, TabParams, TabType};
|
||||
use crate::{
|
||||
frontend::{Frontend, RcFrontend},
|
||||
settings,
|
||||
tab::{Tab, TabParams, TabType},
|
||||
};
|
||||
|
||||
pub struct TabSettings {
|
||||
#[allow(dead_code)]
|
||||
@@ -16,8 +24,27 @@ impl Tab for TabSettings {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_setting_checkbox(
|
||||
params: &mut TabParams,
|
||||
checkbox: Rc<ComponentCheckbox>,
|
||||
fetch_callback: fn(&mut settings::Settings) -> &mut bool,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut c = params.layout.start_common();
|
||||
|
||||
checkbox.set_checked(&mut c.common(), *fetch_callback(params.settings));
|
||||
let rc_frontend = params.frontend.clone();
|
||||
checkbox.on_toggle(Box::new(move |_common, e| {
|
||||
let mut frontend = rc_frontend.borrow_mut();
|
||||
*fetch_callback(&mut frontend.settings) = e.checked;
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
c.finish()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl TabSettings {
|
||||
pub fn new(params: TabParams) -> anyhow::Result<Self> {
|
||||
pub fn new(mut params: TabParams) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: params.globals.clone(),
|
||||
@@ -28,6 +55,34 @@ impl TabSettings {
|
||||
params.parent_id,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_hide_username")?,
|
||||
|settings| &mut settings.home_screen.hide_username,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?,
|
||||
|settings| &mut settings.general.am_pm_clock,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
state
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_opaque_background")?,
|
||||
|settings| &mut settings.general.opaque_background,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
state
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_xwayland_by_default")?,
|
||||
|settings| &mut settings.tweaks.xwayland_by_default,
|
||||
)?;
|
||||
|
||||
Ok(Self { state })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user