Add option to change info text font size
This commit is contained in:
parent
ab61924e5f
commit
47db86ba59
2 changed files with 39 additions and 6 deletions
|
@ -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;
|
||||
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue