Add search to resource browser

This commit is contained in:
Luke Street
2023-03-13 01:32:42 -04:00
parent 1cb12c1e10
commit 222140d74d
2 changed files with 43 additions and 4 deletions
+3 -1
View File
@@ -97,7 +97,9 @@ struct UiState {
impl Default for UiState {
fn default() -> Self {
let mut tree = egui_dock::Tree::new(vec![TabType::Empty]);
tree.split_left(egui_dock::NodeIndex::root(), 0.25, vec![TabType::Project(ProjectTab)]);
tree.split_left(egui_dock::NodeIndex::root(), 0.25, vec![TabType::Project(
ProjectTab::default(),
)]);
Self {
tree,
ui_font: FontId { size: 13.0, family: FontFamily::Proportional },
+40 -3
View File
@@ -19,7 +19,10 @@ use crate::{
pub const K_FORM_FMV0: FourCC = FourCC(*b"FMV0");
pub const K_FORM_ROOM: FourCC = FourCC(*b"ROOM");
pub struct ProjectTab;
#[derive(Default)]
pub struct ProjectTab {
search: String,
}
impl SystemTab for ProjectTab {
type LoadParam = ();
@@ -32,12 +35,40 @@ impl SystemTab for ProjectTab {
state: &mut TabState,
) {
let (server, packages) = query;
let mut set_open = None;
ui.horizontal(|ui| {
if ui.button("Expand all").clicked() {
set_open = Some(true);
}
if ui.button("Collapse all").clicked() {
set_open = Some(false);
}
});
egui::TextEdit::singleline(&mut self.search).hint_text("Search").ui(ui);
let mut packages_sorted =
packages.iter().map(|(_, p)| p).collect::<Vec<&PackageDirectory>>();
packages_sorted.sort_by_key(|p| &p.name);
for package in packages_sorted {
egui::CollapsingHeader::new(&package.name).show(ui, |ui| {
for entry in &package.entries {
let search = self.search.to_ascii_lowercase();
let search = search.trim_start_matches('{').trim_end_matches('}');
let mut iter = package
.entries
.iter()
.filter(|e| {
search.is_empty()
|| (search.as_bytes().len() == 4
&& e.kind.0.eq_ignore_ascii_case(search.as_bytes()))
|| matches!(&e.name, Some(v) if v.contains(search))
|| e.id.to_string().contains(search)
})
.peekable();
if iter.peek().is_none() {
continue;
}
egui::CollapsingHeader::new(&package.name).open(set_open).show(ui, |ui| {
for entry in iter {
let monospace =
ui.style().text_styles.get(&egui::TextStyle::Monospace).unwrap().clone();
let mut job = LayoutJob::simple(
@@ -67,6 +98,12 @@ impl SystemTab for ProjectTab {
let asset_ref = AssetRef { id: entry.id, kind: entry.kind };
if egui::SelectableLabel::new(state.open_assets.contains(&asset_ref), job)
.ui(ui)
.context_menu(|ui| {
if ui.button(format!("Copy \"{}\"", entry.id)).clicked() {
ui.output_mut(|out| out.copied_text = format!("{}", entry.id));
ui.close_menu();
}
})
.clicked()
{
match entry.kind {