Assets: a thumbnail size menu at the end of the type row: small, medium or large tiles, or a list

This commit is contained in:
Rebornim committed 2026-11-11 07:31:30 +00:00
1 parent 0fb7d92057
commit 751f793744
14 files changed
+196 -30

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
//! A grid tile's measurements in the shelf's small, medium and large views
/// A grid tile's size and its thumbnail's size and center below the tile's top, in points
pub(crate) struct GridTile {
pub(crate) width: f32,
pub(crate) height: f32,
pub(crate) thumbnail_size: f32,
pub(crate) thumbnail_center_y: f32,
}
+6
View File
@@ -1139,4 +1139,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "حذف"),
("Filter by path", "تصفية حسب المسار"),
("Hide non-applicable folders", "إخفاء المجلدات غير المطابقة"),
("Thumbnail size", "حجم الصورة المصغّرة"),
("Small", "صغير"),
("Medium", "متوسط"),
("Large", "كبير"),
("List", "قائمة"),
("Procedurals", "إجرائيات"),
];
+6
View File
@@ -1185,4 +1185,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "Löschen"),
("Filter by path", "Nach Pfad filtern"),
("Hide non-applicable folders", "Nicht zutreffende Ordner ausblenden"),
("Thumbnail size", "Vorschaugröße"),
("Small", "Klein"),
("Medium", "Mittel"),
("Large", "Groß"),
("List", "Liste"),
("Procedurals", "Prozedurale"),
];
+6
View File
@@ -1176,4 +1176,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "Eliminar"),
("Filter by path", "Filtrar por ruta"),
("Hide non-applicable folders", "Ocultar carpetas no aplicables"),
("Thumbnail size", "Tamaño de miniatura"),
("Small", "Pequeño"),
("Medium", "Mediano"),
("Large", "Grande"),
("List", "Lista"),
("Procedurals", "Procedurales"),
];
+6
View File
@@ -1200,4 +1200,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "Supprimer"),
("Filter by path", "Filtrer par chemin"),
("Hide non-applicable folders", "Masquer les dossiers non applicables"),
("Thumbnail size", "Taille des miniatures"),
("Small", "Petit"),
("Medium", "Moyen"),
("Large", "Grand"),
("List", "Liste"),
("Procedurals", "Procéduraux"),
];
+6
View File
@@ -1182,4 +1182,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "Elimina"),
("Filter by path", "Filtra per percorso"),
("Hide non-applicable folders", "Nascondi le cartelle non pertinenti"),
("Thumbnail size", "Dimensione miniature"),
("Small", "Piccolo"),
("Medium", "Medio"),
("Large", "Grande"),
("List", "Elenco"),
("Procedurals", "Procedurali"),
];
+6
View File
@@ -1167,4 +1167,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "削除"),
("Filter by path", "パスで絞り込む"),
("Hide non-applicable folders", "該当しないフォルダーを隠す"),
("Thumbnail size", "サムネイルのサイズ"),
("Small", "小"),
("Medium", "中"),
("Large", "大"),
("List", "リスト"),
("Procedurals", "プロシージャル"),
];
+6
View File
@@ -1152,4 +1152,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "삭제"),
("Filter by path", "경로별 필터"),
("Hide non-applicable folders", "해당 없는 폴더 숨기기"),
("Thumbnail size", "썸네일 크기"),
("Small", "작게"),
("Medium", "보통"),
("Large", "크게"),
("List", "목록"),
("Procedurals", "프로시저럴"),
];
+6
View File
@@ -1170,4 +1170,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "Excluir"),
("Filter by path", "Filtrar por caminho"),
("Hide non-applicable folders", "Ocultar pastas não aplicáveis"),
("Thumbnail size", "Tamanho da miniatura"),
("Small", "Pequeno"),
("Medium", "Médio"),
("Large", "Grande"),
("List", "Lista"),
("Procedurals", "Procedurais"),
];
+6
View File
@@ -1095,4 +1095,10 @@ pub const TABLE: &[(&str, &str)] = &[
("Delete", "删除"),
("Filter by path", "按路径筛选"),
("Hide non-applicable folders", "隐藏不适用的文件夹"),
("Thumbnail size", "缩略图大小"),
("Small", "小"),
("Medium", "中"),
("Large", "大"),
("List", "列表"),
("Procedurals", "程序纹理"),
];
+2
View File
@@ -23,6 +23,7 @@ pub mod file_dialogs;
mod filter_slot;
pub mod fonts;
pub mod gpu;
mod grid_tile;
pub mod i18n;
pub mod id_color_pick;
pub mod keymap;
@@ -56,6 +57,7 @@ pub mod shelf_panes;
pub mod shelf_preview;
mod shelf_tabs;
mod shelf_toolbar;
pub mod shelf_view;
mod soft_box;
pub mod state;
pub mod symmetry;
+43 -30
View File
@@ -13,13 +13,12 @@ use crate::decal_drop::DecalDrop;
use crate::i18n::{tr, trf};
use crate::shelf_entry::ShelfEntry;
use crate::shelf_preview::ShelfPreview;
use crate::shelf_view::ShelfView;
use crate::theme::Tokens;
use crate::thumbs::Thumbs;
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;
const TILE_HEIGHT: f32 = 76.0;
/// The gap between tiles in points (their sizes are [`ShelfView`]'s)
const TILE_GAP: f32 = 2.0;
/// Corner radius of a tile's hover and selection highlights, in points
const TILE_ROUNDING: f32 = 3.0;
@@ -36,9 +35,6 @@ const BADGE_INSET: f32 = 2.5;
const BADGE_DOT_FILL: Color32 = Color32::from_gray(205);
const BADGE_DOT_RIM: f32 = 0.8;
const BADGE_DOT_RIM_COLOR: Color32 = Color32::from_black_alpha(170);
/// The thumbnail's size in a tile and its center below the tile's top, in points
const THUMBNAIL_SIZE: f32 = 60.0;
const THUMBNAIL_CENTER_Y: f32 = 31.0;
/// Loading icon size relative to the thumbnail width, and its opacity over the dim text color
const LOADING_ICON_SCALE: f32 = 0.9;
const LOADING_ICON_OPACITY: f32 = 0.5;
@@ -245,7 +241,7 @@ pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
crate::shelf_folders::breadcrumb(app, ui, &paths);
search_field(app, ui);
crate::shelf_tabs::row(app, ui, &counts, |_, _, _| {});
crate::shelf_tabs::row(app, ui, &counts, crate::shelf_view::menu);
ui.add_space(4.0);
let tab = app.ui.shelf_tab;
@@ -277,6 +273,7 @@ pub fn body(app: &mut TextureCraftApp, ui: &mut Ui) {
/// The tiles of `entries` in a scroll area `height` high, then the saved smart materials when `saved_materials`
fn grid(app: &mut TextureCraftApp, ui: &mut Ui, ctx: &egui::Context, entries: &[ShelfEntry], height: f32, saved_materials: bool, filter: &str) {
let view = app.ui.shelf_view;
egui::ScrollArea::vertical()
.id_salt("shelf_scroll")
.auto_shrink([false, false])
@@ -285,7 +282,7 @@ fn grid(app: &mut TextureCraftApp, ui: &mut Ui, ctx: &egui::Context, entries: &[
.show(ui, |ui| {
tiles(ui, |ui| {
for entry in entries {
entry_tile(app, ui, ctx, entry);
entry_tile(app, ui, ctx, entry, view);
}
});
if saved_materials {
@@ -418,12 +415,13 @@ fn scan_brushes(app: &mut TextureCraftApp) {
fn scan_brushes(_: &mut TextureCraftApp) {}
/// The tile of `entry`: a click applies it, an image resource has a context menu
fn entry_tile(app: &mut TextureCraftApp, ui: &mut Ui, ctx: &egui::Context, entry: &ShelfEntry) {
fn entry_tile(app: &mut TextureCraftApp, ui: &mut Ui, ctx: &egui::Context, entry: &ShelfEntry, view: ShelfView) {
// An image removed this frame has nothing to show
let (Some(preview), texture) = (entry.preview(app), entry.thumbnail(app, ctx)) else { return };
let asset = entry.asset();
let response = tile(ui, &mut app.thumbs, texture.as_ref(), || preview, entry.label(), asset.as_ref());
let response = tile_in_view(ui, &mut app.thumbs, texture.as_ref(), || preview, entry.label(), asset.as_ref(), view);
let selected_id = egui::Id::unique(SELECTED_TILE);
let key = entry.key();
let selected = ctx.data(|data| data.get_temp::<String>(selected_id)).is_some_and(|selected| selected == key);
@@ -434,7 +432,7 @@ fn entry_tile(app: &mut TextureCraftApp, ui: &mut Ui, ctx: &egui::Context, entry
}
if entry.includes_randomness() {
randomness_badge(ui.painter(), response.rect);
randomness_badge(ui.painter(), view.thumbnail_rect(response.rect));
}
if response.clicked() || response.secondary_clicked() {
@@ -458,46 +456,61 @@ fn entry_tile(app: &mut TextureCraftApp, ui: &mut Ui, ctx: &egui::Context, entry
}
}
/// Asset tile with optional dragging and a larger hover preview
/// Asset tile with optional dragging and a larger hover preview, at the medium size
pub(crate) fn tile(
ui: &mut Ui,
thumbs: &mut Thumbs,
tex: Option<&egui::TextureHandle>,
texture: Option<&egui::TextureHandle>,
preview: impl FnOnce() -> ShelfPreview,
label: &str,
drag: Option<&Asset>,
) -> egui::Response {
tile_in_view(ui, thumbs, texture, preview, label, drag, ShelfView::Medium)
}
/// [`tile`] at `view`'s size: a grid tile with the name under the thumbnail, or a list row with it beside
fn tile_in_view(
ui: &mut Ui,
thumbs: &mut Thumbs,
texture: Option<&egui::TextureHandle>,
preview: impl FnOnce() -> ShelfPreview,
label: &str,
drag: Option<&Asset>,
view: ShelfView,
) -> egui::Response {
let tk = Tokens::get(ui.ctx());
let sense = if drag.is_some() { Sense::click_and_drag() } else { Sense::click() };
let (rect, resp) = ui.allocate_exact_size(vec2(TILE_WIDTH, TILE_HEIGHT), sense);
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, label));
let (rect, response) = ui.allocate_exact_size(view.tile_size(ui.available_width()), sense);
response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, label));
if let Some(asset) = drag
&& resp.drag_started()
&& response.drag_started()
{
resp.dnd_set_drag_payload(ShelfDrag { asset: asset.clone(), label: label.to_string() });
response.dnd_set_drag_payload(ShelfDrag { asset: asset.clone(), label: label.to_string() });
}
let painter = ui.painter();
if resp.hovered() || resp.dragged() {
if response.hovered() || response.dragged() {
painter.rect_filled(rect, TILE_ROUNDING, tk.row_hover);
}
let image_rect = thumbnail_rect(rect);
thumbnail(painter, tex, image_rect, &tk);
let galley = painter.layout_job(one_line(label, rect.width() - LABEL_MARGIN, tk.text));
painter.galley(egui::pos2(rect.center().x - galley.size().x * 0.5, image_rect.bottom() + LABEL_GAP), galley, tk.text);
let big = if resp.hovered() { big_preview(ui, thumbs, preview) } else { None };
resp.on_hover_ui(|ui| hover_preview(ui, tex, big.as_ref(), label))
}
let image_rect = view.thumbnail_rect(rect);
thumbnail(painter, texture, image_rect, &tk);
if view.name_beside() {
let left = image_rect.right() + crate::shelf_view::LIST_NAME_GAP;
let galley = painter.layout_job(one_line(label, rect.right() - left - LABEL_MARGIN, tk.text));
painter.galley(egui::pos2(left, rect.center().y - galley.size().y * 0.5), galley, tk.text);
} else {
let galley = painter.layout_job(one_line(label, rect.width() - LABEL_MARGIN, tk.text));
painter.galley(egui::pos2(rect.center().x - galley.size().x * 0.5, image_rect.bottom() + LABEL_GAP), galley, tk.text);
}
/// Where a tile's thumbnail goes in the tile's `rect`
fn thumbnail_rect(rect: egui::Rect) -> egui::Rect {
egui::Rect::from_center_size(rect.center_top() + vec2(0.0, THUMBNAIL_CENTER_Y), vec2(THUMBNAIL_SIZE, THUMBNAIL_SIZE))
let big = if response.hovered() { big_preview(ui, thumbs, preview) } else { None };
response.on_hover_ui(|ui| hover_preview(ui, texture, big.as_ref(), label))
}
/// Three light, dark-rimmed dots at the thumbnail's bottom-right corner: the asset includes randomness
fn randomness_badge(painter: &egui::Painter, tile: egui::Rect) {
let corner = thumbnail_rect(tile).right_bottom() - vec2(BADGE_INSET, BADGE_INSET);
fn randomness_badge(painter: &egui::Painter, thumbnail: egui::Rect) {
let corner = thumbnail.right_bottom() - vec2(BADGE_INSET, BADGE_INSET);
for offset in [vec2(0.0, 0.0), vec2(-BADGE_DOT_SPACING, 0.0), vec2(-BADGE_DOT_SPACING * 0.5, -BADGE_DOT_SPACING)] {
painter.circle(corner + offset, BADGE_DOT_RADIUS, BADGE_DOT_FILL, Stroke::new(BADGE_DOT_RIM, BADGE_DOT_RIM_COLOR));
}
+83
View File
@@ -0,0 +1,83 @@
//! How the shelf shows its assets: small, medium or large tiles, or a list (the menu at the type row's end)
use egui::{Rect, Ui, Vec2, vec2};
use egui_phosphor::regular as ic;
use serde::{Deserialize, Serialize};
use crate::TextureCraftApp;
use crate::grid_tile::GridTile;
use crate::i18n::tr;
use crate::widgets::icon_button;
/// A list row's height and its thumbnail's size, in points
const LIST_ROW_HEIGHT: f32 = 30.0;
const LIST_THUMBNAIL_SIZE: f32 = 26.0;
/// The gap between a list row's thumbnail and its name, in points
pub(crate) const LIST_NAME_GAP: f32 = 6.0;
/// The shelf's tile size, or the list
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum ShelfView {
Small,
/// A 68 x 78 grid step, as in the reference
#[default]
Medium,
Large,
List,
}
/// The views in the menu's order: icon and (English, translated where shown) name
const VIEWS: [(ShelfView, &str, &str); 4] = [
(ShelfView::Small, ic::GRID_NINE, "Small"),
(ShelfView::Medium, ic::GRID_FOUR, "Medium"),
(ShelfView::Large, ic::SQUARE, "Large"),
(ShelfView::List, ic::LIST, "List"),
];
impl ShelfView {
/// A grid tile's measurements; None for the list
fn grid(self) -> Option<GridTile> {
match self {
ShelfView::Small => Some(GridTile { width: 50.0, height: 58.0, thumbnail_size: 44.0, thumbnail_center_y: 23.0 }),
ShelfView::Medium => Some(GridTile { width: 66.0, height: 76.0, thumbnail_size: 60.0, thumbnail_center_y: 31.0 }),
ShelfView::Large => Some(GridTile { width: 88.0, height: 100.0, thumbnail_size: 82.0, thumbnail_center_y: 42.0 }),
ShelfView::List => None,
}
}
/// A tile's size in a grid `width` points wide (a list row spans it)
pub(crate) fn tile_size(self, width: f32) -> Vec2 {
match self.grid() {
Some(tile) => vec2(tile.width, tile.height),
None => vec2(width.max(LIST_ROW_HEIGHT), LIST_ROW_HEIGHT),
}
}
/// Where the thumbnail goes in the tile `rect`
pub(crate) fn thumbnail_rect(self, rect: Rect) -> Rect {
match self.grid() {
Some(tile) => Rect::from_center_size(rect.center_top() + vec2(0.0, tile.thumbnail_center_y), vec2(tile.thumbnail_size, tile.thumbnail_size)),
None => Rect::from_center_size(rect.left_center() + vec2(LIST_ROW_HEIGHT * 0.5, 0.0), vec2(LIST_THUMBNAIL_SIZE, LIST_THUMBNAIL_SIZE)),
}
}
/// Whether the name sits right of the thumbnail (a list) rather than under it
pub(crate) fn name_beside(self) -> bool {
self == ShelfView::List
}
}
/// The view menu button: its icon is the current view's
pub(crate) fn menu(app: &mut TextureCraftApp, ui: &mut Ui, size: f32) {
let current = app.ui.shelf_view;
let icon = VIEWS.iter().find(|(view, _, _)| *view == current).map_or(ic::GRID_FOUR, |(_, icon, _)| icon);
let response = icon_button(ui, icon, tr("Thumbnail size"), false, size);
egui::Popup::menu(&response).show(|ui| {
for (view, icon, label) in VIEWS {
if ui.selectable_label(view == current, format!("{icon} {}", tr(label))).clicked() {
app.ui.shelf_view = view;
ui.close();
}
}
});
}
+5
View File
@@ -7,6 +7,7 @@ use crate::docking::Dock;
use crate::keymap::Keymap;
use crate::saved_search::SavedSearch;
use crate::shelf_panes::ShelfPanes;
use crate::shelf_view::ShelfView;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum Mode {
@@ -305,6 +306,9 @@ pub struct UiState {
/// The asset shelf's library folder: a library id, then folder names (empty: all libraries)
#[serde(default)]
pub shelf_path: Vec<String>,
/// The asset shelf's tile size, or its list
#[serde(default)]
pub shelf_view: ShelfView,
/// The asset shelf's open side panes
#[serde(default)]
pub shelf_panes: ShelfPanes,
@@ -406,6 +410,7 @@ impl Default for UiState {
shelf_filter: String::new(),
shelf_tab: 0,
shelf_path: Vec::new(),
shelf_view: ShelfView::default(),
shelf_panes: ShelfPanes::default(),
shelf_saved_searches: Vec::new(),
props_tab: PropsTab::Brush,