add settings: am/pm clock, opaque background, hide username
This commit is contained in:
@@ -7,6 +7,7 @@ use wgui::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
settings,
|
||||
tab::{Tab, TabParams, TabType},
|
||||
various,
|
||||
};
|
||||
@@ -22,7 +23,7 @@ impl Tab for TabHome {
|
||||
}
|
||||
}
|
||||
|
||||
fn configure_label_hello(label_hello: &mut WidgetLabel, i18n: &mut wgui::i18n::I18n) {
|
||||
fn configure_label_hello(label_hello: &mut WidgetLabel, i18n: &mut wgui::i18n::I18n, settings: &settings::Settings) {
|
||||
let mut username = various::get_username();
|
||||
// first character as uppercase
|
||||
if let Some(first) = username.chars().next() {
|
||||
@@ -30,7 +31,12 @@ fn configure_label_hello(label_hello: &mut WidgetLabel, i18n: &mut wgui::i18n::I
|
||||
username.replace_range(0..1, &first);
|
||||
}
|
||||
|
||||
let translated = i18n.translate_and_replace("HELLO_USER", ("{USER}", &username));
|
||||
let translated = if !settings.home_screen.hide_username {
|
||||
i18n.translate_and_replace("HELLO_USER", ("{USER}", &username))
|
||||
} else {
|
||||
i18n.translate("HELLO").to_string()
|
||||
};
|
||||
|
||||
label_hello.set_text_simple(i18n, Translation::from_raw_text(&translated));
|
||||
}
|
||||
|
||||
@@ -47,7 +53,7 @@ impl TabHome {
|
||||
)?;
|
||||
|
||||
let mut label_hello = state.fetch_widget_as::<WidgetLabel>(¶ms.layout.state, "label_hello")?;
|
||||
configure_label_hello(&mut label_hello, &mut params.globals.i18n());
|
||||
configure_label_hello(&mut label_hello, &mut params.globals.i18n(), params.settings);
|
||||
|
||||
let btn_apps = state.fetch_component_as::<ComponentButton>("btn_apps")?;
|
||||
let btn_games = state.fetch_component_as::<ComponentButton>("btn_games")?;
|
||||
|
||||
@@ -3,12 +3,11 @@ use std::rc::Rc;
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
components::checkbox::ComponentCheckbox,
|
||||
event::CallbackDataCommon,
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
frontend::{Frontend, RcFrontend},
|
||||
frontend::{Frontend, FrontendTask},
|
||||
settings,
|
||||
tab::{Tab, TabParams, TabType},
|
||||
};
|
||||
@@ -28,6 +27,7 @@ fn init_setting_checkbox(
|
||||
params: &mut TabParams,
|
||||
checkbox: Rc<ComponentCheckbox>,
|
||||
fetch_callback: fn(&mut settings::Settings) -> &mut bool,
|
||||
change_callback: Option<fn(&mut Frontend, bool)>,
|
||||
) -> anyhow::Result<()> {
|
||||
let mut c = params.layout.start_common();
|
||||
|
||||
@@ -36,6 +36,10 @@ fn init_setting_checkbox(
|
||||
checkbox.on_toggle(Box::new(move |_common, e| {
|
||||
let mut frontend = rc_frontend.borrow_mut();
|
||||
*fetch_callback(&mut frontend.settings) = e.checked;
|
||||
|
||||
if let Some(change_callback) = &change_callback {
|
||||
change_callback(&mut frontend, e.checked);
|
||||
}
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
@@ -59,12 +63,16 @@ impl TabSettings {
|
||||
&mut params,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_hide_username")?,
|
||||
|settings| &mut settings.home_screen.hide_username,
|
||||
None,
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
&mut params,
|
||||
state.data.fetch_component_as::<ComponentCheckbox>("cb_am_pm_clock")?,
|
||||
|settings| &mut settings.general.am_pm_clock,
|
||||
Some(|frontend, _| {
|
||||
frontend.push_task(FrontendTask::RefreshClock);
|
||||
}),
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
@@ -73,6 +81,9 @@ impl TabSettings {
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_opaque_background")?,
|
||||
|settings| &mut settings.general.opaque_background,
|
||||
Some(|frontend, _| {
|
||||
frontend.push_task(FrontendTask::RefreshBackground);
|
||||
}),
|
||||
)?;
|
||||
|
||||
init_setting_checkbox(
|
||||
@@ -81,6 +92,7 @@ impl TabSettings {
|
||||
.data
|
||||
.fetch_component_as::<ComponentCheckbox>("cb_xwayland_by_default")?,
|
||||
|settings| &mut settings.tweaks.xwayland_by_default,
|
||||
None,
|
||||
)?;
|
||||
|
||||
Ok(Self { state })
|
||||
|
||||
Reference in New Issue
Block a user