diff --git a/activity-tracker/src/view/activity_tracker.rs b/activity-tracker/src/view/activity_tracker.rs index 58dea315..3e563554 100644 --- a/activity-tracker/src/view/activity_tracker.rs +++ b/activity-tracker/src/view/activity_tracker.rs @@ -48,12 +48,14 @@ impl ActivityTracker { let locale = res.get::(); vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::Y, Sort::MostPlayed.button_hint(&locale), diff --git a/allium-launcher/src/view/app.rs b/allium-launcher/src/view/app.rs index 8f55423f..fc6bf3e0 100644 --- a/allium-launcher/src/view/app.rs +++ b/allium-launcher/src/view/app.rs @@ -38,11 +38,13 @@ pub struct App where B: Battery + 'static, { + res: Resources, rect: Rect, battery_indicator: BatteryIndicator, views: (Recents, Games, Apps, Settings), selected: usize, tabs: Row>, + title: Label, dirty: bool, } @@ -59,6 +61,7 @@ where ) -> Result { let Rect { x, y, w, h: _h } = rect; let styles = res.get::(); + let locale = res.get::(); let battery_indicator = BatteryIndicator::new( Point::new(w as i32 - 12, y + 8), @@ -69,7 +72,6 @@ where let mut tabs = Row::new( Point::new(x + 12, y + 8), { - let locale = res.get::(); vec![ Label::new( Point::zero(), @@ -94,12 +96,25 @@ where .unwrap() .color(StylesheetColor::Highlight); + let mut title = Label::new( + Point::new(x + 24, y + 8), + title(&locale, selected), + Alignment::Left, + None, + ); + title.font_size(styles.title_font_size); + + drop(styles); + drop(locale); + Ok(Self { + res, rect, views, selected, battery_indicator, tabs, + title, dirty: true, }) } @@ -107,11 +122,12 @@ where pub fn load_or_new(rect: Rect, res: Resources, battery: B) -> Result { let tab_rect = { let styles = res.get::(); + let font_size = (styles.ui_font.size as f32 * styles.title_font_size) as u32; Rect::new( rect.x, - rect.y + styles.ui_font.size as i32 + 8, + rect.y + font_size as i32 + 8, rect.w, - rect.h - styles.ui_font.size - 8, + rect.h - font_size - 8, ) }; @@ -196,6 +212,7 @@ where .get_mut(self.selected) .unwrap() .color(StylesheetColor::Highlight); + self.title.set_text(self.title()); } fn next(&mut self) { @@ -218,6 +235,10 @@ where self.views.0.search(query)?; Ok(()) } + + fn title(&self) -> String { + title(&self.res.get::(), self.selected) + } } #[async_trait(?Send)] @@ -236,17 +257,15 @@ where } let mut drawn = false; - if self.battery_indicator.should_draw() && self.battery_indicator.draw(display, styles)? { - drawn = true; - } + drawn |= + self.battery_indicator.should_draw() && self.battery_indicator.draw(display, styles)?; + drawn |= self.title.should_draw() && self.title.draw(display, styles)?; + drawn |= self.view().should_draw() && self.view_mut().draw(display, styles)?; - if self.tabs.should_draw() && self.tabs.draw(display, styles)? { - drawn = true; - } + // if self.tabs.should_draw() && self.tabs.draw(display, styles)? { + // drawn = true; + // } - if self.view().should_draw() && self.view_mut().draw(display, styles)? { - drawn = true; - } Ok(drawn) } @@ -313,3 +332,13 @@ where unimplemented!() } } + +fn title(locale: &Locale, selected: usize) -> String { + match selected { + 0 => locale.t("tab-recents"), + 1 => locale.t("tab-games"), + 2 => locale.t("tab-apps"), + 3 => locale.t("tab-settings"), + _ => unreachable!(), + } +} diff --git a/allium-launcher/src/view/entry_list.rs b/allium-launcher/src/view/entry_list.rs index 46798bc7..b02fe739 100644 --- a/allium-launcher/src/view/entry_list.rs +++ b/allium-launcher/src/view/entry_list.rs @@ -97,6 +97,7 @@ where let locale = res.get::(); button_hints.push(ButtonHint::new( + res.clone(), Point::zero(), Key::A, locale.t("button-select"), @@ -104,6 +105,7 @@ where )); if S::HAS_BUTTON_HINTS { button_hints.push(ButtonHint::new( + res.clone(), Point::zero(), Key::Y, sort.button_hint(&locale), diff --git a/allium-launcher/src/view/games.rs b/allium-launcher/src/view/games.rs index 513f3b9b..9324ce57 100644 --- a/allium-launcher/src/view/games.rs +++ b/allium-launcher/src/view/games.rs @@ -44,6 +44,7 @@ impl Games { { let locale = res.get::(); vec![ButtonHint::new( + res.clone(), Point::zero(), Key::X, locale.t("sort-search"), diff --git a/allium-launcher/src/view/recents.rs b/allium-launcher/src/view/recents.rs index 8f8d9c0f..7d641154 100644 --- a/allium-launcher/src/view/recents.rs +++ b/allium-launcher/src/view/recents.rs @@ -47,6 +47,7 @@ impl Recents { { let locale = res.get::(); vec![ButtonHint::new( + res.clone(), Point::zero(), Key::X, locale.t("sort-search"), diff --git a/allium-launcher/src/view/settings/about.rs b/allium-launcher/src/view/settings/about.rs index 37bce169..7b048017 100644 --- a/allium-launcher/src/view/settings/about.rs +++ b/allium-launcher/src/view/settings/about.rs @@ -101,6 +101,7 @@ impl About { rect.y + rect.h as i32 - ButtonIcon::diameter(&styles) as i32 - 8, ), vec![ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), diff --git a/allium-launcher/src/view/settings/clock.rs b/allium-launcher/src/view/settings/clock.rs index 55bb9071..5e3d1bb0 100644 --- a/allium-launcher/src/view/settings/clock.rs +++ b/allium-launcher/src/view/settings/clock.rs @@ -160,6 +160,7 @@ impl Clock { rect.y + rect.h as i32 - ButtonIcon::diameter(&styles) as i32 - 8, ), vec![ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), diff --git a/allium-launcher/src/view/settings/display.rs b/allium-launcher/src/view/settings/display.rs index 8e5ddbf2..0f35233e 100644 --- a/allium-launcher/src/view/settings/display.rs +++ b/allium-launcher/src/view/settings/display.rs @@ -110,6 +110,7 @@ impl Display { rect.y + rect.h as i32 - ButtonIcon::diameter(&styles) as i32 - 8, ), vec![ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), @@ -119,6 +120,7 @@ impl Display { 12, ); let edit_button = Some(ButtonHint::new( + res.clone(), Point::zero(), Key::A, locale.t("button-edit"), diff --git a/allium-launcher/src/view/settings/language.rs b/allium-launcher/src/view/settings/language.rs index 3c291c42..5d90bae5 100644 --- a/allium-launcher/src/view/settings/language.rs +++ b/allium-launcher/src/view/settings/language.rs @@ -74,12 +74,14 @@ impl Language { ), vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::A, locale.t("button-edit"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), diff --git a/allium-launcher/src/view/settings/mod.rs b/allium-launcher/src/view/settings/mod.rs index 9744615f..5c57524d 100644 --- a/allium-launcher/src/view/settings/mod.rs +++ b/allium-launcher/src/view/settings/mod.rs @@ -113,12 +113,14 @@ impl Settings { ), vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::A, locale.t("button-select"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), diff --git a/allium-launcher/src/view/settings/theme.rs b/allium-launcher/src/view/settings/theme.rs index a35e9530..f854753f 100644 --- a/allium-launcher/src/view/settings/theme.rs +++ b/allium-launcher/src/view/settings/theme.rs @@ -165,12 +165,14 @@ impl Theme { ), vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::A, locale.t("button-edit"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), diff --git a/allium-launcher/src/view/settings/wifi.rs b/allium-launcher/src/view/settings/wifi.rs index 1eed60d6..2204bea9 100644 --- a/allium-launcher/src/view/settings/wifi.rs +++ b/allium-launcher/src/view/settings/wifi.rs @@ -100,12 +100,14 @@ impl Wifi { ), vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::A, locale.t("button-edit"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), diff --git a/allium-menu/src/view/ingame_menu.rs b/allium-menu/src/view/ingame_menu.rs index 2b3092b5..b845be7f 100644 --- a/allium-menu/src/view/ingame_menu.rs +++ b/allium-menu/src/view/ingame_menu.rs @@ -135,12 +135,14 @@ where ), vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::A, locale.t("button-select"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), diff --git a/allium-menu/src/view/text_reader.rs b/allium-menu/src/view/text_reader.rs index f8a95149..6cd1b91b 100644 --- a/allium-menu/src/view/text_reader.rs +++ b/allium-menu/src/view/text_reader.rs @@ -63,12 +63,14 @@ impl TextReader { ), vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::X, locale.t("guide-button-search"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), @@ -220,12 +222,14 @@ impl TextReader { if self.button_hints.children().len() <= 2 { let locale = self.res.get::(); self.button_hints.push(ButtonHint::new( + self.res.clone(), Point::zero(), Key::L2, locale.t("guide-next"), Alignment::Right, )); self.button_hints.push(ButtonHint::new( + self.res.clone(), Point::zero(), Key::R2, locale.t("guide-prev"), @@ -250,12 +254,14 @@ impl TextReader { if self.button_hints.children().len() <= 2 { let locale = self.res.get::(); self.button_hints.push(ButtonHint::new( + self.res.clone(), Point::zero(), Key::L, locale.t("guide-next"), Alignment::Right, )); self.button_hints.push(ButtonHint::new( + self.res.clone(), Point::zero(), Key::R, locale.t("guide-prev"), diff --git a/common/src/stylesheet.rs b/common/src/stylesheet.rs index 3dfd32da..d0240ac4 100644 --- a/common/src/stylesheet.rs +++ b/common/src/stylesheet.rs @@ -145,7 +145,10 @@ pub struct Stylesheet { pub guide_font: StylesheetFont, #[serde(skip, default = "StylesheetFont::cjk_font")] pub cjk_font: StylesheetFont, - + #[serde(default = "Stylesheet::default_title_font_size")] + pub title_font_size: f32, + #[serde(default = "Stylesheet::default_button_hint_font_size")] + pub button_hint_font_size: f32, #[serde(default = "Stylesheet::default_alt_foreground_color")] alt_foreground_color: Color, #[serde(default = "Stylesheet::default_alt_background_color")] @@ -263,6 +266,16 @@ rgui_particle_color = "0xFF{highlight:X}" Ok(()) } + #[inline] + fn default_title_font_size() -> f32 { + 1.3 + } + + #[inline] + fn default_button_hint_font_size() -> f32 { + 1.0 + } + #[inline] fn default_foreground_color() -> Color { Color::new(255, 255, 255) @@ -360,6 +373,8 @@ impl Default for Stylesheet { ui_font: StylesheetFont::ui_font(), guide_font: StylesheetFont::guide_font(), cjk_font: StylesheetFont::cjk_font(), + title_font_size: Self::default_title_font_size(), + button_hint_font_size: Self::default_button_hint_font_size(), alt_foreground_color: Self::default_alt_foreground_color(), alt_background_color: Self::default_alt_background_color(), alt_highlight_color: Self::default_alt_highlight_color(), diff --git a/common/src/view/button_hint.rs b/common/src/view/button_hint.rs index 07ef4206..e976bcd8 100644 --- a/common/src/view/button_hint.rs +++ b/common/src/view/button_hint.rs @@ -8,6 +8,7 @@ use tokio::sync::mpsc::Sender; use crate::display::Display; use crate::geom::{Alignment, Point, Rect}; use crate::platform::{DefaultPlatform, Key, KeyEvent, Platform}; +use crate::resources::Resources; use crate::stylesheet::Stylesheet; use crate::view::{ButtonIcon, Command, Label, View}; @@ -28,8 +29,10 @@ impl ButtonHint where S: AsRef + PartialEq + Send, { - pub fn new(point: Point, button: Key, text: S, alignment: Alignment) -> Self { - let label = Label::new(Point::zero(), text, alignment, None); + pub fn new(res: Resources, point: Point, button: Key, text: S, alignment: Alignment) -> Self { + let styles = res.get::(); + let mut label = Label::new(Point::zero(), text, alignment, None); + label.font_size(styles.button_hint_font_size); let button = ButtonIcon::new(Point::zero(), button, alignment); Self { diff --git a/common/src/view/button_icon.rs b/common/src/view/button_icon.rs index 34c63496..280c15a5 100644 --- a/common/src/view/button_icon.rs +++ b/common/src/view/button_icon.rs @@ -36,7 +36,7 @@ impl ButtonIcon { } pub fn diameter(styles: &Stylesheet) -> u32 { - styles.ui_font.size + (styles.ui_font.size as f32 * styles.button_hint_font_size) as u32 } } diff --git a/common/src/view/input/keyboard.rs b/common/src/view/input/keyboard.rs index 6b39d111..3dc27524 100644 --- a/common/src/view/input/keyboard.rs +++ b/common/src/view/input/keyboard.rs @@ -44,18 +44,21 @@ impl Keyboard { ), vec![ ButtonHint::new( + res.clone(), Point::zero(), Key::Start, locale.t("button-confirm"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::B, locale.t("button-back"), Alignment::Right, ), ButtonHint::new( + res.clone(), Point::zero(), Key::R, locale.t("keyboard-button-backspace"), diff --git a/common/src/view/label.rs b/common/src/view/label.rs index e8675f77..f3a87f99 100644 --- a/common/src/view/label.rs +++ b/common/src/view/label.rs @@ -36,6 +36,7 @@ where truncated_text: Option, color: StylesheetColor, background_color: StylesheetColor, + font_size: f32, scrolling: Option, dirty: bool, } @@ -57,6 +58,7 @@ where truncated_text: None, color: StylesheetColor::Foreground, background_color: StylesheetColor::Background, + font_size: 1.0, scrolling: None, dirty: true, } @@ -96,6 +98,11 @@ where self } + pub fn font_size(&mut self, font_size: f32) -> &mut Self { + self.font_size = font_size; + self + } + fn layout(&mut self, styles: &Stylesheet) { if self.truncated_text.is_some() { return; @@ -105,7 +112,7 @@ where let text_style = FontTextStyleBuilder::::new(styles.ui_font.font()) .font_fallback(styles.cjk_font.font()) - .font_size(styles.ui_font.size) + .font_size((styles.ui_font.size as f32 * self.font_size) as u32) .build(); let mut text = Text::with_alignment( @@ -225,7 +232,7 @@ where .font_fallback(styles.cjk_font.font()) .text_color(self.color.to_color(styles)) .background_color(self.background_color.to_color(styles)) - .font_size(styles.ui_font.size) + .font_size((styles.ui_font.size as f32 * self.font_size) as u32) .build(); if self.truncated_text.is_none() { @@ -273,7 +280,7 @@ where fn bounding_box(&mut self, styles: &Stylesheet) -> Rect { let text_style = FontTextStyleBuilder::::new(styles.ui_font.font()) .font_fallback(styles.cjk_font.font()) - .font_size(styles.ui_font.size) + .font_size((styles.ui_font.size as f32 * self.font_size) as u32) .build(); let mut rect: Rect = Text::with_alignment(