]> git.seodisparate.com - mpd_info_screen/commitdiff
Impl hide text when "H" key is pressed
authorStephen Seo <seo.disparate@gmail.com>
Thu, 16 Dec 2021 08:28:16 +0000 (17:28 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 16 Dec 2021 08:28:47 +0000 (17:28 +0900)
README.md
src/display.rs
src/main.rs

index 22f832b8c423855660838f293ef6708c4b07c172..81080874c72f637f0f19c671d18f69c49d6af2d0 100644 (file)
--- 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  
index ce8a16bc2c947e2242225857d8b1cb4bd6519060..b027f6a23b0ac7bd1462633d64315e3f2e816ca7 100644 (file)
@@ -68,6 +68,7 @@ pub struct MPDDisplay {
     timer: f64,
     length: f64,
     text_bg_mesh: Option<Mesh>,
+    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(
-                    ctx,
-                    DrawParam {
-                        trans: self.filename_transform,
-                        ..Default::default()
-                    },
-                )?;
-            }
+                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_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()
+                        },
+                    )?;
+                }
 
-            if !self.opts.disable_show_title {
-                self.title_text.draw(
+                self.timer_text.draw(
                     ctx,
                     DrawParam {
-                        trans: self.title_transform,
+                        trans: self.timer_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;
         }
     }
 
index 3cfb6c63f4acef86de614f948c14c6ccc0a186d6..6c8239e60cebf0692b6fff59db98727326cb4888 100644 (file)
@@ -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) => {