Impl hide text when "H" key is pressed

This commit is contained in:
Stephen Seo 2021-12-16 17:28:16 +09:00
parent 7616f1e3f2
commit 78da393fac
3 changed files with 59 additions and 36 deletions

View file

@ -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

View 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(
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;
}
}

View 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) => {