54 lines
1.4 KiB
Rust
54 lines
1.4 KiB
Rust
use egui::Color32;
|
|
|
|
use super::ComponentUiMut;
|
|
|
|
#[derive(Debug, Default, Clone)]
|
|
pub struct SearchBar {
|
|
text: String
|
|
}
|
|
|
|
pub enum SearchType {
|
|
Generic,
|
|
Song,
|
|
Url,
|
|
Source,
|
|
}
|
|
|
|
impl SearchBar {
|
|
pub fn get_search(&self) -> (SearchType, String) {
|
|
if self.text.starts_with("source:") {
|
|
(
|
|
SearchType::Source,
|
|
self.text.strip_prefix("source:").unwrap_or("").to_string().to_lowercase()
|
|
)
|
|
} else if self.text.starts_with("song:") {
|
|
(
|
|
SearchType::Song,
|
|
self.text.strip_prefix("song:").unwrap_or("").to_string().to_lowercase()
|
|
)
|
|
} else if self.text.starts_with("url:") {
|
|
(
|
|
SearchType::Url,
|
|
self.text.strip_prefix("url:").unwrap_or("").to_string().to_lowercase()
|
|
)
|
|
} else {
|
|
(
|
|
SearchType::Generic,
|
|
self.text.clone()
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ComponentUiMut for SearchBar {
|
|
fn ui(&mut self, _: &mut crate::ui::gui::Gui, ui: &mut egui::Ui) {
|
|
ui.vertical(|ui| {
|
|
ui.horizontal(|ui| {
|
|
let tint = Color32::from_hex("#333377").unwrap();
|
|
ui.add(egui::Image::new(crate::data::SEARCH_ICON).tint(tint));
|
|
ui.text_edit_singleline(&mut self.text);
|
|
});
|
|
});
|
|
}
|
|
}
|