Compare commits
2 Commits
d6b9d566d2
...
c423993a93
| Author | SHA1 | Date | |
|---|---|---|---|
| c423993a93 | |||
| bbffa5dbd3 |
|
|
@ -13,7 +13,7 @@ members=[
|
||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version="2.1.1"
|
version="2.1.2"
|
||||||
edition="2024"
|
edition="2024"
|
||||||
repository="https://git.mcorangehq.xyz/XOR64/xmpd/"
|
repository="https://git.mcorangehq.xyz/XOR64/xmpd/"
|
||||||
license="GPL-3.0"
|
license="GPL-3.0"
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
|
use eframe::Frame;
|
||||||
|
use egui::{Align, Align2, Area, Key, Layout, Order, Style};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use xmpd_cache::DlStatus;
|
use xmpd_cache::DlStatus;
|
||||||
use xmpd_manifest::{song::Song, store::BaseStore};
|
use xmpd_manifest::{song::Song, store::BaseStore};
|
||||||
|
|
||||||
use crate::{components::{left_nav::LeftNav, toast::ToastType, CompGetter, CompUi}, windows::WindowId};
|
use crate::{components::{CompGetter, CompUi, left_nav::LeftNav, toast::ToastType}, utils::SearchType, windows::WindowId};
|
||||||
|
|
||||||
use super::SongList;
|
use super::SongList;
|
||||||
|
|
||||||
|
|
@ -15,6 +17,8 @@ pub struct Header {
|
||||||
|
|
||||||
component_register!(Header);
|
component_register!(Header);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl CompUi for Header {
|
impl CompUi for Header {
|
||||||
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
fn draw(ui: &mut egui::Ui, state: &mut crate::GuiState) -> crate::Result<()> {
|
||||||
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
let theme = xmpd_settings::Settings::get()?.theme.clone();
|
||||||
|
|
@ -26,7 +30,53 @@ impl CompUi for Header {
|
||||||
.tint(theme.accent_color);
|
.tint(theme.accent_color);
|
||||||
ui.add(search_icon);
|
ui.add(search_icon);
|
||||||
{
|
{
|
||||||
ui.text_edit_singleline(&mut handle_error_ui!(Header::get()).search_text);
|
let resp = ui.text_edit_singleline(&mut handle_error_ui!(Header::get()).search_text);
|
||||||
|
let popup_id = resp.id.with("mode_popup");
|
||||||
|
if resp.clicked() {
|
||||||
|
ui.memory_mut(|m| m.open_popup(popup_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Genuinely cancerous code incoming
|
||||||
|
let search_text = handle_error_ui!(Header::get()).search_text.clone();
|
||||||
|
if !search_text.is_empty() {
|
||||||
|
if ui.memory(|mem: &egui::Memory| mem.is_popup_open(popup_id)) {
|
||||||
|
Area::new(popup_id)
|
||||||
|
.order(Order::Foreground)
|
||||||
|
.constrain(true)
|
||||||
|
.fixed_pos(resp.rect.left_bottom())
|
||||||
|
.pivot(Align2::LEFT_TOP)
|
||||||
|
.show(ui.ctx(), |ui| {
|
||||||
|
let tf = crate::main_window::get_themed_frame(&theme)
|
||||||
|
.stroke(egui::Stroke::new(
|
||||||
|
1.5,
|
||||||
|
theme.secondary_bg_color,
|
||||||
|
));
|
||||||
|
let frame_margin = tf.total_margin();
|
||||||
|
tf.show(ui, |ui| {
|
||||||
|
ui.with_layout(Layout::top_down_justified(Align::LEFT), |ui| {
|
||||||
|
ui.set_width(resp.rect.width() - frame_margin.sum().x);
|
||||||
|
let st = SearchType::from_str(&search_text);
|
||||||
|
let style = ui.style_mut();
|
||||||
|
style.visuals.selection.bg_fill = theme.secondary_bg_color;
|
||||||
|
style.visuals.selection.stroke.color = theme.accent_color;
|
||||||
|
for item in &[SearchType::Author, SearchType::Source, SearchType::Genre] {
|
||||||
|
if ui.selectable_label(st.0 == *item, item.new_query(&st.1)).clicked() {
|
||||||
|
{
|
||||||
|
handle_error_ui!(Header::get()).search_text = item.new_query(&st.1);
|
||||||
|
}
|
||||||
|
ui.memory_mut(|m| m.close_popup());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if ui.input(|i| i.key_pressed(Key::Escape)) || resp.clicked_elsewhere() {
|
||||||
|
ui.memory_mut(|mem| mem.close_popup());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::RIGHT), |ui| {
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::RIGHT), |ui| {
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ impl SongList {
|
||||||
let should_display = match &query_type {
|
let should_display = match &query_type {
|
||||||
SearchType::Normal |
|
SearchType::Normal |
|
||||||
SearchType::Author |
|
SearchType::Author |
|
||||||
|
SearchType::Genre |
|
||||||
SearchType::Source if query_text.is_empty() => true,
|
SearchType::Source if query_text.is_empty() => true,
|
||||||
|
|
||||||
SearchType::Source => {
|
SearchType::Source => {
|
||||||
|
|
@ -83,6 +84,13 @@ impl SongList {
|
||||||
.to_lowercase()
|
.to_lowercase()
|
||||||
.contains(&query_text)
|
.contains(&query_text)
|
||||||
},
|
},
|
||||||
|
SearchType::Genre => {
|
||||||
|
song.genres()
|
||||||
|
.iter()
|
||||||
|
.map(|v| v.to_lowercase().contains(&query_text))
|
||||||
|
.collect::<Vec<bool>>()
|
||||||
|
.contains(&true)
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if should_display {
|
if should_display {
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ pub fn draw(ctx: &egui::Context, state: &mut GuiState, cache_rx: &Receiver<Messa
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_themed_frame(theme: &Theme) -> egui::Frame {
|
pub fn get_themed_frame(theme: &Theme) -> egui::Frame {
|
||||||
egui::Frame::none()
|
egui::Frame::none()
|
||||||
.fill(theme.primary_bg_color)
|
.fill(theme.primary_bg_color)
|
||||||
.stroke(egui::Stroke::new(
|
.stroke(egui::Stroke::new(
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, PartialOrd)]
|
||||||
pub enum SearchType {
|
pub enum SearchType {
|
||||||
Normal,
|
Normal,
|
||||||
Author,
|
Author,
|
||||||
Source,
|
Source,
|
||||||
|
Genre
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SearchType {
|
impl SearchType {
|
||||||
|
|
@ -13,9 +16,27 @@ impl SearchType {
|
||||||
(Self::Source, i.strip_prefix("source:").unwrap_or("").to_string().to_lowercase()),
|
(Self::Source, i.strip_prefix("source:").unwrap_or("").to_string().to_lowercase()),
|
||||||
i @ _ if i.starts_with("author:") =>
|
i @ _ if i.starts_with("author:") =>
|
||||||
(Self::Author, i.strip_prefix("author:").unwrap_or("").to_string().to_lowercase()),
|
(Self::Author, i.strip_prefix("author:").unwrap_or("").to_string().to_lowercase()),
|
||||||
|
i @ _ if i.starts_with("genre:") =>
|
||||||
|
(Self::Author, i.strip_prefix("genre:").unwrap_or("").to_string().to_lowercase()),
|
||||||
i @ _ => (Self::Normal, i.to_string().to_lowercase())
|
i @ _ => (Self::Normal, i.to_string().to_lowercase())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn new_query(&self, s: &str) -> String {
|
||||||
|
format!("{self}:{s}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for SearchType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
let s = match self {
|
||||||
|
Self::Normal => "",
|
||||||
|
Self::Genre => "genre",
|
||||||
|
Self::Source => "source",
|
||||||
|
Self::Author => "author"
|
||||||
|
};
|
||||||
|
f.write_str(s)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn super_separator(ui: &mut egui::Ui, color: egui::Color32, width: f32, height: f32) {
|
pub fn super_separator(ui: &mut egui::Ui, color: egui::Color32, width: f32, height: f32) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user