Assets: a library breadcrumb above the search (All libraries, Project, Starter assets, Your assets, then folders)

This commit is contained in:
Rebornim committed 2026-11-11 07:31:30 +00:00
1 parent a401d36f9c
commit 3277ef7253
14 files changed
+177 -2

No files matched your search

+4
View File
@@ -1129,4 +1129,8 @@ pub const TABLE: &[(&str, &str)] = &[
"الحد الأقصى لبيانات المشروع بعد فك الضغط. ارفع هذا الحد لفتح مشاريع أكبر.",
),
("Filter by type", "تصفية حسب النوع"),
("All libraries", "كل المكتبات"),
("Browse folders", "تصفح المجلدات"),
("Starter assets", "الأصول المضمّنة"),
("Your assets", "أصولك"),
];
+4
View File
@@ -1175,4 +1175,8 @@ pub const TABLE: &[(&str, &str)] = &[
"Maximale entpackte Projektdaten. Erhöhen Sie diesen Grenzwert, um größere Projekte zu öffnen.",
),
("Filter by type", "Nach Typ filtern"),
("All libraries", "Alle Bibliotheken"),
("Browse folders", "Ordner durchsuchen"),
("Starter assets", "Mitgelieferte Assets"),
("Your assets", "Eigene Assets"),
];
+4
View File
@@ -1166,4 +1166,8 @@ pub const TABLE: &[(&str, &str)] = &[
"Máximo de datos descomprimidos del proyecto. Aumenta este límite para abrir proyectos más grandes.",
),
("Filter by type", "Filtrar por tipo"),
("All libraries", "Todas las bibliotecas"),
("Browse folders", "Explorar carpetas"),
("Starter assets", "Recursos incluidos"),
("Your assets", "Tus recursos"),
];
+4
View File
@@ -1190,4 +1190,8 @@ pub const TABLE: &[(&str, &str)] = &[
"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"),
("All libraries", "Toutes les bibliothèques"),
("Browse folders", "Parcourir les dossiers"),
("Starter assets", "Ressources fournies"),
("Your assets", "Vos ressources"),
];
+4
View File
@@ -1172,4 +1172,8 @@ pub const TABLE: &[(&str, &str)] = &[
"Quantità massima di dati decompressi del progetto. Aumenta questo limite per aprire progetti più grandi.",
),
("Filter by type", "Filtra per tipo"),
("All libraries", "Tutte le librerie"),
("Browse folders", "Sfoglia cartelle"),
("Starter assets", "Risorse incluse"),
("Your assets", "Le tue risorse"),
];
+4
View File
@@ -1157,4 +1157,8 @@ pub const TABLE: &[(&str, &str)] = &[
"展開後のプロジェクトデータの上限です。大きなプロジェクトを開くには、この上限を引き上げてください。",
),
("Filter by type", "種類で絞り込む"),
("All libraries", "すべてのライブラリ"),
("Browse folders", "フォルダーを参照"),
("Starter assets", "付属アセット"),
("Your assets", "マイアセット"),
];
+4
View File
@@ -1142,4 +1142,8 @@ pub const TABLE: &[(&str, &str)] = &[
"압축 해제된 프로젝트 데이터의 최대 크기입니다. 더 큰 프로젝트를 열려면 이 한도를 높이세요.",
),
("Filter by type", "유형별 필터"),
("All libraries", "모든 라이브러리"),
("Browse folders", "폴더 찾아보기"),
("Starter assets", "기본 에셋"),
("Your assets", "내 에셋"),
];
+4
View File
@@ -1160,4 +1160,8 @@ pub const TABLE: &[(&str, &str)] = &[
"Limite de dados descompactados do projeto. Aumente este limite para abrir projetos maiores.",
),
("Filter by type", "Filtrar por tipo"),
("All libraries", "Todas as bibliotecas"),
("Browse folders", "Navegar pelas pastas"),
("Starter assets", "Recursos incluídos"),
("Your assets", "Seus recursos"),
];
+4
View File
@@ -1085,4 +1085,8 @@ pub const TABLE: &[(&str, &str)] = &[
("Max project size on open", "打开项目的大小上限"),
("Maximum decompressed project data. Increase this limit to open larger projects.", "解压后项目数据的大小上限。提高此限制以打开更大的项目。"),
("Filter by type", "按类型筛选"),
("All libraries", "所有库"),
("Browse folders", "浏览文件夹"),
("Starter assets", "内置资源"),
("Your assets", "我的资源"),
];
+1
View File
@@ -50,6 +50,7 @@ mod resource_picker_item;
mod running_bake;
pub mod shelf;
mod shelf_entry;
mod shelf_folders;
pub mod shelf_preview;
mod shelf_tabs;
mod soft_box;
+14 -2
View File
@@ -229,8 +229,19 @@ pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
let ctx = ui.ctx().clone();
let filter = app.ui.shelf_filter.to_lowercase();
scan_brushes(app);
let matching: Vec<ShelfEntry> = ShelfEntry::all(app).into_iter().filter(|entry| entry.matches(&filter)).collect();
let all = ShelfEntry::all(app);
let paths = crate::shelf_folders::with_every_library(crate::shelf_folders::paths(&all));
// A folder that is gone (its last image removed) shows everything again
if !paths.iter().any(|path| path.starts_with(&app.ui.shelf_path)) {
app.ui.shelf_path.clear();
}
let folder = app.ui.shelf_path.clone();
let matching: Vec<ShelfEntry> = all.into_iter().filter(|entry| entry.in_folder(&folder) && entry.matches(&filter)).collect();
let counts: Vec<usize> = TABS.iter().map(|(tab, _, _)| matching.iter().filter(|entry| entry.tab() == *tab).count()).collect();
crate::shelf_folders::breadcrumb(app, ui, &paths);
search_field(app, ui);
crate::shelf_tabs::row(app, ui, &counts, |_, _, _| {});
ui.add_space(4.0);
@@ -250,7 +261,8 @@ pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
}
});
if shown_tab.is_none_or(|shown| shown == Tab::Smart) {
let in_user_library = folder.first().is_none_or(|library| library == crate::shelf_entry::USER);
if in_user_library && shown_tab.is_none_or(|shown| shown == Tab::Smart) {
library(app, ui, &filter);
}
});
+30
View File
@@ -25,6 +25,13 @@ const SEED_PROBE_OFFSET: f32 = 0.13;
/// A smaller difference between the two seeds' samples is rounding
const SEED_TOLERANCE: f32 = 1e-4;
/// The libraries' ids: the open project's images, the built-in assets, the user's saved assets
pub(crate) const PROJECT: &str = "project";
pub(crate) const STARTER: &str = "starter";
pub(crate) const USER: &str = "user";
/// The libraries in the picker's order: id and (English, translated where shown) name
pub(crate) const LIBRARIES: [(&str, &str); 3] = [(PROJECT, "Project"), (STARTER, "Starter assets"), (USER, "Your assets")];
/// A shelf tile's asset
#[derive(Clone)]
pub(crate) enum ShelfEntry {
@@ -88,6 +95,29 @@ impl ShelfEntry {
}
}
/// Where the asset lives: its library id ([`LIBRARIES`]), its type's folder, then its category if it has one (names in English, shown through `tr`)
pub(crate) fn path(&self) -> Vec<&str> {
let (library, folder, category) = match self {
ShelfEntry::Material(material) if material.smart => (STARTER, "Smart materials", Some(material.category)),
ShelfEntry::Material(material) => (STARTER, "Materials", Some(material.category)),
ShelfEntry::SmartMask(_) => (STARTER, "Smart masks", None),
ShelfEntry::Filter(filter) => (STARTER, "Filters", Some(filter.group)),
ShelfEntry::Brush(preset) => (STARTER, "Brushes", Some(preset.category)),
ShelfEntry::SavedBrush(_) => (USER, "Brushes", None),
ShelfEntry::Alpha(alpha) => (STARTER, "Alphas", Some(alpha.category)),
ShelfEntry::Procedural(_) => (STARTER, "Procedurals", None),
ShelfEntry::Environment(_) => (STARTER, "Environments", None),
ShelfEntry::Image(_) => (PROJECT, "Textures", None),
};
[library, folder].into_iter().chain(category).collect()
}
/// Whether the asset is in folder `path` (a library id, then folder names) or below it
pub(crate) fn in_folder(&self, path: &[String]) -> bool {
let own = self.path();
path.len() <= own.len() && path.iter().zip(own).all(|(wanted, have)| wanted == have)
}
/// The name under the tile, translated where the asset's name is
pub(crate) fn label(&self) -> &str {
match self {
+92
View File
@@ -0,0 +1,92 @@
//! The shelf's library folders ([`ShelfEntry::path`]) for the breadcrumb above the search and the Filter by path tree
use egui::{RichText, Ui};
use crate::TextureCraftApp;
use crate::i18n::tr;
use crate::shelf_entry::{LIBRARIES, ShelfEntry};
use crate::theme::Tokens;
use crate::widgets::icon_button;
/// The breadcrumb arrows' size relative to an icon button
const ARROW_SCALE: f32 = 0.8;
/// The folder paths of `entries`, each a library id then folder names
pub(crate) fn paths(entries: &[ShelfEntry]) -> Vec<Vec<String>> {
let mut paths: Vec<Vec<String>> = entries.iter().map(|entry| entry.path().into_iter().map(str::to_string).collect()).collect();
paths.sort();
paths.dedup();
paths
}
/// `paths` and every library, even one with nothing in it (the picker always lists them all)
pub(crate) fn with_every_library(mut paths: Vec<Vec<String>>) -> Vec<Vec<String>> {
paths.extend(LIBRARIES.iter().map(|(id, _)| vec![id.to_string()]));
paths.sort();
paths.dedup();
paths
}
/// The folders right below `prefix` (libraries in their usual order, folders by name)
pub(crate) fn children(paths: &[Vec<String>], prefix: &[String]) -> Vec<String> {
let mut out: Vec<String> = Vec::new();
for path in paths.iter().filter(|path| path.len() > prefix.len() && path.starts_with(prefix)) {
if let Some(next) = path.get(prefix.len())
&& !out.contains(next)
{
out.push(next.clone());
}
}
if prefix.is_empty() {
out.sort_by_key(|library| LIBRARIES.iter().position(|(id, _)| id == library));
}
out
}
/// A folder's shown name: libraries by their name, folders (type and category names) translated
pub(crate) fn name(level: usize, segment: &str) -> &str {
match LIBRARIES.iter().find(|(id, _)| *id == segment) {
Some((_, library)) if level == 0 => tr(library),
_ => tr(segment),
}
}
/// "› All libraries › …": each arrow lists the folders at its level, the names are plain text, a last arrow lists the folders inside
pub(crate) fn breadcrumb(app: &mut TextureCraftApp, ui: &mut Ui, paths: &[Vec<String>]) {
let tk = Tokens::get(ui.ctx());
let size = ui.spacing().interact_size.y * ARROW_SCALE;
let mut picked: Option<Vec<String>> = None;
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = ui.spacing().item_spacing.x * 0.5;
let path = app.ui.shelf_path.clone();
for level in 0..=path.len() {
let options = children(paths, &path[..level]);
if level > 0 && options.is_empty() {
break;
}
let current = path.get(level);
let response = icon_button(ui, egui_phosphor::regular::CARET_RIGHT, tr("Browse folders"), false, size);
egui::Popup::menu(&response).show(|ui| {
if level == 0 && ui.selectable_label(current.is_none(), tr("All libraries")).clicked() {
picked = Some(Vec::new());
}
for option in &options {
if ui.selectable_label(current == Some(option), name(level, option)).clicked() {
picked = Some(path[..level].iter().cloned().chain([option.clone()]).collect());
}
}
});
let shown = match current {
Some(segment) => name(level, segment),
None if level == 0 => tr("All libraries"),
None => continue,
};
ui.label(RichText::new(shown).strong().color(tk.text_strong));
}
});
if let Some(path) = picked {
app.ui.shelf_path = path;
}
}
+4
View File
@@ -300,6 +300,9 @@ pub struct UiState {
/// 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,
/// The asset shelf's library folder: a library id, then folder names (empty: all libraries)
#[serde(default)]
pub shelf_path: Vec<String>,
pub props_tab: PropsTab,
#[serde(default)]
pub text: TextUi,
@@ -390,6 +393,7 @@ impl Default for UiState {
layer_channel: Channel::BaseColor,
shelf_filter: String::new(),
shelf_tab: 0,
shelf_path: Vec::new(),
props_tab: PropsTab::Brush,
text: TextUi::default(),
rename: None,