Skip to content

Commit

Permalink
feat: add battery level indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
goweiwen committed Dec 25, 2023
1 parent 313444b commit bafc3d7
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 32 deletions.
6 changes: 5 additions & 1 deletion activity-tracker/src/view/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ where
let styles = res.get::<Stylesheet>();
let locale = res.get::<Locale>();

let battery_indicator = BatteryIndicator::new(Point::new(w as i32 - 12, y + 8), battery);
let battery_indicator = BatteryIndicator::new(
Point::new(w as i32 - 12, y + 8),
battery,
styles.show_battery_level,
);

let label = Label::new(
Point::new(x + 12, y + 8),
Expand Down
7 changes: 6 additions & 1 deletion allium-launcher/src/view/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ where
battery: B,
) -> Result<Self> {
let Rect { x, y, w, h: _h } = rect;
let styles = res.get::<Stylesheet>();

let battery_indicator = BatteryIndicator::new(Point::new(w as i32 - 12, y + 8), battery);
let battery_indicator = BatteryIndicator::new(
Point::new(w as i32 - 12, y + 8),
battery,
styles.show_battery_level,
);

let mut tabs = Row::new(
Point::new(x + 12, y + 8),
Expand Down
31 changes: 19 additions & 12 deletions allium-launcher/src/view/settings/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Theme {
),
vec![
locale.t("settings-theme-dark-mode"),
locale.t("settings-theme-show-battery-level"),
locale.t("settings-theme-ui-font"),
locale.t("settings-theme-ui-font-size"),
locale.t("settings-theme-guide-font"),
Expand All @@ -73,6 +74,11 @@ impl Theme {
stylesheet.background_color.is_dark(),
Alignment::Right,
)),
Box::new(Toggle::new(
Point::zero(),
stylesheet.show_battery_level,
Alignment::Right,
)),
Box::new(Select::new(
Point::zero(),
fonts
Expand Down Expand Up @@ -287,24 +293,25 @@ impl View for Theme {
)),
);
}
1 => {
1 => self.stylesheet.toggle_battery_percentage(),
2 => {
self.stylesheet.ui_font.path =
self.fonts[val.as_int().unwrap() as usize].clone()
}
2 => self.stylesheet.ui_font.size = val.as_int().unwrap() as u32,
3 => {
3 => self.stylesheet.ui_font.size = val.as_int().unwrap() as u32,
4 => {
self.stylesheet.guide_font.path =
self.fonts[val.as_int().unwrap() as usize].clone()
}
4 => self.stylesheet.guide_font.size = val.as_int().unwrap() as u32,
5 => self.stylesheet.highlight_color = val.as_color().unwrap(),
6 => self.stylesheet.foreground_color = val.as_color().unwrap(),
7 => self.stylesheet.background_color = val.as_color().unwrap(),
8 => self.stylesheet.disabled_color = val.as_color().unwrap(),
9 => self.stylesheet.button_a_color = val.as_color().unwrap(),
10 => self.stylesheet.button_b_color = val.as_color().unwrap(),
11 => self.stylesheet.button_x_color = val.as_color().unwrap(),
12 => self.stylesheet.button_y_color = val.as_color().unwrap(),
5 => self.stylesheet.guide_font.size = val.as_int().unwrap() as u32,
6 => self.stylesheet.highlight_color = val.as_color().unwrap(),
7 => self.stylesheet.foreground_color = val.as_color().unwrap(),
8 => self.stylesheet.background_color = val.as_color().unwrap(),
9 => self.stylesheet.disabled_color = val.as_color().unwrap(),
10 => self.stylesheet.button_a_color = val.as_color().unwrap(),
11 => self.stylesheet.button_b_color = val.as_color().unwrap(),
12 => self.stylesheet.button_x_color = val.as_color().unwrap(),
13 => self.stylesheet.button_y_color = val.as_color().unwrap(),
_ => unreachable!("Invalid index"),
}

Expand Down
6 changes: 5 additions & 1 deletion allium-menu/src/view/ingame_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ where
);
name.color(common::stylesheet::StylesheetColor::Highlight);

let battery_indicator = BatteryIndicator::new(Point::new(w as i32 - 12, y + 8), battery);
let battery_indicator = BatteryIndicator::new(
Point::new(w as i32 - 12, y + 8),
battery,
styles.show_battery_level,
);

let entries = MenuEntry::entries(&retroarch_info);
let mut menu = SettingsList::new(
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/de-DE/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = Bildschirmauflösung
settings-theme = Design
settings-theme-dark-mode = Dunkles Design
settings-theme-show-battery-level = Akkustand anzeigen
settings-theme-ui-font = UI Schriftart
settings-theme-ui-font-size = UI Schriftgröße
settings-theme-guide-font = Schriftart Anleitung
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = Screen Resolution
settings-theme = Theme
settings-theme-dark-mode = Dark Mode
settings-theme-show-battery-level = Battery Percentage
settings-theme-ui-font = UI Font
settings-theme-ui-font-size = UI Font Size
settings-theme-guide-font = Guide Font
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/es-CO/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = Resolucion
settings-theme = Tema
settings-theme-dark-mode = Modo oscuro
settings-theme-show-battery-level = Porcentaje de bateria
settings-theme-ui-font = Fuente UI
settings-theme-ui-font-size = Tamaño de fuente UI
settings-theme-guide-font = Fuente de Guia
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/es-ES/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = Resolución
settings-theme = Tema
settings-theme-dark-mode = Modo oscuro
settings-theme-show-battery-level = Porcentaje de batería
settings-theme-ui-font = Fuente del menú
settings-theme-ui-font-size = Tamaño de fuente del menú
settings-theme-guide-font = Fuente para las guías
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/fr-FR/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = Résolution écran
settings-theme = Thème
settings-theme-dark-mode = Mode sombre
settings-theme-show-battery-level = Pourcentage de batterie
settings-theme-ui-font = UI: Police
settings-theme-ui-font-size = UI: Taille de police
settings-theme-guide-font = Guide: Police
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/id-ID/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = Resolusi Layar
settings-theme = Tema
settings-theme-dark-mode = Mode Gelap
settings-theme-show-battery-level = Persentase Baterai
settings-theme-ui-font = Huruf sistem
settings-theme-ui-font-size = Ukuran huruf
settings-theme-guide-font = Huruf di Panduan
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/ja-JP/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = 画面解像度
settings-theme = テーマ
settings-theme-dark-mode = ダークモード
settings-theme-show-battery-level = バッテリー残
settings-theme-ui-font = UIフォント
settings-theme-ui-font-size = UIフォントサイズ
settings-theme-guide-font = ガイドフォント
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/zh-CN/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = 屏幕分辨率
settings-theme = 主题
settings-theme-dark-mode = 暗黑模式
settings-theme-show-battery-level = 显示电量
settings-theme-ui-font = UI字体
settings-theme-ui-font-size = UI字体大小
settings-theme-guide-font = 指南字体
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/zh-HK/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = 螢幕分辨率
settings-theme = 主題
settings-theme-dark-mode = 暗黑模式
settings-theme-show-battery-level = 顯示電池電量
settings-theme-ui-font = UI字體
settings-theme-ui-font-size = UI字體大小
settings-theme-guide-font = 指南字體
Expand Down
1 change: 1 addition & 0 deletions assets/root/.allium/locales/zh-TW/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ settings-display-screen-resolution = 螢幕分辨率
settings-theme = 主題
settings-theme-dark-mode = 暗黑模式
settings-theme-show-battery-level = 顯示電池電量
settings-theme-ui-font = UI字體
settings-theme-ui-font-size = UI字體大小
settings-theme-guide-font = 指南字體
Expand Down
4 changes: 2 additions & 2 deletions common/src/platform/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl SimulatorBattery {
pub fn new() -> SimulatorBattery {
SimulatorBattery {
percentage: 100,
charging: true,
charging: false,
}
}
}
Expand All @@ -298,7 +298,7 @@ impl Battery for SimulatorBattery {
fn update(&mut self) -> Result<()> {
trace!("Updating battery");
if self.percentage > 0 {
self.percentage -= 10;
self.percentage -= 5
}
self.charging = !self.charging;
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions common/src/stylesheet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl StylesheetFont {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Stylesheet {
pub enable_box_art: bool,
pub show_battery_level: bool,
#[serde(default = "Stylesheet::default_foreground_color")]
pub foreground_color: Color,
#[serde(default = "Stylesheet::default_background_color")]
Expand Down Expand Up @@ -237,6 +238,10 @@ impl Stylesheet {
mem::swap(&mut self.button_y_color, &mut self.alt_button_y_color);
}

pub fn toggle_battery_percentage(&mut self) {
self.show_battery_level = !self.show_battery_level;
}

fn patch_ra_config(&self) -> Result<()> {
let mut file = File::create("/mnt/SDCARD/RetroArch/.retroarch/assets/rgui/Allium.cfg")?;
write!(
Expand Down Expand Up @@ -343,6 +348,7 @@ impl Default for Stylesheet {
fn default() -> Self {
Self {
enable_box_art: true,
show_battery_level: false,
foreground_color: Self::default_foreground_color(),
background_color: Self::default_background_color(),
highlight_color: Self::default_highlight_color(),
Expand Down
Loading

0 comments on commit bafc3d7

Please sign in to comment.