]> git.seodisparate.com - mpd_info_screen/commitdiff
Add option to change info text font size
authorStephen Seo <seo.disparate@gmail.com>
Fri, 13 Sep 2024 07:45:42 +0000 (16:45 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 13 Sep 2024 07:57:19 +0000 (16:57 +0900)
src/display.rs
src/main.rs

index 98ce09fdd7b7687d1ded487435b7537f0d5f76cb..a8360c0d2ab1924ec10eebaa1142cca4e19a950a 100644 (file)
@@ -19,14 +19,16 @@ use std::thread;
 use std::time::{Duration, Instant};
 
 const POLL_TIME: Duration = Duration::from_millis(333);
+const INIT_FONT_SIZE_RATIO: f32 = 1.4167;
 const INIT_FONT_SIZE_X: f32 = 36.0;
-const INIT_FONT_SIZE_Y: f32 = 51.0;
+const INIT_FONT_SIZE_Y: f32 = INIT_FONT_SIZE_X * INIT_FONT_SIZE_RATIO;
 const TEXT_X_OFFSET: f32 = 0.3;
 const TEXT_OFFSET_Y_SPACING: f32 = 0.4;
 const TEXT_HEIGHT_SCALE: f32 = 0.12;
 const ARTIST_HEIGHT_SCALE: f32 = 0.12;
 const ALBUM_HEIGHT_SCALE: f32 = 0.12;
-const TIMER_HEIGHT_SCALE: f32 = 0.105;
+const TIMER_HEIGHT_SCALE_RATIO: f32 = 0.875;
+const TIMER_HEIGHT_SCALE: f32 = TEXT_HEIGHT_SCALE * TIMER_HEIGHT_SCALE_RATIO;
 const MIN_WIDTH_RATIO: f32 = 4.0 / 5.0;
 const INCREASE_AMT: f32 = 6.0 / 5.0;
 const DECREASE_AMT: f32 = 5.0 / 6.0;
@@ -470,10 +472,27 @@ impl MPDDisplay {
     fn refresh_text_transforms(&mut self, ctx: &mut Context) -> GameResult<()> {
         let drawable_size = ctx.gfx.drawable_size();
 
-        let text_height_limit = TEXT_HEIGHT_SCALE * drawable_size.1.abs();
-        let album_height_limit = ALBUM_HEIGHT_SCALE * drawable_size.1.abs();
-        let artist_height_limit = ARTIST_HEIGHT_SCALE * drawable_size.1.abs();
-        let timer_height = TIMER_HEIGHT_SCALE * drawable_size.1.abs();
+        let text_height_scale: f32;
+        let album_height_scale: f32;
+        let artist_height_scale: f32;
+        let timer_height_scale: f32;
+
+        if let Some(forced_scale) = &self.opts.force_text_height_scale {
+            text_height_scale = *forced_scale;
+            album_height_scale = *forced_scale;
+            artist_height_scale = *forced_scale;
+            timer_height_scale = *forced_scale * TIMER_HEIGHT_SCALE_RATIO;
+        } else {
+            text_height_scale = TEXT_HEIGHT_SCALE;
+            album_height_scale = ALBUM_HEIGHT_SCALE;
+            artist_height_scale = ARTIST_HEIGHT_SCALE;
+            timer_height_scale = TIMER_HEIGHT_SCALE;
+        }
+
+        let text_height_limit = text_height_scale * drawable_size.1.abs();
+        let album_height_limit = album_height_scale * drawable_size.1.abs();
+        let artist_height_limit = artist_height_scale * drawable_size.1.abs();
+        let timer_height = timer_height_scale * drawable_size.1.abs();
 
         let mut offset_y: f32 = drawable_size.1;
 
index 10ea49ae7b5fd0c80a8a3ca687b4df4f37f38e84..aab0b7a2a31e46b58087ca1fd053ea7d4952c084 100644 (file)
@@ -37,6 +37,11 @@ pub struct Opt {
     disable_show_filename: bool,
     #[arg(long = "disable-show-percentage", help = "disable percentage display")]
     disable_show_percentage: bool,
+    #[arg(
+        long = "force-text-height-scale",
+        help = "force-set text height relative to window height as a ratio (default 0.12)"
+    )]
+    force_text_height_scale: Option<f32>,
     #[arg(long = "pprompt", help = "input password via prompt")]
     enable_prompt_password: bool,
     #[arg(long = "pfile", help = "read password from file")]
@@ -59,6 +64,15 @@ pub struct Opt {
 
 fn main() -> Result<(), String> {
     let mut opt = Opt::parse();
+    if let Some(forced_scale) = &mut opt.force_text_height_scale {
+        if *forced_scale < 0.01 {
+            *forced_scale = 0.01;
+            println!("WARNING: Clamped \"force-text-height-scale\" to minimum of 0.01!");
+        } else if *forced_scale > 0.5 {
+            *forced_scale = 0.5;
+            println!("WARNING: Clamped \"force-text-height-scale\" to maximum of 0.5!");
+        }
+    }
     println!("Got host addr == {}, port == {}", opt.host, opt.port);
 
     // Read password from file if exists, error otherwise.