From 78da393faca5331e56a9ec25ba1a4ccf80249296 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 16 Dec 2021 17:28:16 +0900 Subject: [PATCH] Impl hide text when "H" key is pressed --- README.md | 2 ++ src/display.rs | 91 ++++++++++++++++++++++++++++++-------------------- src/main.rs | 2 ++ 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 22f832b..8108087 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ counter, and the filename currently being played Note that presing the Escape key when the window is focused closes the program. +Also note that pressing the H key while displaying text will hide the text. + # Issues / TODO - [ ] UTF-8 Non-ascii font support diff --git a/src/display.rs b/src/display.rs index ce8a16b..b027f6a 100644 --- a/src/display.rs +++ b/src/display.rs @@ -68,6 +68,7 @@ pub struct MPDDisplay { timer: f64, length: f64, text_bg_mesh: Option, + hide_text: bool, } impl MPDDisplay { @@ -95,6 +96,7 @@ impl MPDDisplay { timer: 0.0, length: 0.0, text_bg_mesh: None, + hide_text: false, } } @@ -504,50 +506,52 @@ impl EventHandler for MPDDisplay { )?; } - self.notice_text.draw(ctx, DrawParam::default())?; + if !self.hide_text { + self.notice_text.draw(ctx, DrawParam::default())?; - if self.is_valid && self.is_initialized { - if let Some(mesh) = &self.text_bg_mesh { - mesh.draw(ctx, DrawParam::default())?; - } + if self.is_valid && self.is_initialized { + if let Some(mesh) = &self.text_bg_mesh { + mesh.draw(ctx, DrawParam::default())?; + } - if !self.opts.disable_show_filename { - self.filename_text.draw( + if !self.opts.disable_show_filename { + self.filename_text.draw( + ctx, + DrawParam { + trans: self.filename_transform, + ..Default::default() + }, + )?; + } + + if !self.opts.disable_show_artist { + self.artist_text.draw( + ctx, + DrawParam { + trans: self.artist_transform, + ..Default::default() + }, + )?; + } + + if !self.opts.disable_show_title { + self.title_text.draw( + ctx, + DrawParam { + trans: self.title_transform, + ..Default::default() + }, + )?; + } + + self.timer_text.draw( ctx, DrawParam { - trans: self.filename_transform, + trans: self.timer_transform, ..Default::default() }, )?; } - - if !self.opts.disable_show_artist { - self.artist_text.draw( - ctx, - DrawParam { - trans: self.artist_transform, - ..Default::default() - }, - )?; - } - - if !self.opts.disable_show_title { - self.title_text.draw( - ctx, - DrawParam { - trans: self.title_transform, - ..Default::default() - }, - )?; - } - - self.timer_text.draw( - ctx, - DrawParam { - trans: self.timer_transform, - ..Default::default() - }, - )?; } graphics::present(ctx) @@ -588,6 +592,21 @@ impl EventHandler for MPDDisplay { self.password_entered = true; //log(format!("Entered \"{}\"", self.opts.password.as_ref().unwrap_or(&String::new()))); } + } else { + if keycode == event::KeyCode::H { + self.hide_text = true; + } + } + } + + fn key_up_event( + &mut self, + _ctx: &mut Context, + keycode: event::KeyCode, + _keymods: event::KeyMods, + ) { + if keycode == event::KeyCode::H { + self.hide_text = false; } } diff --git a/src/main.rs b/src/main.rs index 3cfb6c6..6c8239e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -93,6 +93,8 @@ fn main() -> Result<(), String> { } if state == ElementState::Pressed { display.key_down_event(ctx, keycode, modifiers_state.into(), false); + } else { + display.key_up_event(ctx, keycode, modifiers_state.into()); } } event::winit_event::WindowEvent::Resized(phys_size) => {