xmpd/xmpd-gui/src/utils.rs
2026-01-11 22:41:43 +02:00

51 lines
1.4 KiB
Rust

use std::fmt::Display;
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub enum SearchType {
Normal,
Author,
Source,
Genre
}
impl SearchType {
pub fn from_str(s: &str) -> (Self, String) {
match s {
i @ _ if i.starts_with("source:") =>
(Self::Source, i.strip_prefix("source:").unwrap_or("").to_string().to_lowercase()),
i @ _ if i.starts_with("author:") =>
(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())
}
}
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) {
egui::Frame::none()
.fill(color)
.show(ui, |ui| {
ui.set_width(width);
ui.set_height(height);
});
}