dash-frontend: tab titles, home screen username
This commit is contained in:
@@ -20,6 +20,7 @@ use crate::tab::{
|
||||
|
||||
mod assets;
|
||||
mod tab;
|
||||
mod various;
|
||||
|
||||
pub struct Frontend {
|
||||
pub layout: RcLayout,
|
||||
|
||||
@@ -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>(¶ms.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")?;
|
||||
|
||||
6
dash-frontend/src/various.rs
Normal file
6
dash-frontend/src/various.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
pub fn get_username() -> String {
|
||||
match std::env::var("USER") {
|
||||
Ok(user) => user,
|
||||
Err(_) => String::from("anonymous"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user