add WguiFontSystem, remove FONT_SYSTEM singleton, custom fonts, add Light font weight
there are a few gzip-compressed ttf as for now, looks like variable fonts aren't parsed properly by cosmic_text. Not sure why. Also, we probably need to have a fallback for CJK characters in the future, or just fallback to the built-in ones in the OS.
This commit is contained in:
BIN
dash-frontend/assets/Quicksand-Bold.ttf.gz
Normal file
BIN
dash-frontend/assets/Quicksand-Bold.ttf.gz
Normal file
Binary file not shown.
BIN
dash-frontend/assets/Quicksand-Light.ttf.gz
Normal file
BIN
dash-frontend/assets/Quicksand-Light.ttf.gz
Normal file
Binary file not shown.
BIN
dash-frontend/assets/Quicksand-Regular.ttf.gz
Normal file
BIN
dash-frontend/assets/Quicksand-Regular.ttf.gz
Normal file
Binary file not shown.
@@ -100,6 +100,8 @@
|
||||
<rectangle
|
||||
width="100%"
|
||||
height="48"
|
||||
min_height="48"
|
||||
max_height="48"
|
||||
box_sizing="border_box"
|
||||
round="8"
|
||||
flex_direction="row"
|
||||
@@ -130,7 +132,7 @@
|
||||
|
||||
<!-- Right bottom side -->
|
||||
<div margin_right="16">
|
||||
<label id="label_time" size="16" />
|
||||
<label id="label_time" size="16" weight="light" />
|
||||
</div>
|
||||
</rectangle>
|
||||
</div>
|
||||
|
||||
@@ -3,9 +3,9 @@ use std::{cell::RefCell, collections::VecDeque, rc::Rc};
|
||||
use chrono::Timelike;
|
||||
use glam::Vec2;
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
assets::{AssetPath, AssetProvider},
|
||||
components::button::ComponentButton,
|
||||
event::{CallbackDataCommon, EventAlterables},
|
||||
font_config::WguiFontConfig,
|
||||
globals::WguiGlobals,
|
||||
i18n::Translation,
|
||||
layout::{LayoutParams, RcLayout, WidgetID},
|
||||
@@ -54,7 +54,22 @@ pub enum FrontendTask {
|
||||
|
||||
impl Frontend {
|
||||
pub fn new(params: InitParams) -> anyhow::Result<(RcFrontend, RcLayout)> {
|
||||
let globals = WguiGlobals::new(Box::new(assets::Asset {}), wgui::globals::Defaults::default())?;
|
||||
let mut assets = Box::new(assets::Asset {});
|
||||
|
||||
let font_binary_bold = assets.load_from_path_gzip("Quicksand-Bold.ttf.gz")?;
|
||||
let font_binary_regular = assets.load_from_path_gzip("Quicksand-Regular.ttf.gz")?;
|
||||
let font_binary_light = assets.load_from_path_gzip("Quicksand-Light.ttf.gz")?;
|
||||
|
||||
let globals = WguiGlobals::new(
|
||||
assets,
|
||||
wgui::globals::Defaults::default(),
|
||||
&WguiFontConfig {
|
||||
binaries: vec![&font_binary_regular, &font_binary_bold, &font_binary_light],
|
||||
family_name_sans_serif: "Quicksand",
|
||||
family_name_serif: "Quicksand",
|
||||
family_name_monospace: "",
|
||||
},
|
||||
)?;
|
||||
|
||||
let (layout, state) = wgui::parser::new_layout_from_assets(
|
||||
&ParseDocumentParams {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
components::button::ComponentButton,
|
||||
event::CallbackDataCommon,
|
||||
i18n::Translation,
|
||||
layout::Widget,
|
||||
parser::{Fetchable, ParseDocumentParams, ParserState},
|
||||
widget::label::WidgetLabel,
|
||||
};
|
||||
@@ -23,7 +25,7 @@ impl Tab for TabHome {
|
||||
}
|
||||
}
|
||||
|
||||
fn configure_label_hello(label_hello: &mut WidgetLabel, i18n: &mut wgui::i18n::I18n, settings: &settings::Settings) {
|
||||
fn configure_label_hello(common: &mut CallbackDataCommon, label_hello: Widget, settings: &settings::Settings) {
|
||||
let mut username = various::get_username();
|
||||
// first character as uppercase
|
||||
if let Some(first) = username.chars().next() {
|
||||
@@ -32,12 +34,13 @@ fn configure_label_hello(label_hello: &mut WidgetLabel, i18n: &mut wgui::i18n::I
|
||||
}
|
||||
|
||||
let translated = if !settings.home_screen.hide_username {
|
||||
i18n.translate_and_replace("HELLO_USER", ("{USER}", &username))
|
||||
common.i18n().translate_and_replace("HELLO_USER", ("{USER}", &username))
|
||||
} else {
|
||||
i18n.translate("HELLO").to_string()
|
||||
common.i18n().translate("HELLO").to_string()
|
||||
};
|
||||
|
||||
label_hello.set_text_simple(i18n, Translation::from_raw_text(&translated));
|
||||
let mut label_hello = label_hello.get_as_mut::<WidgetLabel>().unwrap();
|
||||
label_hello.set_text(common, Translation::from_raw_text(&translated));
|
||||
}
|
||||
|
||||
impl TabHome {
|
||||
@@ -52,8 +55,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(), params.settings);
|
||||
let mut c = params.layout.start_common();
|
||||
let widget_label = state.fetch_widget(&c.layout.state, "label_hello")?.widget;
|
||||
configure_label_hello(&mut c.common(), widget_label, params.settings);
|
||||
|
||||
let btn_apps = state.fetch_component_as::<ComponentButton>("btn_apps")?;
|
||||
let btn_games = state.fetch_component_as::<ComponentButton>("btn_games")?;
|
||||
|
||||
@@ -2,7 +2,6 @@ use std::rc::Rc;
|
||||
|
||||
use wgui::{
|
||||
components::button::ComponentButton,
|
||||
event::CallbackDataCommon,
|
||||
globals::WguiGlobals,
|
||||
layout::{Layout, WidgetID},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user