mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-29 17:44:09 +01:00
Assets: type tab row: a click on the picked type shows every type again, types with nothing matching greyed, one dropdown when narrow
This commit is contained in:
1 parent
0ec76bb05e
commit
6077efb3ad
13 files changed
+94
-23
No files matched your search
@@ -1129,4 +1129,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
"Maximum decompressed project data. Increase this limit to open larger projects.",
|
||||
"الحد الأقصى لبيانات المشروع بعد فك الضغط. ارفع هذا الحد لفتح مشاريع أكبر.",
|
||||
),
|
||||
("Filter by type", "تصفية حسب النوع"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -1157,4 +1157,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
"Maximum decompressed project data. Increase this limit to open larger projects.",
|
||||
"展開後のプロジェクトデータの上限です。大きなプロジェクトを開くには、この上限を引き上げてください。",
|
||||
),
|
||||
("Filter by type", "種類で絞り込む"),
|
||||
];
|
||||
@@ -1142,4 +1142,5 @@ pub const TABLE: &[(&str, &str)] = &[
|
||||
"Maximum decompressed project data. Increase this limit to open larger projects.",
|
||||
"압축 해제된 프로젝트 데이터의 최대 크기입니다. 더 큰 프로젝트를 열려면 이 한도를 높이세요.",
|
||||
),
|
||||
("Filter by type", "유형별 필터"),
|
||||
];
|
||||
@@ -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"),
|
||||
];
|
||||
@@ -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", "按类型筛选"),
|
||||
];
|
||||
@@ -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;
|
||||
|
||||
+12
-22
@@ -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> = ShelfEntry::all(app).into_iter().filter(|entry| entry.matches(&filter)).collect();
|
||||
let counts: Vec<usize> = 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> =
|
||||
ShelfEntry::all(app).into_iter().filter(|entry| (searching || entry.tab() == shown_tab) && entry.matches(&filter)).collect();
|
||||
let mut entries: Vec<ShelfEntry> = 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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user