dash-frontend: tab titles, home screen username

This commit is contained in:
Aleksander
2025-09-20 16:54:16 +02:00
parent 1358af75e3
commit 4f71dc6097
22 changed files with 181 additions and 45 deletions

View File

@@ -20,6 +20,7 @@ use crate::tab::{
mod assets;
mod tab;
mod various;
pub struct Frontend {
pub layout: RcLayout,

View File

@@ -1,9 +1,14 @@
use wgui::{
components::button::ComponentButton,
i18n::Translation,
parser::{ParseDocumentParams, ParserState},
widget::label::WidgetLabel,
};
use crate::tab::{Tab, TabParams, TabType};
use crate::{
tab::{Tab, TabParams, TabType},
various,
};
pub struct TabHome {
#[allow(dead_code)]
@@ -16,6 +21,18 @@ impl Tab for TabHome {
}
}
fn configure_label_hello(label_hello: &mut WidgetLabel, i18n: &mut wgui::i18n::I18n) {
let mut username = various::get_username();
// first character as uppercase
if let Some(first) = username.chars().next() {
let first = first.to_uppercase().to_string();
username.replace_range(0..1, &first);
}
let translated = i18n.translate_and_replace("HELLO_USER", ("{USER}", &username));
label_hello.set_text_simple(i18n, Translation::from_raw_text(&translated));
}
impl TabHome {
pub fn new(params: TabParams) -> anyhow::Result<Self> {
let state = wgui::parser::parse_from_assets(
@@ -29,6 +46,9 @@ impl TabHome {
params.parent_id,
)?;
let mut label_hello = state.fetch_widget_as::<WidgetLabel>(&params.layout.state, "label_hello")?;
configure_label_hello(&mut label_hello, &mut params.globals.i18n());
let btn_apps = state.fetch_component_as::<ComponentButton>("btn_apps")?;
let btn_games = state.fetch_component_as::<ComponentButton>("btn_games")?;
let btn_monado = state.fetch_component_as::<ComponentButton>("btn_monado")?;

View File

@@ -0,0 +1,6 @@
pub fn get_username() -> String {
match std::env::var("USER") {
Ok(user) => user,
Err(_) => String::from("anonymous"),
}
}