space to play/pause

+ bugfix: when clearing queue, last song's title would still be shown. this is no longer the case
This commit is contained in:
Mark 2023-10-25 19:07:57 +02:00
parent 1eee22bb4b
commit 5161b5577d
2 changed files with 38 additions and 13 deletions

View File

@ -153,17 +153,17 @@ impl GuiElemTrait for CurrentSong {
// redraw
if self.config.redraw {
self.config.redraw = false;
if let Some(song) = new_song {
let status_bar_text = info
.gui_config
.status_bar_text
.gen(&info.database, info.database.get_song(&song));
self.children[0]
.try_as_mut::<AdvancedLabel>()
.unwrap()
.content = status_bar_text;
self.children[0]
.try_as_mut::<AdvancedLabel>()
.unwrap()
.content = if let Some(song) = new_song {
self.text_updated = Some(Instant::now());
}
info.gui_config
.status_bar_text
.gen(&info.database, info.database.get_song(&song))
} else {
vec![]
};
}
}
if let Some(updated) = &self.text_updated {

View File

@ -1,7 +1,13 @@
use std::time::Instant;
use musicdb_lib::data::queue::QueueContent;
use speedy2d::{color::Color, dimen::Vec2, shape::Rectangle, Graphics2D};
use musicdb_lib::{data::queue::QueueContent, server::Command};
use speedy2d::{
color::Color,
dimen::Vec2,
shape::Rectangle,
window::{KeyScancode, VirtualKeyCode},
Graphics2D,
};
use crate::{
gui::{morph_rect, DrawInfo, GuiAction, GuiElem, GuiElemCfg, GuiElemTrait},
@ -83,7 +89,7 @@ impl GuiScreen {
scroll_sensitivity_pages: f64,
) -> Self {
Self {
config: config.w_keyboard_watch().w_mouse(),
config: config.w_keyboard_watch().w_mouse().w_keyboard_focus(),
children: vec![
GuiElem::new(notif_overlay),
GuiElem::new(StatusBar::new(
@ -320,6 +326,25 @@ impl GuiElemTrait for GuiScreen {
.get_timeout_val();
}
}
fn key_focus(
&mut self,
modifiers: speedy2d::window::ModifiersState,
down: bool,
key: Option<speedy2d::window::VirtualKeyCode>,
scan: speedy2d::window::KeyScancode,
) -> Vec<GuiAction> {
if down && matches!(key, Some(VirtualKeyCode::Space)) {
vec![GuiAction::Build(Box::new(|db| {
vec![GuiAction::SendToServer(if db.playing {
Command::Pause
} else {
Command::Resume
})]
}))]
} else {
vec![]
}
}
}
#[derive(Clone)]