mirror of
https://github.com/Dummi26/musicdb.git
synced 2025-12-14 20:06:16 +01:00
update client + remake web-ui (server, incomplete)
This commit is contained in:
@@ -33,6 +33,7 @@ use crate::{
|
||||
gui_edit_song::EditorForSongs,
|
||||
gui_notif::{NotifInfo, NotifOverlay},
|
||||
gui_screen::GuiScreen,
|
||||
gui_song_adder::SongAdder,
|
||||
gui_text::Label,
|
||||
textcfg,
|
||||
};
|
||||
@@ -1127,6 +1128,8 @@ pub enum GuiAction {
|
||||
EditSongs(Vec<Song>),
|
||||
// EditAlbums(Vec<Album>),
|
||||
// EditArtists(Vec<Artist>),
|
||||
OpenAddSongsMenu,
|
||||
CloseAddSongsMenu,
|
||||
}
|
||||
pub enum Dragging {
|
||||
Artist(ArtistId),
|
||||
@@ -1307,6 +1310,19 @@ impl Gui {
|
||||
GuiAction::EditSongs(songs) => {
|
||||
self.gui.c_editing_songs = Some(EditorForSongs::new(songs));
|
||||
}
|
||||
GuiAction::OpenAddSongsMenu => {
|
||||
if self.gui.c_song_adder.is_none() {
|
||||
self.gui.c_song_adder = Some(SongAdder::new(
|
||||
GuiElemCfg::default(),
|
||||
self.high_performance,
|
||||
self.line_height,
|
||||
self.scroll_pixels_multiplier,
|
||||
self.scroll_lines_multiplier,
|
||||
self.scroll_pages_multiplier,
|
||||
));
|
||||
}
|
||||
}
|
||||
GuiAction::CloseAddSongsMenu => self.gui.c_song_adder = None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ use crate::{
|
||||
gui_notif::NotifOverlay,
|
||||
gui_queue::QueueViewer,
|
||||
gui_settings::Settings,
|
||||
gui_song_adder::SongAdder,
|
||||
gui_statusbar::StatusBar,
|
||||
gui_text::Label,
|
||||
gui_wrappers::Hotkey,
|
||||
@@ -49,6 +50,7 @@ pub struct GuiScreen {
|
||||
pub c_editing_songs: Option<EditorForSongs>,
|
||||
pub c_status_bar: StatusBar,
|
||||
pub c_settings: Settings,
|
||||
pub c_song_adder: Option<SongAdder>,
|
||||
pub c_main_view: Panel<MainView>,
|
||||
pub c_context_menu: Option<Box<dyn GuiElem>>,
|
||||
pub idle: AnimationController<f32>,
|
||||
@@ -110,6 +112,7 @@ impl GuiScreen {
|
||||
scroll_sensitivity_lines,
|
||||
scroll_sensitivity_pages,
|
||||
),
|
||||
c_song_adder: None,
|
||||
c_main_view: Panel::new(
|
||||
GuiElemCfg::at(Rectangle::from_tuples((0.0, 0.0), (1.0, 0.9))),
|
||||
MainView {
|
||||
@@ -248,6 +251,7 @@ impl GuiElem for GuiScreen {
|
||||
]
|
||||
.into_iter()
|
||||
.chain(self.c_editing_songs.as_mut().map(|v| v.elem_mut()))
|
||||
.chain(self.c_song_adder.as_mut().map(|v| v.elem_mut()).into_iter())
|
||||
.chain([
|
||||
self.c_status_bar.elem_mut(),
|
||||
self.c_settings.elem_mut(),
|
||||
|
||||
@@ -68,6 +68,7 @@ pub struct SettingsContent {
|
||||
pub scroll_sensitivity: Panel<(Label, Slider)>,
|
||||
pub idle_time: Panel<(Label, Slider)>,
|
||||
pub save_button: Button<[Label; 1]>,
|
||||
pub add_new_songs_button: Button<[Label; 1]>,
|
||||
pub keybinds: Vec<Panel<(AdvancedLabel, KeybindInput)>>,
|
||||
pub keybinds_should_be_updated: Arc<AtomicBool>,
|
||||
pub keybinds_updated: bool,
|
||||
@@ -84,13 +85,14 @@ impl GuiElemChildren for SettingsContent {
|
||||
self.scroll_sensitivity.elem_mut(),
|
||||
self.idle_time.elem_mut(),
|
||||
self.save_button.elem_mut(),
|
||||
self.add_new_songs_button.elem_mut(),
|
||||
]
|
||||
.into_iter()
|
||||
.chain(self.keybinds.iter_mut().map(|v| v.elem_mut())),
|
||||
)
|
||||
}
|
||||
fn len(&self) -> usize {
|
||||
7 + self.keybinds.len()
|
||||
8 + self.keybinds.len()
|
||||
}
|
||||
}
|
||||
pub struct KeybindInput {
|
||||
@@ -455,6 +457,17 @@ impl SettingsContent {
|
||||
Vec2::new(0.5, 0.5),
|
||||
)],
|
||||
),
|
||||
add_new_songs_button: Button::new(
|
||||
GuiElemCfg::default(),
|
||||
|_| vec![GuiAction::OpenAddSongsMenu],
|
||||
[Label::new(
|
||||
GuiElemCfg::default(),
|
||||
"search for new songs".to_string(),
|
||||
Color::WHITE,
|
||||
None,
|
||||
Vec2::new(0.5, 0.5),
|
||||
)],
|
||||
),
|
||||
keybinds: vec![],
|
||||
keybinds_should_be_updated: Arc::new(AtomicBool::new(true)),
|
||||
keybinds_updated: false,
|
||||
@@ -537,7 +550,7 @@ impl GuiElem for Settings {
|
||||
scrollbox.config_mut().redraw = true;
|
||||
if scrollbox.children_heights.len() == scrollbox.children.len() {
|
||||
for (i, h) in scrollbox.children_heights.iter_mut().enumerate() {
|
||||
*h = if i == 0 || i >= 7 {
|
||||
*h = if i == 0 || i >= 8 {
|
||||
info.line_height * 2.0
|
||||
} else {
|
||||
info.line_height
|
||||
|
||||
187
musicdb-client/src/gui_song_adder.rs
Normal file
187
musicdb-client/src/gui_song_adder.rs
Normal file
@@ -0,0 +1,187 @@
|
||||
use musicdb_lib::data::{AlbumId, ArtistId};
|
||||
use speedy2d::{color::Color, dimen::Vec2, Graphics2D};
|
||||
|
||||
use crate::{
|
||||
gui::{DrawInfo, GuiElem, GuiElemCfg},
|
||||
gui_base::{Button, Panel, ScrollBox},
|
||||
gui_text::Label,
|
||||
};
|
||||
|
||||
pub struct SongAdder {
|
||||
pub config: GuiElemCfg,
|
||||
state: u8,
|
||||
c_loading: Option<Label>,
|
||||
c_scroll_box: ScrollBox<Vec<AddableSong>>,
|
||||
c_background: Panel<()>,
|
||||
data: Option<Vec<AddSong>>,
|
||||
}
|
||||
struct AddSong {
|
||||
path: String,
|
||||
path_broken: bool,
|
||||
artist: Option<ArtistId>,
|
||||
album: Option<AlbumId>,
|
||||
}
|
||||
impl SongAdder {
|
||||
pub fn new(
|
||||
mut config: GuiElemCfg,
|
||||
no_animations: bool,
|
||||
line_height: f32,
|
||||
scroll_sensitivity_pixels: f64,
|
||||
scroll_sensitivity_lines: f64,
|
||||
scroll_sensitivity_pages: f64,
|
||||
) -> Self {
|
||||
config.redraw = true;
|
||||
Self {
|
||||
config,
|
||||
state: 0,
|
||||
c_loading: Some(Label::new(
|
||||
GuiElemCfg::default(),
|
||||
format!("Loading..."),
|
||||
Color::GRAY,
|
||||
None,
|
||||
Vec2::new(0.5, 0.5),
|
||||
)),
|
||||
c_scroll_box: ScrollBox::new(
|
||||
GuiElemCfg::default(),
|
||||
crate::gui_base::ScrollBoxSizeUnit::Pixels,
|
||||
vec![],
|
||||
vec![],
|
||||
line_height,
|
||||
),
|
||||
c_background: Panel::with_background(GuiElemCfg::default().w_mouse(), (), Color::BLACK),
|
||||
data: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GuiElem for SongAdder {
|
||||
fn config(&self) -> &GuiElemCfg {
|
||||
&self.config
|
||||
}
|
||||
fn config_mut(&mut self) -> &mut GuiElemCfg {
|
||||
&mut self.config
|
||||
}
|
||||
fn children(&mut self) -> Box<dyn Iterator<Item = &mut dyn GuiElem> + '_> {
|
||||
Box::new(
|
||||
[
|
||||
self.c_loading.as_mut().map(|v| v.elem_mut()),
|
||||
Some(self.c_scroll_box.elem_mut()),
|
||||
Some(self.c_background.elem_mut()),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten(),
|
||||
)
|
||||
}
|
||||
fn any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
fn any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
fn elem(&self) -> &dyn GuiElem {
|
||||
self
|
||||
}
|
||||
fn elem_mut(&mut self) -> &mut dyn GuiElem {
|
||||
self
|
||||
}
|
||||
fn draw(&mut self, info: &mut DrawInfo, _g: &mut Graphics2D) {
|
||||
if self.state < 10 {
|
||||
self.state += 1;
|
||||
if self.state == 2 {
|
||||
self.c_loading = None;
|
||||
eprintln!("Locking GetCon...");
|
||||
let mut get_con = info.get_con.lock().unwrap();
|
||||
eprintln!("Requesting list of unused songs...");
|
||||
match get_con.find_unused_song_files(None).unwrap() {
|
||||
Ok(data) => {
|
||||
eprintln!("Got list of songs.");
|
||||
self.c_scroll_box.children = data
|
||||
.iter()
|
||||
.map(|(path, is_bad)| AddableSong::new(path.to_owned(), *is_bad))
|
||||
.collect();
|
||||
self.c_scroll_box.config_mut().redraw = true;
|
||||
self.data = Some(
|
||||
data.into_iter()
|
||||
.map(|(p, b)| AddSong {
|
||||
path: p,
|
||||
path_broken: b,
|
||||
artist: None,
|
||||
album: None,
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Got error: {e}");
|
||||
self.c_loading = Some(Label::new(
|
||||
GuiElemCfg::default(),
|
||||
format!("Error:\n{e}"),
|
||||
Color::RED,
|
||||
None,
|
||||
Vec2::new(0.5, 0.5),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.config.redraw {
|
||||
self.config.redraw = false;
|
||||
self.c_scroll_box.config_mut().redraw = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AddableSong {
|
||||
pub config: GuiElemCfg,
|
||||
pub c_button: Button<[Label; 1]>,
|
||||
pub path: String,
|
||||
pub is_bad: bool,
|
||||
}
|
||||
impl AddableSong {
|
||||
pub fn new(path: String, is_bad: bool) -> Self {
|
||||
Self {
|
||||
config: GuiElemCfg::default(),
|
||||
c_button: Button::new(
|
||||
GuiElemCfg::default(),
|
||||
|_| vec![],
|
||||
[Label::new(
|
||||
GuiElemCfg::default(),
|
||||
format!("{path}"),
|
||||
if is_bad {
|
||||
Color::LIGHT_GRAY
|
||||
} else {
|
||||
Color::WHITE
|
||||
},
|
||||
None,
|
||||
Vec2::new(0.0, 0.5),
|
||||
)],
|
||||
),
|
||||
path,
|
||||
is_bad,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl GuiElem for AddableSong {
|
||||
fn config(&self) -> &GuiElemCfg {
|
||||
&self.config
|
||||
}
|
||||
fn config_mut(&mut self) -> &mut GuiElemCfg {
|
||||
&mut self.config
|
||||
}
|
||||
fn children(&mut self) -> Box<dyn Iterator<Item = &mut dyn GuiElem> + '_> {
|
||||
Box::new([self.c_button.elem_mut()].into_iter())
|
||||
}
|
||||
fn any(&self) -> &dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
fn any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
self
|
||||
}
|
||||
fn elem(&self) -> &dyn GuiElem {
|
||||
self
|
||||
}
|
||||
fn elem_mut(&mut self) -> &mut dyn GuiElem {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,8 @@ mod gui_screen;
|
||||
#[cfg(feature = "speedy2d")]
|
||||
mod gui_settings;
|
||||
#[cfg(feature = "speedy2d")]
|
||||
mod gui_song_adder;
|
||||
#[cfg(feature = "speedy2d")]
|
||||
mod gui_statusbar;
|
||||
#[cfg(feature = "speedy2d")]
|
||||
mod gui_text;
|
||||
|
||||
Reference in New Issue
Block a user