Settings, took care of warnings

This commit is contained in:
2024-11-15 12:33:11 +02:00
parent 14ee1e69bc
commit a060161c64
26 changed files with 323 additions and 126 deletions

View File

@@ -19,7 +19,7 @@ bench = false
[dependencies]
xmpd-manifest.path = "../xmpd-manifest"
xmpd-derive.path = "../xmpd-derive"
xmpd-settings.path = "../xmpd-settings"
egui.workspace = true
eframe.workspace = true
tokio.workspace = true

View File

@@ -43,12 +43,13 @@ impl CompUi for LeftNav {
}
fn add_playlist_tab(ui: &mut egui::Ui, pid: &Option<uuid::Uuid>, title: &str, author: Option<&str>, song_count: usize, width: f32) {
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
let wdg_rect = ui.horizontal(|ui| {
ui.set_width(width);
ui.add_space(5.0);
ui.add(
egui::Image::new(crate::data::NOTE_ICON)
.tint(crate::data::C_ACCENT)
.tint(theme.accent_color)
.fit_to_exact_size(egui::Vec2::new(32.0, 32.0))
);
ui.vertical(|ui| {
@@ -57,7 +58,7 @@ fn add_playlist_tab(ui: &mut egui::Ui, pid: &Option<uuid::Uuid>, title: &str, au
ui.label(
RichText::new(title)
.size(10.0)
.color(crate::data::C_ACCENT)
.color(theme.accent_color)
);
} else {
ui.label(
@@ -69,13 +70,13 @@ fn add_playlist_tab(ui: &mut egui::Ui, pid: &Option<uuid::Uuid>, title: &str, au
if let Some(author) = author {
ui.monospace(
RichText::new(format!("By {author}"))
.color(crate::data::C_TEXT_DIM)
.color(theme.dim_text_color)
.size(8.0)
);
}
ui.monospace(
RichText::new(format!("{song_count} songs"))
.color(crate::data::C_TEXT_DIM)
.color(theme.dim_text_color)
.size(8.0)
);
});

View File

@@ -1,4 +1,4 @@
use std::sync::{MutexGuard, PoisonError};
use std::sync::MutexGuard;
use crate::GuiState;

View File

@@ -13,7 +13,8 @@ component_register!(Player);
impl CompUi for Player {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
fn draw(ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
let theme = xmpd_settings::Settings::get()?.theme.clone();
let avail = ui.available_size();
ui.vertical_centered_justified(|ui| {
ui.add_space(3.0);
@@ -25,7 +26,7 @@ impl CompUi for Player {
.show_value(false);
ui.style_mut().spacing.slider_width = avail.x * 0.90;
let s = Stroke {
color: crate::data::C_ACCENT,
color: theme.accent_color,
width: 2.0
};
ui.style_mut().visuals.widgets.inactive.fg_stroke = s;
@@ -45,15 +46,15 @@ impl CompUi for Player {
let prev = egui::Image::new(crate::data::PREV_ICON)
.tint(crate::data::C_ACCENT)
.tint(theme.accent_color)
.sense(Sense::click())
.max_size(Vec2::new(16.0, 16.0));
let pp = egui::Image::new(pp)
.tint(crate::data::C_ACCENT)
.tint(theme.accent_color)
.sense(Sense::click())
.max_size(Vec2::new(16.0, 16.0));
let next = egui::Image::new(crate::data::NEXT_ICON)
.tint(crate::data::C_ACCENT)
.tint(theme.accent_color)
.sense(Sense::click())
.max_size(Vec2::new(16.0, 16.0));
if ui.add(prev).clicked() {}

View File

@@ -1,6 +1,6 @@
use egui::{Color32, RichText, Vec2};
use egui::{RichText, Vec2};
use song_list_nav::SearchType;
use xmpd_manifest::{query::QueryType, song::Song, store::BaseStore};
use xmpd_manifest::{song::Song, store::BaseStore};
use super::{CompGetter, CompUi};
pub mod song_list_nav;
@@ -79,23 +79,23 @@ impl CompUi for SongList {
}
fn display_song_tab(ui: &mut egui::Ui, sid: &uuid::Uuid, song: &Song) {
let theme = handle_error_ui!(xmpd_settings::Settings::get()).theme.clone();
let rct = ui.horizontal(|ui| {
ui.add(
egui::Image::new(crate::data::NOTE_ICON)
.tint(crate::data::C_ACCENT)
.tint(theme.accent_color)
.fit_to_exact_size(Vec2::new(32.0, 32.0))
);
ui.vertical(|ui| {
let selected_song_id = {handle_error_ui!(SongList::get()).selected_song_id};
if selected_song_id == *sid {
ui.label(RichText::new(song.name()).color(crate::data::C_ACCENT));
ui.label(RichText::new(song.name()).color(theme.accent_color));
} else {
ui.label(song.name());
};
ui.monospace(
RichText::new(format!("By {}", song.author()))
.color(crate::data::C_TEXT_DIM)
.color(theme.dim_text_color)
.size(10.0)
);
});

View File

@@ -16,10 +16,11 @@ component_register!(SongListNav);
impl CompUi for SongListNav {
fn draw(ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
let theme = xmpd_settings::Settings::get()?.theme.clone();
ui.horizontal(|ui| {
let search_icon = egui::Image::new(crate::data::SEARCH_ICON)
.fit_to_exact_size(egui::Vec2::new(16.0, 16.0))
.tint(crate::data::C_ACCENT);
.tint(theme.accent_color);
ui.add(search_icon);
{
ui.text_edit_singleline(&mut handle_error_ui!(SongListNav::get()).text);

View File

@@ -1,12 +1,8 @@
use super::CompUi;
#[derive(Debug, Default)]
pub struct TopNav;
component_register!(TopNav);
impl CompUi for TopNav {
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
ui.add_space(3.0);
@@ -14,7 +10,15 @@ impl CompUi for TopNav {
ui.add_space(3.0);
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
// TBD
if ui.button("Settings").clicked() {
}
});
ui.menu_button("Manifest", |ui| {
if ui.button("Save").clicked() {
handle_error_ui!(state.manifest.save());
}
});
ui.menu_button("Help", |ui| {
if ui.button("Source").clicked() {
@@ -22,12 +26,7 @@ impl CompUi for TopNav {
}
});
ui.menu_button("Manifest", |ui| {
if ui.button("Save").clicked() {
handle_error_ui!(state.manifest.save());
}
});
});
});

View File

@@ -1,18 +1,8 @@
// pub const APP_ICON: egui::ImageSource = egui::include_image!("../../assets/app_icon.png");
pub const APP_ICON_BYTES: &[u8] = include_bytes!("../../assets/app_icon.png");
// pub const APP_ICON_BYTES: &[u8] = include_bytes!("../../assets/app_icon.png");
pub const NOTE_ICON: egui::ImageSource = egui::include_image!("../../assets/note.svg");
pub const SEARCH_ICON: egui::ImageSource = egui::include_image!("../../assets/search.svg");
pub const PREV_ICON: egui::ImageSource = egui::include_image!("../../assets/prev.svg");
pub const NEXT_ICON: egui::ImageSource = egui::include_image!("../../assets/next.svg");
pub const PLAY_ICON: egui::ImageSource = egui::include_image!("../../assets/play.svg");
pub const PAUSE_ICON: egui::ImageSource = egui::include_image!("../../assets/pause.svg");
// TODO: Replace this with config for theming
// pub const C_ACCENT: egui::Color32 = egui::Color32::from_rgb(51, 51, 119);
pub const C_ACCENT: egui::Color32 = egui::Color32::from_rgb(5, 102, 146); // #0566F6
pub const C_PRIM_BG: egui::Color32 = egui::Color32::from_rgb(31, 34, 40); // #1F2228
pub const C_SEC_BG: egui::Color32 = egui::Color32::from_rgb(47, 53, 61); // #2f353d
pub const C_TEXT: egui::Color32 = egui::Color32::from_rgb(223, 223, 223); // #dfdfdf
pub const C_TEXT_DIM: egui::Color32 = egui::Color32::from_rgb(175, 175, 175 ); // #afafaf

View File

@@ -1,8 +1,6 @@
#![feature(async_closure)]
use std::{path::{Path, PathBuf}, time::Duration};
use egui::TextStyle;
use windows::WindowId;
use xmpd_manifest::{store::JsonStore, Manifest};
#[macro_use]
@@ -20,21 +18,21 @@ type Result<T> = anyhow::Result<T>;
pub fn start(manifest_path: PathBuf) -> Result<()> {
let options = eframe::NativeOptions::default();
let mut state = GuiState::new(&manifest_path)?;
let theme = xmpd_settings::Settings::get()?.theme.clone();
let res = eframe::run_simple_native(W_NAME, options, move |ctx, _frame| {
egui_extras::install_image_loaders(ctx);
state.windows.clone().draw_all(ctx, &mut state);
egui::CentralPanel::default()
.frame(
egui::Frame::none()
.fill(data::C_PRIM_BG)
.fill(theme.primary_bg_color)
.stroke(egui::Stroke::new(
1.0,
data::C_SEC_BG,
theme.secondary_bg_color,
)),
)
.show(ctx, |ui| {
ui.style_mut().visuals.override_text_color = Some(crate::data::C_TEXT);
ui.style_mut().visuals.override_text_color = Some(theme.text_color);
main_window::draw(ui, &mut state)
});
ctx.request_repaint_after(Duration::from_millis(500));

View File

@@ -1,17 +1,13 @@
use egui::ViewportId;
use xmpd_manifest::store::JsonStore;
use crate::{components::{CompGetter, CompUi}, GuiState};
use crate::{components::CompUi, GuiState};
pub fn draw(ui: &mut egui::Ui, state: &mut GuiState) -> crate::Result<()> {
// The central panel the region left after adding TopPanel's and SidePanel's
// ui.heading(format!("Songs ({})", self.manifest.get_song_count()));
let theme = xmpd_settings::Settings::get()?.theme.clone();
let avail = ui.available_size();
ui.vertical(|ui| {
handle_error_ui!(crate::components::top_nav::TopNav::draw(ui, state));
crate::utils::super_separator(ui, crate::data::C_ACCENT, avail.x, 2.0);
crate::utils::super_separator(ui, theme.accent_color, avail.x, 2.0);
let avail = ui.available_size();
let main_height = avail.y * 0.91;
@@ -35,15 +31,15 @@ pub fn draw(ui: &mut egui::Ui, state: &mut GuiState) -> crate::Result<()> {
egui::TopBottomPanel::new(egui::panel::TopBottomSide::Bottom, "player")
.frame(
egui::Frame::none()
.fill(crate::data::C_PRIM_BG)
.fill(theme.primary_bg_color)
.stroke(egui::Stroke::new(
1.0,
crate::data::C_SEC_BG,
theme.secondary_bg_color,
)),
)
.show(ui.ctx(), |ui| {
ui.style_mut().visuals.override_text_color = Some(crate::data::C_TEXT);
ui.style_mut().visuals.override_text_color = Some(theme.accent_color);
handle_error_ui!(crate::components::player::Player::draw(ui, state));
});
});

View File

@@ -2,7 +2,6 @@
pub fn super_separator(ui: &mut egui::Ui, color: egui::Color32, width: f32, height: f32) {
egui::Frame::none()
.fill(color)
// .stroke(egui::Stroke { color: crate::data::C_ACCENT, width: 1.0 })
.show(ui, |ui| {
ui.set_width(width);
ui.set_height(height);

View File

@@ -7,7 +7,7 @@ pub struct ErrorW {
}
impl Window for ErrorW {
fn draw(&self, ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
fn draw(&self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
ui.label("Hello from other window!");
Ok(())
}

View File

@@ -1,8 +1,9 @@
use std::{collections::{HashMap, HashSet}, ops::Deref, sync::{Arc, Mutex}};
use std::{collections::{HashMap, HashSet}, sync::{Arc, Mutex}};
use egui::{ViewportBuilder, ViewportId};
use crate::GuiState;
mod error;
mod settings;
lazy_static::lazy_static!(
static ref WINDOWS: Arc<Mutex<HashMap<WindowId, Box<dyn Window>>>> = Arc::new(Mutex::new(HashMap::new()));
@@ -16,6 +17,7 @@ pub trait Window: std::fmt::Debug + Send {
#[derive(Debug, Clone, Hash, PartialEq, PartialOrd, Ord, Eq)]
pub enum WindowId {
Settings,
Error
}
@@ -49,7 +51,6 @@ impl Windows {
if self.is_open(&win_id) {
ctx.show_viewport_immediate(vp_id.clone(), builder.clone(), |ctx, _vp_class| {
ctx.input(|inp| {
// println!("CLose requested: {}",inp.viewport().close_requested() );
self.toggle(win_id, !inp.viewport().close_requested());
});
egui::CentralPanel::default().show(ctx, |ui| {

View File

@@ -0,0 +1,14 @@
use super::Window;
#[derive(Debug, Clone)]
pub struct SettingsW {
}
impl Window for SettingsW {
fn draw(&self, ui: &mut egui::Ui, _: &mut crate::GuiState) -> crate::Result<()> {
Ok(())
}
}