107 lines
4.1 KiB
Rust
107 lines
4.1 KiB
Rust
use std::sync::mpsc::Receiver;
|
|
|
|
use xmpd_cache::Message;
|
|
use xmpd_manifest::store::BaseStore;
|
|
use xmpd_settings::theme::Theme;
|
|
|
|
use crate::{components::{self, song_list, toast::ToastType, CompGetter, CompUi}, GuiState};
|
|
|
|
pub fn draw(ctx: &egui::Context, state: &mut GuiState, cache_rx: &Receiver<Message>) -> crate::Result<()> {
|
|
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
|
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Top, "top_nav")
|
|
.frame(get_themed_frame(&theme))
|
|
.show(ctx, |ui| {
|
|
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
|
|
handle_error_ui!(crate::components::top_nav::TopNav::draw(ui, state));
|
|
}
|
|
);
|
|
egui::CentralPanel::default()
|
|
.frame(get_themed_frame(&theme))
|
|
.show(ctx, |ui| {
|
|
handle_error_ui!(components::toast::Toast::draw(ui, state));
|
|
let avail = ui.available_size();
|
|
ui.vertical(|ui| {
|
|
crate::utils::super_separator(ui, theme.accent_color, avail.x, 2.0);
|
|
let avail = ui.available_size();
|
|
let main_height = avail.y * 0.91;
|
|
|
|
let left_nav_width = (avail.x * 0.25).clamp(0.0, 200.0);
|
|
let song_list_width = avail.x - left_nav_width - 35.0;
|
|
ui.horizontal(|ui| {
|
|
ui.set_height(main_height);
|
|
ui.vertical(|ui| {
|
|
ui.set_height(main_height);
|
|
ui.group(|ui| {
|
|
//ui.set_height(main_height * 0.1);
|
|
ui.set_max_width(left_nav_width);
|
|
handle_error_ui!(crate::components::left_nav::header::Header::draw(ui, state));
|
|
});
|
|
let avail = ui.available_size();
|
|
ui.group(|ui| {
|
|
ui.set_height(avail.y);
|
|
ui.set_max_width(left_nav_width);
|
|
handle_error_ui!(crate::components::left_nav::LeftNav::draw(ui, state));
|
|
});
|
|
});
|
|
ui.vertical(|ui| {
|
|
ui.group(|ui| {
|
|
ui.set_width(song_list_width);
|
|
handle_error_ui!(crate::components::song_list::header::Header::draw(ui, state));
|
|
});
|
|
ui.group(|ui| {
|
|
ui.set_width(song_list_width);
|
|
handle_error_ui!(crate::components::song_list::SongList::draw(ui, state));
|
|
});
|
|
});
|
|
});
|
|
|
|
});
|
|
}
|
|
);
|
|
|
|
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "player")
|
|
.frame(get_themed_frame(&theme))
|
|
.show(ctx, |ui| {
|
|
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
|
|
handle_error_ui!(crate::components::player::Player::draw(ui, state));
|
|
}
|
|
);
|
|
if let Ok(msg) = cache_rx.try_recv() {
|
|
match msg {
|
|
Message::DownloadDone(sid) => {
|
|
if let Some(song) = state.manifest.store().get_song(&sid) {
|
|
let mut toast = crate::components::toast::Toast::get()?;
|
|
toast.show_toast(
|
|
"Done downloading",
|
|
&format!("Downloaded {} by {}", song.name(), song.author()),
|
|
ToastType::Info
|
|
);
|
|
}
|
|
}
|
|
Message::Error(file, line, e) => {
|
|
if let Ok(mut toast) = crate::components::toast::Toast::get() {
|
|
toast.show_toast(
|
|
&format!("Error in {file}:{line}"),
|
|
&format!("{e}"),
|
|
crate::components::toast::ToastType::Error,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn get_themed_frame(theme: &Theme) -> egui::Frame {
|
|
egui::Frame::none()
|
|
.fill(theme.primary_bg_color)
|
|
.stroke(egui::Stroke::new(
|
|
5.0,
|
|
theme.secondary_bg_color,
|
|
))
|
|
}
|
|
|
|
|