From 6077efb3adfde8c8117d3f0cd512173da25a9735 Mon Sep 17 00:00:00 2001 From: Rebornim Date: Wed, 11 Nov 2026 02:44:17 +0000 Subject: [PATCH] Assets: type tab row: a click on the picked type shows every type again, types with nothing matching greyed, one dropdown when narrow --- crates/ui-egui/src/i18n/ar.rs | 1 + crates/ui-egui/src/i18n/de.rs | 1 + crates/ui-egui/src/i18n/es.rs | 1 + crates/ui-egui/src/i18n/fr.rs | 1 + crates/ui-egui/src/i18n/it.rs | 1 + crates/ui-egui/src/i18n/ja.rs | 1 + crates/ui-egui/src/i18n/ko.rs | 1 + crates/ui-egui/src/i18n/pt_br.rs | 1 + crates/ui-egui/src/i18n/zh_hans.rs | 1 + crates/ui-egui/src/lib.rs | 1 + crates/ui-egui/src/shelf.rs | 34 +++++--------- crates/ui-egui/src/shelf_tabs.rs | 71 ++++++++++++++++++++++++++++++ crates/ui-egui/src/state.rs | 2 +- 13 files changed, 94 insertions(+), 23 deletions(-) create mode 100644 crates/ui-egui/src/shelf_tabs.rs diff --git a/crates/ui-egui/src/i18n/ar.rs b/crates/ui-egui/src/i18n/ar.rs index 46a167de..e1f581d2 100644 --- a/crates/ui-egui/src/i18n/ar.rs +++ b/crates/ui-egui/src/i18n/ar.rs @@ -1129,4 +1129,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "الحد الأقصى لبيانات المشروع بعد فك الضغط. ارفع هذا الحد لفتح مشاريع أكبر.", ), + ("Filter by type", "تصفية حسب النوع"), ]; diff --git a/crates/ui-egui/src/i18n/de.rs b/crates/ui-egui/src/i18n/de.rs index 7ad71027..8064b888 100644 --- a/crates/ui-egui/src/i18n/de.rs +++ b/crates/ui-egui/src/i18n/de.rs @@ -1175,4 +1175,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "Maximale entpackte Projektdaten. Erhöhen Sie diesen Grenzwert, um größere Projekte zu öffnen.", ), + ("Filter by type", "Nach Typ filtern"), ]; diff --git a/crates/ui-egui/src/i18n/es.rs b/crates/ui-egui/src/i18n/es.rs index d1c35108..8fb206d4 100644 --- a/crates/ui-egui/src/i18n/es.rs +++ b/crates/ui-egui/src/i18n/es.rs @@ -1166,4 +1166,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "Máximo de datos descomprimidos del proyecto. Aumenta este límite para abrir proyectos más grandes.", ), + ("Filter by type", "Filtrar por tipo"), ]; diff --git a/crates/ui-egui/src/i18n/fr.rs b/crates/ui-egui/src/i18n/fr.rs index 182e71e8..da1da090 100644 --- a/crates/ui-egui/src/i18n/fr.rs +++ b/crates/ui-egui/src/i18n/fr.rs @@ -1190,4 +1190,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "Volume maximal des données décompressées du projet. Augmentez cette limite pour ouvrir des projets plus volumineux.", ), + ("Filter by type", "Filtrer par type"), ]; diff --git a/crates/ui-egui/src/i18n/it.rs b/crates/ui-egui/src/i18n/it.rs index 1e243196..82437ae6 100644 --- a/crates/ui-egui/src/i18n/it.rs +++ b/crates/ui-egui/src/i18n/it.rs @@ -1172,4 +1172,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "Quantità massima di dati decompressi del progetto. Aumenta questo limite per aprire progetti più grandi.", ), + ("Filter by type", "Filtra per tipo"), ]; diff --git a/crates/ui-egui/src/i18n/ja.rs b/crates/ui-egui/src/i18n/ja.rs index c705d024..92ceb5c1 100644 --- a/crates/ui-egui/src/i18n/ja.rs +++ b/crates/ui-egui/src/i18n/ja.rs @@ -1157,4 +1157,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "展開後のプロジェクトデータの上限です。大きなプロジェクトを開くには、この上限を引き上げてください。", ), + ("Filter by type", "種類で絞り込む"), ]; diff --git a/crates/ui-egui/src/i18n/ko.rs b/crates/ui-egui/src/i18n/ko.rs index 20e114da..6bb57959 100644 --- a/crates/ui-egui/src/i18n/ko.rs +++ b/crates/ui-egui/src/i18n/ko.rs @@ -1142,4 +1142,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "압축 해제된 프로젝트 데이터의 최대 크기입니다. 더 큰 프로젝트를 열려면 이 한도를 높이세요.", ), + ("Filter by type", "유형별 필터"), ]; diff --git a/crates/ui-egui/src/i18n/pt_br.rs b/crates/ui-egui/src/i18n/pt_br.rs index 2de14047..8ba06687 100644 --- a/crates/ui-egui/src/i18n/pt_br.rs +++ b/crates/ui-egui/src/i18n/pt_br.rs @@ -1160,4 +1160,5 @@ pub const TABLE: &[(&str, &str)] = &[ "Maximum decompressed project data. Increase this limit to open larger projects.", "Limite de dados descompactados do projeto. Aumente este limite para abrir projetos maiores.", ), + ("Filter by type", "Filtrar por tipo"), ]; diff --git a/crates/ui-egui/src/i18n/zh_hans.rs b/crates/ui-egui/src/i18n/zh_hans.rs index c1925515..3842e2c7 100644 --- a/crates/ui-egui/src/i18n/zh_hans.rs +++ b/crates/ui-egui/src/i18n/zh_hans.rs @@ -1085,4 +1085,5 @@ pub const TABLE: &[(&str, &str)] = &[ ), ("Max project size on open", "打开项目的大小上限"), ("Maximum decompressed project data. Increase this limit to open larger projects.", "解压后项目数据的大小上限。提高此限制以打开更大的项目。"), + ("Filter by type", "按类型筛选"), ]; diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index cbfc80a8..5b87b257 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -51,6 +51,7 @@ mod running_bake; pub mod shelf; mod shelf_entry; pub mod shelf_preview; +mod shelf_tabs; mod soft_box; pub mod state; pub mod symmetry; diff --git a/crates/ui-egui/src/shelf.rs b/crates/ui-egui/src/shelf.rs index 6543b230..fd085ad8 100644 --- a/crates/ui-egui/src/shelf.rs +++ b/crates/ui-egui/src/shelf.rs @@ -15,7 +15,7 @@ use crate::shelf_entry::ShelfEntry; use crate::shelf_preview::ShelfPreview; use crate::theme::Tokens; use crate::thumbs::Thumbs; -use crate::widgets::{dnd_release, icon_button}; +use crate::widgets::dnd_release; /// A shelf tile's size and the gap between tiles in points: a 68 x 78 grid step, as in the reference const TILE_WIDTH: f32 = 66.0; @@ -65,7 +65,7 @@ pub(crate) enum Tab { Environments, } -/// The shelf tabs: icon and (English, translated where shown) name. +/// The shelf tabs: icon and (English, translated where shown) name pub(crate) const TABS: [(Tab, &str, &str); 8] = [ (Tab::Materials, ic::SPHERE, "Materials"), (Tab::Smart, ic::STACK, "Smart materials"), @@ -228,20 +228,12 @@ pub fn drop_target(app: &mut TextureCraftApp, ui: &Ui, response: &egui::Response pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) { let tokens = Tokens::get(ui.ctx()); let ctx = ui.ctx().clone(); - let mut tab = app.ui.shelf_tab.min(TABS.len() - 1); let searching = !app.ui.shelf_filter.is_empty(); - - ui.horizontal_wrapped(|ui| { - let button_size = ui.spacing().interact_size.y; - ui.spacing_mut().item_spacing = vec2(2.0, 2.0); - for (i, (_, icon, label)) in TABS.iter().enumerate() { - if icon_button(ui, icon, tr(label), i == tab && !searching, button_size).clicked() { - tab = i; - app.ui.shelf_filter.clear(); - } - } - }); - app.ui.shelf_tab = tab; + let filter = app.ui.shelf_filter.to_lowercase(); + scan_brushes(app); + let matching: Vec = ShelfEntry::all(app).into_iter().filter(|entry| entry.matches(&filter)).collect(); + let counts: Vec = TABS.iter().map(|(tab, _, _)| matching.iter().filter(|entry| entry.tab() == *tab).count()).collect(); + crate::shelf_tabs::row(app, ui, &counts, |_, _, _| {}); ui.horizontal(|ui| { ui.label(RichText::new(ic::MAGNIFYING_GLASS).color(tokens.text_dim)); @@ -249,16 +241,14 @@ pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) { }); ui.add_space(4.0); - let filter = app.ui.shelf_filter.to_lowercase(); - let shown_tab = TABS[tab].0; - scan_brushes(app); + let tab = app.ui.shelf_tab; + let shown_tab = TABS.get(tab).map(|(shown, _, _)| *shown); // Searching shows matches from every tab in one grid - let mut entries: Vec = - ShelfEntry::all(app).into_iter().filter(|entry| (searching || entry.tab() == shown_tab) && entry.matches(&filter)).collect(); + let mut entries: Vec = matching.into_iter().filter(|entry| searching || crate::shelf_tabs::shows(tab, entry.tab())).collect(); entries.sort_by_cached_key(|entry| entry.label().to_lowercase()); egui::ScrollArea::vertical().id_salt("shelf_scroll").auto_shrink([false, false]).show(ui, |ui| { - if !searching && shown_tab == Tab::Textures { + if !searching && shown_tab == Some(Tab::Textures) { import_images(app, ui, &ctx, entries.is_empty()); } tiles(ui, |ui| { @@ -267,7 +257,7 @@ pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) { } }); - if searching || shown_tab == Tab::Smart { + if searching || shown_tab.is_none_or(|shown| shown == Tab::Smart) { library(app, ui, &filter); } }); diff --git a/crates/ui-egui/src/shelf_tabs.rs b/crates/ui-egui/src/shelf_tabs.rs new file mode 100644 index 00000000..4e2c3e07 --- /dev/null +++ b/crates/ui-egui/src/shelf_tabs.rs @@ -0,0 +1,71 @@ +//! The shelf's type row: one icon per type (none picked shows every type), greyed without matches, one dropdown when narrow + +use egui::{Ui, vec2}; + +use crate::TextureCraftApp; +use crate::i18n::tr; +use crate::shelf::{TABS, Tab}; +use crate::widgets::{icon_button, icon_dropdown_button}; + +/// The gap between the row's icons in points +const ICON_GAP: f32 = 2.0; +/// The size of the dot that marks the collapsed row's dropdown while a type is picked, in points +const FILTER_DOT_RADIUS: f32 = 2.5; + +/// `app.ui.shelf_tab` while no type is picked: every type shows +pub(crate) const NO_TYPE: usize = TABS.len(); + +/// The row, then `trailing` at its right end; `counts[i]` is how many assets of `TABS[i]` match the search +pub(crate) fn row(app: &mut TextureCraftApp, ui: &mut Ui, counts: &[usize], trailing: impl FnOnce(&mut TextureCraftApp, &mut Ui, f32)) { + let size = ui.spacing().interact_size.y; + // The type icons and one icon after them + let row_width = (TABS.len() + 1) as f32 * (size + ICON_GAP); + let mut picked = app.ui.shelf_tab.min(NO_TYPE); + + ui.horizontal(|ui| { + ui.spacing_mut().item_spacing = vec2(ICON_GAP, ICON_GAP); + if ui.available_width() >= row_width { + for (i, (_, icon, label)) in TABS.iter().enumerate() { + // The picked type stays clickable so it can be unpicked + let empty = i != picked && counts.get(i).is_none_or(|count| *count == 0); + if ui.add_enabled_ui(!empty, |ui| icon_button(ui, icon, tr(label), i == picked, size)).inner.clicked() { + picked = if i == picked { NO_TYPE } else { i }; + } + } + } else { + collapsed(ui, &mut picked, counts, size); + } + + let rest = ui.available_width() - size; + ui.add_space(rest.max(0.0)); + trailing(app, ui, size); + }); + app.ui.shelf_tab = picked; +} + +/// One dropdown listing the types, dotted while one is picked +fn collapsed(ui: &mut Ui, picked: &mut usize, counts: &[usize], size: f32) { + let filtering = *picked != NO_TYPE; + let response = icon_dropdown_button(ui, egui_phosphor::regular::FUNNEL_SIMPLE, tr("Filter by type"), filtering, size); + let response = response.on_hover_text(tr("Filter by type")); + if filtering { + let tk = crate::theme::Tokens::get(ui.ctx()); + let dot = response.rect.left_top() + vec2(size - FILTER_DOT_RADIUS, FILTER_DOT_RADIUS); + ui.painter().circle_filled(dot, FILTER_DOT_RADIUS, tk.accent); + } + + egui::Popup::menu(&response).show(|ui| { + for (i, (_, icon, label)) in TABS.iter().enumerate() { + let empty = i != *picked && counts.get(i).is_none_or(|count| *count == 0); + if ui.add_enabled(!empty, egui::Button::selectable(i == *picked, format!("{icon} {}", tr(label)))).clicked() { + *picked = if i == *picked { NO_TYPE } else { i }; + ui.close(); + } + } + }); +} + +/// Whether `tab` (an index into [`TABS`], or [`NO_TYPE`]) shows assets of type `kind` +pub(crate) fn shows(tab: usize, kind: Tab) -> bool { + TABS.get(tab).is_none_or(|(shown, _, _)| *shown == kind) +} diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index e52a2907..2c03dc45 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -297,7 +297,7 @@ pub struct UiState { /// Channel whose blending the layer rows show. pub layer_channel: Channel, pub shelf_filter: String, - /// The asset shelf's open tab. + /// The asset shelf's picked type: an index into the shelf's types, or past them for every type #[serde(default)] pub shelf_tab: usize, pub props_tab: PropsTab,