Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Render library: Appearances card with a sphere grid, scopes, favourites and recents (#6429)

Nathan Dane2897d3b22ebe
diff --git a/assets/locales/pending/render-library-grid.json b/assets/locales/pending/render-library-grid.json
new file mode 100644
index 0000000000..ba8a374194
--- /dev/null
+++ b/assets/locales/pending/render-library-grid.json
@@ -0,0 +1,236 @@
+{
+ "en": {
+ "render.appearances": "Appearances",
+ "render.category_metal": "Metal",
+ "render.category_paint": "Paint",
+ "render.category_plastic": "Plastic",
+ "render.category_wood": "Wood",
+ "render.environment_tiles_require_raytrace": "Environments require CPU or GPU ray tracing. Select it in the Output editor.",
+ "render.frame_presets": "Frame presets",
+ "render.frame_presets_pending": "Arrives with the Shot editor",
+ "render.library_appearance_available": "Available appearance",
+ "render.library_applicable": "Applicable resources",
+ "render.library_apply_appearance": "Apply appearance",
+ "render.library_apply_hint": "Click to apply · drag onto the model",
+ "render.library_filters": "Catalog and availability",
+ "render.library_grid": "Grid",
+ "render.library_in_design": "In Design",
+ "render.library_ior": "IOR",
+ "render.library_list": "List",
+ "render.library_metallic": "Metallic",
+ "render.library_opacity": "Opacity",
+ "render.library_other": "Other appearances",
+ "render.library_roughness": "Roughness",
+ "render.library_users": "Users",
+ "render.search_appearances": "Search {count} appearances",
+ "render.size_presets": "Size presets",
+ "render.size_presets_pending": "Arrives with the Output editor",
+ "render.studio_tiles_require_gpu": "Studios require GPU path tracing. Select GPU in the Output editor.",
+ "render.studios_environments": "Studios and Environments"
+ },
+ "de": {
+ "render.appearances": "Erscheinungsbilder",
+ "render.category_metal": "Metall",
+ "render.category_paint": "Lack",
+ "render.category_plastic": "Kunststoff",
+ "render.category_wood": "Holz",
+ "render.environment_tiles_require_raytrace": "Umgebungen benötigen CPU- oder GPU-Raytracing. Im Ausgabeeditor wählen.",
+ "render.frame_presets": "Bildvorlagen",
+ "render.frame_presets_pending": "Kommt mit dem Aufnahmeeditor",
+ "render.library_appearance_available": "Verfügbares Erscheinungsbild",
+ "render.library_applicable": "Passende Ressourcen",
+ "render.library_apply_appearance": "Erscheinungsbild anwenden",
+ "render.library_apply_hint": "Klicken zum Anwenden · auf das Modell ziehen",
+ "render.library_filters": "Katalog und Verfügbarkeit",
+ "render.library_grid": "Raster",
+ "render.library_in_design": "Im Design",
+ "render.library_inspect_only": "Zum Prüfen wählen · Im Inspektor anwenden",
+ "render.library_ior": "Brechungsindex",
+ "render.library_list": "Liste",
+ "render.library_metallic": "Metallisch",
+ "render.library_opacity": "Deckkraft",
+ "render.library_other": "Weitere Erscheinungsbilder",
+ "render.library_roughness": "Rauheit",
+ "render.library_users": "Verwendungen",
+ "render.search_appearances": "{count} Erscheinungsbilder durchsuchen",
+ "render.size_presets": "Größenvorlagen",
+ "render.size_presets_pending": "Kommt mit dem Ausgabeeditor",
+ "render.studio_tiles_require_gpu": "Studios benötigen GPU-Pfadverfolgung. Im Ausgabeeditor GPU wählen.",
+ "render.studios_environments": "Studios und Umgebungen"
+ },
+ "ja": {
+ "render.appearances": "外観",
+ "render.category_metal": "金属",
+ "render.category_paint": "塗装",
+ "render.category_plastic": "プラスチック",
+ "render.category_wood": "木材",
+ "render.environment_tiles_require_raytrace": "環境には CPU または GPU レイトレーシングが必要です。出力エディターで選択してください。",
+ "render.frame_presets": "構図プリセット",
+ "render.frame_presets_pending": "ショットエディターとともに追加予定",
+ "render.library_appearance_available": "利用可能な外観",
+ "render.library_applicable": "適用に適したリソース",
+ "render.library_apply_appearance": "外観を適用",
+ "render.library_apply_hint": "クリックで適用 · モデルにドラッグ",
+ "render.library_filters": "カタログと利用状況",
+ "render.library_grid": "グリッド",
+ "render.library_in_design": "デザイン内",
+ "render.library_ior": "屈折率",
+ "render.library_list": "リスト",
+ "render.library_metallic": "金属度",
+ "render.library_opacity": "不透明度",
+ "render.library_other": "その他の外観",
+ "render.library_roughness": "粗さ",
+ "render.library_users": "使用箇所",
+ "render.search_appearances": "{count} 件の外観を検索",
+ "render.size_presets": "サイズプリセット",
+ "render.size_presets_pending": "出力エディターとともに追加予定",
+ "render.studio_tiles_require_gpu": "スタジオには GPU パストレーシングが必要です。出力エディターで GPU を選択してください。",
+ "render.studios_environments": "スタジオと環境"
+ },
+ "zh": {
+ "render.appearances": "外观",
+ "render.category_metal": "金属",
+ "render.category_paint": "涂漆",
+ "render.category_plastic": "塑料",
+ "render.category_wood": "木材",
+ "render.environment_tiles_require_raytrace": "环境需要 CPU 或 GPU 光线追踪。请在输出编辑器中选择。",
+ "render.frame_presets": "构图预设",
+ "render.frame_presets_pending": "随镜头编辑器推出",
+ "render.library_appearance_available": "可用外观",
+ "render.library_applicable": "适用资源",
+ "render.library_apply_appearance": "应用外观",
+ "render.library_apply_hint": "点击应用 · 拖到模型上",
+ "render.library_filters": "目录与可用性",
+ "render.library_grid": "网格",
+ "render.library_in_design": "设计中",
+ "render.library_ior": "折射率",
+ "render.library_list": "列表",
+ "render.library_metallic": "金属度",
+ "render.library_opacity": "不透明度",
+ "render.library_other": "其他外观",
+ "render.library_roughness": "粗糙度",
+ "render.library_users": "使用位置",
+ "render.search_appearances": "搜索 {count} 种外观",
+ "render.size_presets": "尺寸预设",
+ "render.size_presets_pending": "随输出编辑器推出",
+ "render.studio_tiles_require_gpu": "摄影棚需要 GPU 路径追踪。请在输出编辑器中选择 GPU。",
+ "render.studios_environments": "摄影棚和环境"
+ },
+ "ko": {
+ "render.appearances": "외관",
+ "render.category_metal": "금속",
+ "render.category_paint": "페인트",
+ "render.category_plastic": "플라스틱",
+ "render.category_wood": "목재",
+ "render.environment_tiles_require_raytrace": "환경에는 CPU 또는 GPU 광선 추적이 필요합니다. 출력 편집기에서 선택하세요.",
+ "render.frame_presets": "구도 프리셋",
+ "render.frame_presets_pending": "샷 편집기와 함께 제공 예정",
+ "render.library_appearance_available": "사용 가능한 외관",
+ "render.library_applicable": "적용 가능한 리소스",
+ "render.library_apply_appearance": "외관 적용",
+ "render.library_apply_hint": "클릭하여 적용 · 모델로 드래그",
+ "render.library_filters": "카탈로그 및 사용 가능 여부",
+ "render.library_grid": "격자",
+ "render.library_in_design": "디자인 내",
+ "render.library_inspect_only": "선택하여 확인 · 검사기에서 적용",
+ "render.library_ior": "굴절률",
+ "render.library_list": "목록",
+ "render.library_metallic": "금속성",
+ "render.library_opacity": "불투명도",
+ "render.library_other": "기타 외관",
+ "render.library_roughness": "거칠기",
+ "render.library_users": "사용 위치",
+ "render.search_appearances": "외관 {count}개 검색",
+ "render.size_presets": "크기 프리셋",
+ "render.size_presets_pending": "출력 편집기와 함께 제공 예정",
+ "render.studio_tiles_require_gpu": "스튜디오에는 GPU 경로 추적이 필요합니다. 출력 편집기에서 GPU를 선택하세요.",
+ "render.studios_environments": "스튜디오 및 환경"
+ },
+ "ar": {
+ "render.appearances": "المظاهر",
+ "render.category_metal": "معدن",
+ "render.category_paint": "طلاء",
+ "render.category_plastic": "بلاستيك",
+ "render.category_wood": "خشب",
+ "render.environment_tiles_require_raytrace": "تتطلب البيئات تتبّع الأشعة على المعالج أو بطاقة الرسومات. اخترْه في محرر المخرجات.",
+ "render.frame_presets": "إعدادات مسبقة للإطار",
+ "render.frame_presets_pending": "تصل مع محرر اللقطة",
+ "render.library_appearance_available": "مظهر متاح",
+ "render.library_applicable": "الموارد القابلة للتطبيق",
+ "render.library_apply_appearance": "تطبيق المظهر",
+ "render.library_apply_hint": "انقر للتطبيق · اسحب إلى النموذج",
+ "render.library_filters": "الفهرس والتوفر",
+ "render.library_grid": "شبكة",
+ "render.library_in_design": "في التصميم",
+ "render.library_ior": "معامل الانكسار",
+ "render.library_list": "قائمة",
+ "render.library_metallic": "معدنية",
+ "render.library_opacity": "العتامة",
+ "render.library_other": "مظاهر أخرى",
+ "render.library_roughness": "الخشونة",
+ "render.library_users": "المستخدمون",
+ "render.search_appearances": "ابحث في {count} مظهرًا",
+ "render.size_presets": "إعدادات الحجم المسبقة",
+ "render.size_presets_pending": "تصل مع محرر المخرجات",
+ "render.studio_tiles_require_gpu": "تتطلب الاستوديوهات تتبّع المسار على بطاقة الرسومات. اخترْ GPU في محرر المخرجات.",
+ "render.studios_environments": "الاستوديوهات والبيئات"
+ },
+ "he": {
+ "render.appearances": "מראות",
+ "render.category_metal": "מתכת",
+ "render.category_paint": "צבע",
+ "render.category_plastic": "פלסטיק",
+ "render.category_wood": "עץ",
+ "render.environment_tiles_require_raytrace": "סביבות דורשות מעקב קרניים במעבד או בכרטיס המסך. בחר זאת בעורך הפלט.",
+ "render.frame_presets": "הגדרות מסגרת מוכנות",
+ "render.frame_presets_pending": "יגיע עם עורך הצילום",
+ "render.library_appearance_available": "מראה זמין",
+ "render.library_applicable": "משאבים ישימים",
+ "render.library_apply_appearance": "החל מראה",
+ "render.library_apply_hint": "לחץ להחלה · גרור אל המודל",
+ "render.library_filters": "קטלוג וזמינות",
+ "render.library_grid": "רשת",
+ "render.library_in_design": "בתכנון",
+ "render.library_ior": "מקדם שבירה",
+ "render.library_list": "רשימה",
+ "render.library_metallic": "מתכתיות",
+ "render.library_opacity": "אטימות",
+ "render.library_other": "מראות אחרים",
+ "render.library_roughness": "חספוס",
+ "render.library_users": "משתמשים",
+ "render.search_appearances": "חפש בין {count} מראות",
+ "render.size_presets": "הגדרות גודל מוכנות",
+ "render.size_presets_pending": "יגיע עם עורך הפלט",
+ "render.studio_tiles_require_gpu": "סטודיו דורש מעקב נתיב במעבד הגרפי. בחר GPU בעורך הפלט.",
+ "render.studios_environments": "סטודיו וסביבות"
+ },
+ "vi": {
+ "render.appearances": "Diện mạo",
+ "render.category_metal": "Kim loại",
+ "render.category_paint": "Sơn",
+ "render.category_plastic": "Nhựa",
+ "render.category_wood": "Gỗ",
+ "render.environment_tiles_require_raytrace": "Môi trường cần dò tia trên CPU hoặc GPU. Chọn trong trình chỉnh Đầu ra.",
+ "render.frame_presets": "Khung đặt sẵn",
+ "render.frame_presets_pending": "Sẽ có cùng trình chỉnh cảnh chụp",
+ "render.library_appearance_available": "Diện mạo khả dụng",
+ "render.library_applicable": "Tài nguyên áp dụng được",
+ "render.library_apply_appearance": "Áp dụng diện mạo",
+ "render.library_apply_hint": "Bấm để áp dụng · kéo vào mô hình",
+ "render.library_filters": "Danh mục và tình trạng sẵn có",
+ "render.library_grid": "Lưới",
+ "render.library_in_design": "Trong thiết kế",
+ "render.library_ior": "Chiết suất",
+ "render.library_list": "Danh sách",
+ "render.library_metallic": "Độ kim loại",
+ "render.library_opacity": "Độ đục",
+ "render.library_other": "Diện mạo khác",
+ "render.library_roughness": "Độ nhám",
+ "render.library_users": "Người dùng",
+ "render.search_appearances": "Tìm trong {count} diện mạo",
+ "render.size_presets": "Cỡ đặt sẵn",
+ "render.size_presets_pending": "Sẽ có cùng trình chỉnh Đầu ra",
+ "render.studio_tiles_require_gpu": "Studio cần dò đường đi của tia bằng GPU. Chọn GPU trong trình chỉnh Đầu ra.",
+ "render.studios_environments": "Studio và môi trường"
+ }
+}
diff --git a/crates/ui-egui/src/browser.rs b/crates/ui-egui/src/browser.rs
index b49a587e02..474db59303 100644
--- a/crates/ui-egui/src/browser.rs
+++ b/crates/ui-egui/src/browser.rs
@@ -882,6 +882,7 @@ fn render_card(app: &mut SolveApp, ui: &mut egui::Ui, acts: &mut Actions) {
if narrow && !app.shell.render_browser_open {
app.shell.browser = None;
crate::shell::register_panel(app, "render:browser", None, None);
+ crate::shell::register_panel(app, "render:appearances", None, None);
crate::render_ui::dock_chip(app, ui, "render:browser:show", "ui.browser_title", "view.render_browser", json!({"open":true}));
return;
}
@@ -898,9 +899,11 @@ fn render_card(app: &mut SolveApp, ui: &mut egui::Ui, acts: &mut Actions) {
id: "render:browser",
title: &title,
icon: "list",
- bounds,
+ bounds: crate::ui_kit::Panel::stack_first_bounds(bounds),
fill_height: true,
compact: crate::render_ui::compact(app, bounds.width()),
+ enabled: true,
+ header_actions: None,
},
&mut side,
&mut width,
@@ -944,6 +947,9 @@ fn render_card(app: &mut SolveApp, ui: &mut egui::Ui, acts: &mut Actions) {
);
if let Some(rect) = rect {
crate::scenario::publish_rect("browser:card", rect);
+ crate::render_workspace::appearances_card(app, ui, crate::ui_kit::Panel::stack_next_bounds(bounds, rect));
+ } else {
+ crate::shell::register_panel(app, "render:appearances", None, None);
}
}
diff --git a/crates/ui-egui/src/colour_tokens_tests.rs b/crates/ui-egui/src/colour_tokens_tests.rs
index fe4343871b..0561d047ba 100644
--- a/crates/ui-egui/src/colour_tokens_tests.rs
+++ b/crates/ui-egui/src/colour_tokens_tests.rs
@@ -147,6 +147,8 @@ const ALLOWED_LITERALS: &[(&str, usize, &str)] = &[
("dialogs_appearance.rs", 1, "a design appearance: the colour is the fact"),
("dialogs_save_mesh.rs", 1, "an installed slicer's own icon, drawn untinted"),
("dialogs_library.rs", 1, "a library appearance's swatch: the colour is the fact"),
+ ("render_ui/scene.rs", 2, "Browser appearance swatches: the colours are document data"),
+ ("render_workspace_library.rs", 1, "a catalog appearance preview: the colour is authored data"),
("render_workspace_materials.rs", 1, "an authored material swatch: the displayed colour is the material data"),
("dialogs_assembly.rs", 1, "the interference fill, shaded from its token"),
("dialogs_motion.rs", 1, "a white outline"),
diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs
index b44168d29b..7d2a5b5b49 100644
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@ -710,6 +710,17 @@ mod tests {
"render.tree_browser",
"render.tree_search",
"render.tree_more",
+ "render.studios_environments",
+ "render.frame_presets",
+ "render.size_presets",
+ "render.frame_presets_pending",
+ "render.size_presets_pending",
+ "render.search_appearances",
+ "render.library_applicable",
+ "render.library_other",
+ "render.library_apply_hint",
+ "render.studio_tiles_require_gpu",
+ "render.environment_tiles_require_raytrace",
] {
assert_ne!(locale.text(id), Locale::for_language("en").text(id), "{language}: {id}");
}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index c1775c199f..f43e7b14ae 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -2342,6 +2342,7 @@ impl SolveApp {
if !self.ui.show_browser || render_ui::focused(self) {
self.shell.browser = None;
shell::register_panel(self, "render:browser", None, None);
+ shell::register_panel(self, "render:appearances", None, None);
}
if floating || left_timeline || !show_timeline {
self.shell.history = None;
diff --git a/crates/ui-egui/src/prefs.rs b/crates/ui-egui/src/prefs.rs
index a340f0d893..3180d7c223 100644
--- a/crates/ui-egui/src/prefs.rs
+++ b/crates/ui-egui/src/prefs.rs
@@ -881,6 +881,9 @@ preference_settings! {
render_inspector_width: f32 = 305.0;
render_browser_side: String = "left".into();
render_browser_width: f32 = 266.0;
+ /// Resource identities and history belong to the user, never the design.
+ render_library_favorites: std::collections::BTreeSet<(String, String)> = Default::default();
+ render_library_recent: std::collections::VecDeque<(String, String)> = Default::default();
/// Draw the parts browser on a translucent card over the 3D view instead of a column of its
/// own, so the workspace keeps the whole window width.
browser_float: bool = false, PAGE_INTERFACE;
@@ -2670,6 +2673,9 @@ pub fn migrate(mut p: Prefs) -> Prefs {
if p.agent_chat_turn_limit == crate::agent_chat::gate::OLD_DEFAULT_TURN_LIMIT {
p.agent_chat_turn_limit = 0;
}
+ let valid_resource = |(kind, id): &(String, String)| !kind.is_empty() && kind.len() <= 64 && !id.is_empty() && id.len() <= 4096;
+ p.render_library_favorites = p.render_library_favorites.into_iter().filter(valid_resource).take(256).collect();
+ p.render_library_recent = p.render_library_recent.into_iter().filter(valid_resource).take(32).collect();
if p.orbit_cursor {
p.orbit_around = OrbitAround::Cursor;
p.orbit_cursor = false;
diff --git a/crates/ui-egui/src/render_workspace.rs b/crates/ui-egui/src/render_workspace.rs
index 49facceb7e..f6f5c4f0e7 100644
--- a/crates/ui-egui/src/render_workspace.rs
+++ b/crates/ui-egui/src/render_workspace.rs
@@ -625,11 +625,9 @@ pub(crate) fn apply_browser_controls(app: &mut SolveApp, value: &serde_json::Val
let view = &mut app.render_workspace.view;
if let Some(by_look) = value.get("by_look").and_then(serde_json::Value::as_bool) {
view.by_look = by_look;
- view.inspector.library_open = false;
}
if let Some(search) = value.get("search").and_then(serde_json::Value::as_bool) {
view.search_objects = search;
- view.inspector.library_open = false;
}
if let Some(query) = value.get("query").and_then(serde_json::Value::as_str) {
view.object_query = query.into();
@@ -649,12 +647,12 @@ pub(crate) fn browser_mode(app: &mut SolveApp, ui: &mut egui::Ui) -> bool {
}
});
}
- if app.render_workspace.view.inspector.library_open {
- crate::ui_kit::scope(ui, |ui| library::browse(app, ui));
- true
- } else {
- false
- }
+ false
+}
+
+/// Per-stage companion sharing the Browser's dock policy.
+pub(crate) fn appearances_card(app: &mut SolveApp, ui: &mut egui::Ui, bounds: egui::Rect) {
+ library::card(app, ui, bounds);
}
fn image_host(app: &SolveApp, method: ImageMethod) -> Result<&ImageHost, String> {
diff --git a/crates/ui-egui/src/render_workspace_inspector.rs b/crates/ui-egui/src/render_workspace_inspector.rs
index cd7f87be45..a29aa4fc17 100644
--- a/crates/ui-egui/src/render_workspace_inspector.rs
+++ b/crates/ui-egui/src/render_workspace_inspector.rs
@@ -86,7 +86,6 @@ pub(super) struct View {
pub effects: super::effects::View,
pub page: Page,
reveal: Option<&'static str>,
- pub library_open: bool,
pending: Option<Pending>,
shot_name: String,
scene_review: Option<Review>,
@@ -192,7 +191,6 @@ impl Default for View {
effects: Default::default(),
page: Page::Scene,
reveal: None,
- library_open: false,
pending: None,
shot_name: String::new(),
scene_review: None,
@@ -234,6 +232,8 @@ pub(super) fn panel(app: &mut SolveApp, ui: &mut egui::Ui) {
bounds,
fill_height: true,
compact: crate::render_ui::compact(app, bounds.width()),
+ enabled: true,
+ header_actions: None,
},
&mut side,
&mut width,
diff --git a/crates/ui-egui/src/render_workspace_library.rs b/crates/ui-egui/src/render_workspace_library.rs
index 2e6064a95a..cc4c5bd4e6 100644
--- a/crates/ui-egui/src/render_workspace_library.rs
+++ b/crates/ui-egui/src/render_workspace_library.rs
@@ -5,7 +5,7 @@ use crate::{SolveApp, theme::Tokens, ui_kit};
use serde_json::{Value, json};
use solidcraft_engine::{doc::Document, geom::Vec3};
use std::{
- collections::{BTreeMap, BTreeSet, VecDeque},
+ collections::BTreeMap,
sync::{Arc, Weak},
};
@@ -39,8 +39,10 @@ pub(super) struct View {
collection: usize,
collection_query: String,
navigation: BTreeMap<String, Navigation>,
- favorites: BTreeSet<(String, String)>,
- recent: VecDeque<(String, String)>,
+ category: String,
+ layout: usize,
+ revision: Option<u64>,
+ document: Option<Weak<Document>>,
labels: BTreeMap<(String, String), String>,
statuses: BTreeMap<(String, String), String>,
preview: Option<SourcePreview>,
@@ -70,7 +72,7 @@ impl std::fmt::Debug for SourcePreview {
impl Default for View {
fn default() -> Self {
Self {
- kind: "surfaces".into(),
+ kind: "appearances".into(),
query: String::new(),
entries: Vec::new(),
selected: None,
@@ -98,8 +100,10 @@ impl Default for View {
collection: 0,
collection_query: String::new(),
navigation: Default::default(),
- favorites: Default::default(),
- recent: Default::default(),
+ category: String::new(),
+ layout: 0,
+ revision: None,
+ document: None,
labels: Default::default(),
statuses: Default::default(),
preview: None,
@@ -111,10 +115,46 @@ impl Default for View {
}
fn refresh(app: &mut SolveApp, view: &mut View) -> Result<(), String> {
- let reply = app.run("render.library.list", json!({"kind":view.kind,"query":view.query,"offset":view.offset,"limit":48,"availability":if view.kind=="physical_profiles" {"all"} else {&view.availability}}))?;
- view.entries = reply["items"].as_array().cloned().ok_or_else(|| crate::i18n::tr("render.error_library_reply").to_string())?;
- view.total = reply["total"].as_u64().and_then(|n| usize::try_from(n).ok()).unwrap_or(0);
- view.next = reply["next_offset"].as_u64().and_then(|n| usize::try_from(n).ok());
+ if matches!(view.collection, 1 | 2) {
+ let keys: Vec<_> = if view.collection == 1 {
+ app.preferences.render_library_favorites.iter().take(256).cloned().collect()
+ } else {
+ app.preferences.render_library_recent.iter().take(32).cloned().collect()
+ };
+ view.entries = keys
+ .into_iter()
+ .filter_map(|(kind, id)| {
+ let detail = describe(app, &kind, &id).ok()?;
+ let mut entry = detail["resource"].clone();
+ entry["resource"] = detail["resource"].clone();
+ entry["projection"] = detail["projection"].clone();
+ entry["library_kind"] = json!(kind);
+ entry["catalog_identity"] = json!(id);
+ Some(entry)
+ })
+ .collect();
+ view.total = view.entries.len();
+ view.next = None;
+ } else if view.collection == 3 || view.kind == "appearances" {
+ let reply = app.run(if view.collection == 3 { "appearance.list" } else { "appearance.library" }, json!({}))?;
+ view.entries = reply[if view.collection == 3 { "in_design" } else { "appearances" }].as_array().cloned().unwrap_or_default();
+ view.total = view.entries.len();
+ view.next = None;
+ } else {
+ let reply = app.run("render.library.list", json!({"kind":view.kind,"query":view.query,"offset":view.offset,"limit":48,"availability":if view.kind=="physical_profiles" {"all"} else {&view.availability}}))?;
+ view.entries = reply["items"].as_array().cloned().ok_or_else(|| crate::i18n::tr("render.error_library_reply").to_string())?;
+ // Capture authored optical parameters once per page; selection remains read-only.
+ for entry in &mut view.entries {
+ if let Some(id) = entry["id"].as_str() {
+ let detail = app.run("render.library.describe", json!({"kind":view.kind,"id":id}))?;
+ entry["resource"] = detail["resource"].clone();
+ }
+ }
+ view.total = reply["total"].as_u64().and_then(|n| usize::try_from(n).ok()).unwrap_or(0);
+ view.next = reply["next_offset"].as_u64().and_then(|n| usize::try_from(n).ok());
+ }
+ view.revision = Some(app.session.revision);
+ view.document = Some(Arc::downgrade(&app.session.doc));
view.loaded = true;
// Search/page changes preserve the independently inspected resource.
view.acknowledge_projection = false;
@@ -184,6 +224,7 @@ fn patch(app: &SolveApp) -> Result<Value, String> {
}
const KINDS: &[(&str, &str)] = &[
+ ("appearances", "render.appearances"),
("native_scenes", "render.library_native_scenes"),
("surfaces", "render.library_surfaces"),
("hdr", "render.library_hdr"),
@@ -228,6 +269,7 @@ fn switch_kind(view: &mut View, kind: &str) {
view.availability = "all".into();
}
view.loaded = false;
+ view.category.clear();
view.preview = None;
view.preview_error = None;
view.physical_plan = None;
@@ -235,15 +277,19 @@ fn switch_kind(view: &mut View, kind: &str) {
view.physical_ack = false;
}
pub(super) fn open_category(app: &mut SolveApp, kind: &str) {
+ // Explicit catalog browsing retains read-only Inspector workflows on the library stage.
+ let page = app.render_workspace.view.inspector.page;
+ let _ = app.run("view.render_stage", json!({"stage":"look"}));
+ app.render_workspace.view.inspector.page = page;
switch_kind(&mut app.render_workspace.view.library, kind);
app.render_workspace.view.library.collection = 0;
- app.render_workspace.view.inspector.library_open = true;
app.ui.show_browser = true;
+ let _ = app.run("view.render_browser", json!({"open":true}));
app.tree.panel_collapsed = false;
}
fn choose(app: &mut SolveApp, view: &mut View, kind: &str, id: &str) -> Result<(), String> {
switch_kind(view, kind);
- let detail = app.run("render.library.describe", json!({"kind":kind,"id":id}))?;
+ let detail = describe(app, kind, id)?;
let display = detail["resource"]["name"].as_str().or_else(|| detail["resource"]["designation"].as_str()).unwrap_or(id).to_string();
let status = detail["projection"]["status"].as_str().unwrap_or("reference_only").to_string();
view.details = Some(detail);
@@ -255,13 +301,16 @@ fn choose(app: &mut SolveApp, view: &mut View, kind: &str, id: &str) -> Result<(
view.physical_plan = None;
app.render_workspace.view.inspector.clear_resource_reviews();
let key = (kind.to_string(), id.to_string());
- view.recent.retain(|old| old != &key);
- view.recent.push_front(key.clone());
- view.recent.truncate(32);
+ app.preferences.render_library_recent.retain(|old| old != &key);
+ app.preferences.render_library_recent.push_front(key.clone());
+ app.preferences.render_library_recent.truncate(32);
+ if matches!(view.collection, 1 | 2) {
+ view.loaded = false;
+ }
view.statuses.insert(key.clone(), status);
view.labels.insert(key, display);
- view.labels.retain(|key, _| view.favorites.contains(key) || view.recent.contains(key));
- view.statuses.retain(|key, _| view.favorites.contains(key) || view.recent.contains(key));
+ view.labels.retain(|key, _| app.preferences.render_library_favorites.contains(key) || app.preferences.render_library_recent.contains(key));
+ view.statuses.retain(|key, _| app.preferences.render_library_favorites.contains(key) || app.preferences.render_library_recent.contains(key));
app.render_workspace.view.inspector.page = match kind {
"native_scenes" | "scenes" | "selene_shots" => super::inspector::Page::Scene,
"hdr" | "environments" => super::inspector::Page::Environment,
@@ -273,162 +322,595 @@ fn choose(app: &mut SolveApp, view: &mut View, kind: &str, id: &str) -> Result<(
Ok(())
}
-/// The existing browser card owns layout and occlusion in both shell modes.
-pub(super) fn browse(app: &mut SolveApp, ui: &mut egui::Ui) {
- let mut view = std::mem::take(&mut app.render_workspace.view.library);
- let label = KINDS.iter().find(|(kind, _)| *kind == view.kind).map_or("", |(_, key)| app.tr(key)).to_string();
- let menu = ui_kit::dropdown_menu(ui, "render_library_kind", &label, |ui| {
- for &(kind, key) in KINDS {
- let r = ui_kit::list_picker(ui, kind, app.tr(key), view.kind == kind);
- crate::scenario::publish_handle(&format!("render:library-kind:{kind}"), r.rect.center());
- if r.clicked() {
- switch_kind(&mut view, kind);
- view.collection = 0;
- ui.close();
- }
+/// Resolve previews and Inspector metadata through the same public catalog commands.
+fn look_signature(entry: &Value) -> Value {
+ json!([entry["name"], entry["color"], entry["opacity"], entry["pbr"]])
+}
+fn appearance_id(entry: &Value) -> String {
+ entry["id"].as_str().map(str::to_owned).unwrap_or_else(|| look_signature(entry).to_string())
+}
+fn describe(app: &mut SolveApp, kind: &str, id: &str) -> Result<Value, String> {
+ if kind != "appearances" {
+ return app.run("render.library.describe", json!({"kind":kind,"id":id}));
+ }
+ for (command, field) in [("appearance.library", "appearances"), ("appearance.list", "in_design")] {
+ let reply = app.run(command, json!({}))?;
+ if let Some(resource) = reply[field].as_array().and_then(|items| items.iter().find(|item| appearance_id(item) == id)) {
+ return Ok(
+ json!({"resource":resource,"projection":{"status":if resource["available"] == false { "blocked" } else { "native_appearance" }}}),
+ );
}
+ }
+ // Custom looks carry their complete scalar definition in their preference key,
+ // so a favourite survives closing its originating design.
+ if let Ok(Value::Array(parts)) = serde_json::from_str::<Value>(id)
+ && parts.len() == 4
+ {
+ return Ok(
+ json!({"resource":{"name":parts.first(),"color":parts.get(1),"opacity":parts.get(2),"pbr":parts.get(3)},"projection":{"status":"native_appearance"}}),
+ );
+ }
+ Err("appearance is no longer available".into())
+}
+
+fn preview_parameters(entry: &Value) -> Value {
+ let source = entry.get("resource").unwrap_or(entry);
+ if let Some(parameters) = source.pointer("/baseline_projection/runtime_parameters") {
+ return parameters.clone();
+ }
+ if let (Some(low), Some(high)) = (source["base_linear_low"].as_array(), source["base_linear_high"].as_array()) {
+ let color: Vec<_> = low
+ .iter()
+ .zip(high)
+ .take(3)
+ .map(|(a, b)| {
+ let linear = ((a.as_f64().unwrap_or(0.0) + b.as_f64().unwrap_or(0.0)) * 0.5).clamp(0.0, 1.0);
+ let encoded = if linear <= 0.0031308 { linear * 12.92 } else { 1.055 * linear.powf(1.0 / 2.4) - 0.055 };
+ (encoded * 255.0).round() as u8
+ })
+ .collect();
+ return json!({"color":color,"opacity":1.0,"pbr":{"metallic":source["metallic"],"roughness":source["roughness"],"dielectric_ior":1.5}});
+ }
+ source.clone()
+}
+fn tile_sphere(entry: &Value) -> ui_kit::Sphere {
+ let p = preview_parameters(entry);
+ let color = crate::dialogs_appearance::parse_color(&p["color"]).map(|[r, g, b]| egui::Color32::from_rgb(r, g, b)).unwrap_or(Tokens::get().body);
+ let scalar = |key: &str, default: f64| p["pbr"][key].as_f64().filter(|v| v.is_finite()).unwrap_or(default).clamp(0.0, 1.0);
+ let opacity = p["opacity"].as_f64().filter(|v| v.is_finite()).unwrap_or(1.0).clamp(0.0, 1.0);
+ let kind = if opacity < 1.0 {
+ ui_kit::FinishKind::Glass
+ } else if scalar("metallic", if category(entry) == "metal" { 1.0 } else { 0.0 }) >= 0.5 {
+ ui_kit::FinishKind::Metal
+ } else if scalar("roughness", 0.5) <= 0.2 {
+ ui_kit::FinishKind::Gloss
+ } else if scalar("roughness", 0.5) >= 0.7 {
+ ui_kit::FinishKind::Matte
+ } else {
+ ui_kit::FinishKind::Satin
+ };
+ ui_kit::Sphere { color, kind, opacity: Some(opacity as f32) }
+}
+fn user_count(entry: &Value) -> usize {
+ ["bodies", "faces", "components"].iter().filter_map(|key| entry[*key].as_array()).map(Vec::len).fold(0, usize::saturating_add)
+}
+fn usage_for<'a>(entry: &Value, used: &'a [Value]) -> Option<&'a Value> {
+ let source = entry.get("resource").unwrap_or(entry);
+ let parameters = preview_parameters(entry);
+ let name = source["name"].as_str()?;
+ let name = if source.get("base_linear_low").is_some() || source.pointer("/baseline_projection/runtime_parameters").is_some() {
+ format!("{} {name}", entry["id"].as_str()?)
+ } else {
+ name.to_string()
+ };
+ let color = crate::dialogs_appearance::parse_color(&parameters["color"])?;
+ used.iter().find(|look| {
+ look["name"].as_str() == Some(&name)
+ && crate::dialogs_appearance::parse_color(&look["color"]) == Some(color)
+ && look["opacity"].as_f64() == parameters["opacity"].as_f64()
+ && ["metallic", "roughness", "dielectric_ior"].iter().all(|key| look["pbr"][*key].as_f64() == parameters["pbr"][*key].as_f64())
+ })
+}
+fn matches_entry(entry: &Value, query: &str, category: &str, availability: &str) -> bool {
+ let state = entry.pointer("/projection/status").and_then(Value::as_str).unwrap_or(if entry["available"] == false {
+ "blocked"
+ } else {
+ "native_appearance"
});
- crate::scenario::publish_target("render:library-category", menu.rect);
- let collection_labels =
- [app.tr("render.library_all").to_string(), app.tr("render.library_favorites").to_string(), app.tr("render.library_recent").to_string()];
- ui_kit::segmented(ui, &mut view.collection, &collection_labels.iter().map(String::as_str).collect::<Vec<_>>(), Default::default());
- let query = if view.collection == 0 { &mut view.query } else { &mut view.collection_query };
- let search = ui_kit::bounded_cell_editor(ui, ui.id().with("render_library_search"), query, app.tr("render.library_search"), false, 128);
- crate::scenario::publish_target("render:library-search", search.rect);
- let enter = search.has_focus() && ui.input(|input| input.key_pressed(egui::Key::Enter));
- ui.horizontal(|ui| {
- if (ui_kit::button(ui, app.tr("render.library_search"), ui_kit::Button::Normal).clicked() || enter) && view.collection == 0 {
- view.offset = 0;
- view.loaded = false;
- }
- if ui_kit::button(ui, app.tr("render.library_clear_search"), ui_kit::Button::Normal).clicked() {
- if view.collection == 0 {
- view.query.clear();
- view.offset = 0;
- view.loaded = false;
- } else {
- view.collection_query.clear();
+ let admitted = match availability {
+ "usable" => matches!(state, "native_appearance" | "native_composition" | "implemented_pending_batch_validation"),
+ "blocked" => state == "blocked",
+ "specification" => state == "specification_only",
+ _ => true,
+ };
+ let source = entry.get("resource").unwrap_or(entry);
+ let query = query.to_lowercase();
+ admitted
+ && (category.is_empty() || entry["category"].as_str() == Some(category))
+ && ["id", "name", "category", "family", "description", "domains", "process", "intended_use", "tags"]
+ .iter()
+ .filter_map(|field| source.get(*field))
+ .any(|field| field.to_string().to_lowercase().contains(&query))
+}
+
+pub(super) fn card(app: &mut SolveApp, ui: &mut egui::Ui, bounds: egui::Rect) {
+ let mut side = app.preferences.render_browser_side.clone();
+ let mut width = app.preferences.render_browser_width;
+ let stage = app.render_workspace.view.stage;
+ let title = app.tr(stage_title(stage)).to_string();
+ let mut layout = app.render_workspace.view.library.layout;
+ let mut actions = |ui: &mut egui::Ui| {
+ ui_kit::catalog_scope(ui, |ui| {
+ ui_kit::segmented_icons(
+ ui,
+ &mut layout,
+ &[
+ ui_kit::IconSegment { key: "render:library-grid", icon: "grid", tip: crate::i18n::tr("render.library_grid").into() },
+ ui_kit::IconSegment { key: "render:library-list", icon: "list", tip: crate::i18n::tr("render.library_list").into() },
+ ],
+ &[],
+ )
+ });
+ };
+ let response = ui_kit::Panel::workspace(
+ ui,
+ ui_kit::WorkspaceOptions {
+ id: "render:appearances",
+ title: &title,
+ icon: "",
+ bounds,
+ fill_height: true,
+ compact: crate::render_ui::compact(app, bounds.width()),
+ enabled: matches!(stage, super::Stage::Look | super::Stage::Light),
+ header_actions: (stage == super::Stage::Look).then_some(&mut actions as &mut dyn FnMut(&mut egui::Ui)),
+ },
+ &mut side,
+ &mut width,
+ |ui| match stage {
+ super::Stage::Look => ui_kit::catalog_scope(ui, |ui| browse_contents(app, ui, true)),
+ super::Stage::Light => light_panel(app, ui),
+ super::Stage::Frame | super::Stage::Output => {
+ let reason = app.tr(if stage == super::Stage::Frame { "render.frame_presets_pending" } else { "render.size_presets_pending" });
+ ui_kit::text(ui, reason, ui_kit::Text::Note("render:stage-presets-pending"));
+ }
+ },
+ );
+ app.render_workspace.view.library.layout = layout;
+ app.preferences.render_browser_width = width;
+ let requested =
+ response.as_ref().and_then(|r| r.inner.1).map(str::to_string).or_else(|| (app.preferences.render_browser_side != side).then(|| side.clone()));
+ if let Some(side) = requested {
+ let _ = app.run("view.render_dock", json!({"panel":"browser","side":side}));
+ }
+ crate::shell::register_panel(
+ app,
+ "render:appearances",
+ response.map(|r| r.response.rect),
+ if bounds.width() < 800.0 { None } else { Some(if side == "left" { ui_kit::Edge::Left } else { ui_kit::Edge::Right }) },
+ );
+}
+
+fn stage_title(stage: super::Stage) -> &'static str {
+ match stage {
+ super::Stage::Look => "render.appearances",
+ super::Stage::Light => "render.studios_environments",
+ super::Stage::Frame => "render.frame_presets",
+ super::Stage::Output => "render.size_presets",
+ }
+}
+
+fn light_panel(app: &mut SolveApp, ui: &mut egui::Ui) {
+ egui::ScrollArea::vertical().id_salt("render_light_resources").auto_shrink([false, false]).show(ui, |ui| {
+ for (kind, heading) in [("native_scenes", "render.library_native_scenes"), ("hdr", "render.library_hdr")] {
+ ui_kit::text(ui, app.tr(heading), ui_kit::Text::Inline);
+ let reply = match app.run("render.library.list", json!({"kind":kind,"limit":128})) {
+ Ok(reply) => reply,
+ Err(error) => {
+ app.set_status(error, true);
+ continue;
+ }
+ };
+ let entries = reply["items"].as_array().cloned().unwrap_or_default();
+ let ids: Vec<_> = entries.iter().map(|e| format!("render:light:{}", e["id"].as_str().unwrap_or(""))).collect();
+ let tiles: Vec<_> = entries
+ .iter()
+ .zip(&ids)
+ .map(|(entry, id)| ui_kit::SphereTile {
+ id,
+ name: entry["name"].as_str().unwrap_or(""),
+ sphere: ui_kit::Sphere { color: Tokens::get().body, kind: ui_kit::FinishKind::Metal, opacity: None },
+ selected: false,
+ users: 0,
+ tip: entry["name"].as_str().unwrap_or(""),
+ })
+ .collect();
+ let reason = light_reason(app, kind);
+ let grid = ui.add_enabled_ui(reason.is_none(), |ui| ui_kit::sphere_grid(ui, &tiles));
+ if let Some(reason) = reason {
+ grid.response.on_disabled_hover_text(reason);
+ }
+ if let Some(entry) = grid.inner.and_then(|index| entries.get(index))
+ && let Some(id) = entry["id"].as_str()
+ && let Err(error) = apply_light(app, kind, id)
+ {
+ app.set_status(error, true);
}
}
});
- if view.collection == 0 && view.kind != "physical_profiles" {
- let choices = [
- ("all", "render.library_all_states"),
- ("usable", "render.library_usable"),
- ("specification", "render.library_specs"),
- ("blocked", "render.library_blocked"),
- ];
- let label = choices.iter().find(|(id, _)| *id == view.availability).map_or("", |(_, key)| app.tr(key)).to_string();
- ui_kit::dropdown_menu(ui, "render_library_availability", &label, |ui| {
- for (id, key) in choices {
- if ui_kit::list_picker(ui, id, app.tr(key), view.availability == id).clicked() {
- view.availability = id.into();
- view.offset = 0;
- view.loaded = false;
- ui.close();
+}
+
+fn light_reason(app: &SolveApp, kind: &str) -> Option<String> {
+ if kind == "native_scenes" && app.render_workspace.view.method != ImageMethod::GpuRaytrace {
+ return Some(app.tr("render.studio_tiles_require_gpu").into());
+ }
+ if app.render_workspace.view.method == ImageMethod::Raster {
+ return Some(app.tr("render.environment_tiles_require_raytrace").into());
+ }
+ patch(app).err()
+}
+
+fn apply_light(app: &mut SolveApp, kind: &str, id: &str) -> Result<(), String> {
+ if let Some(reason) = light_reason(app, kind) {
+ return Err(reason);
+ }
+ let set = patch(app)?;
+ let name = app.render_workspace.view.name.clone();
+ let (command, request) = if kind == "native_scenes" {
+ (
+ "render.preset.apply",
+ json!({"id":id,"name":name,"set":set,"expected_revision":app.session.revision,
+ "replace_lighting_and_environment":true,"replace_stage":true}),
+ )
+ } else {
+ ("render.library.environment.apply", json!({"id":id,"name":name,"set":set,"replace_environment":true}))
+ };
+ app.run(command, request)?;
+ setups::load(app);
+ Ok(())
+}
+
+fn selected_looks(app: &mut SolveApp) -> Vec<Value> {
+ use solidcraft_engine::Sel;
+ let targets: Vec<_> = app
+ .session
+ .selection
+ .iter()
+ .filter_map(|sel| match sel {
+ Sel::Body { name } => Some(json!({"body":name})),
+ Sel::Face { body, index, .. } => Some(json!({"body":body,"face":index})),
+ Sel::Occurrence { path } => {
+ path.last().and_then(|id| app.session.doc.occurrences.iter().find(|o| o.id == *id)).map(|o| json!({"component":o.component}))
+ }
+ _ => None,
+ })
+ .collect();
+ targets
+ .into_iter()
+ .filter_map(|target| {
+ let chain = app.run("appearance.chain", json!({"target":target})).ok()?;
+ chain["steps"].as_array()?.iter().find(|s| s["step"] == chain["active"]).map(|s| s["look"].clone()).filter(|v| !v.is_null())
+ })
+ .collect()
+}
+
+fn category(entry: &Value) -> &'static str {
+ let source = entry.get("resource").unwrap_or(entry);
+ let label = source["category"].as_str().or_else(|| source["name"].as_str()).unwrap_or("").to_lowercase();
+ if label.contains("wood") {
+ "wood"
+ } else if label.contains("paint") || label.contains("coating") {
+ "paint"
+ } else if label.contains("plastic") || label.contains("abs") || label.contains("rubber") || label.contains("polymer") {
+ "plastic"
+ } else if ["metal", "alumin", "steel", "iron", "brass", "copper", "titanium", "chrome"].iter().any(|word| label.contains(word)) {
+ "metal"
+ } else {
+ "other"
+ }
+}
+
+fn applicable(entry: &Value, selected: &[Value], used: &[Value]) -> bool {
+ usage_for(entry, used).is_some()
+ || user_count(entry) > 0
+ || selected.iter().any(|look| {
+ let same_category = category(entry) != "other" && category(entry) == category(look);
+ same_category || tile_sphere(entry).kind == tile_sphere(look).kind
+ })
+}
+
+fn apply_look(app: &mut SolveApp, entry: &Value) -> Result<(), String> {
+ use solidcraft_engine::Sel;
+ let mut bodies = Vec::new();
+ let mut faces = Vec::new();
+ let mut components = Vec::new();
+ for sel in &app.session.selection {
+ match sel {
+ Sel::Body { name } => bodies.push(name.clone()),
+ Sel::Face { body, point, .. } => faces.push(json!({"body":body,"point":point})),
+ Sel::Occurrence { path } => {
+ if let Some(occurrence) = path.last().and_then(|id| app.session.doc.occurrences.iter().find(|o| o.id == *id)) {
+ components.push(occurrence.component.to_string());
}
}
- });
+ _ => {}
+ }
+ }
+ if bodies.is_empty() && faces.is_empty() && components.is_empty() {
+ return Ok(());
}
- if !view.loaded
+ let mut params = if let Some(id) = entry["id"].as_str() {
+ json!({"appearance":id})
+ } else {
+ json!({"name":entry["name"],"color":entry["color"],"opacity":entry["opacity"],"pbr":entry["pbr"]})
+ };
+ params["bodies"] = json!(bodies);
+ params["faces"] = json!(faces);
+ params["components"] = json!(components);
+ app.run("appearance.assign", params)?;
+ Ok(())
+}
+
+fn browse_contents(app: &mut SolveApp, ui: &mut egui::Ui, stage_card: bool) {
+ let mut view = std::mem::take(&mut app.render_workspace.view.library);
+ let t = Tokens::get();
+ let document_changed =
+ view.revision != Some(app.session.revision) || view.document.as_ref().is_none_or(|doc| !Weak::ptr_eq(doc, &Arc::downgrade(&app.session.doc)));
+ if (!view.loaded || document_changed)
&& let Err(error) = refresh(app, &mut view)
{
view.loaded = true;
app.set_status(error, true);
}
- let entries: Vec<(String, String, String, Value)> = if view.collection == 0 {
- view.entries
- .iter()
- .filter_map(|entry| {
- Some((
- view.kind.clone(),
- entry["id"].as_str()?.to_string(),
- entry["name"].as_str().unwrap_or("").to_string(),
- entry["projection"].clone(),
- ))
- })
- .collect()
- } else {
- let keys: Vec<_> = if view.collection == 1 { view.favorites.iter().cloned().collect() } else { view.recent.iter().cloned().collect() };
- keys.into_iter()
- .filter(|key| {
- format!("{} {} {}", key.0, key.1, view.labels.get(key).map(String::as_str).unwrap_or(""))
- .to_lowercase()
- .contains(&view.collection_query.to_lowercase())
- })
- .map(|key| {
- let label = view.labels.get(&key).cloned().unwrap_or_else(|| key.1.clone());
- let projection = json!({"status":view.statuses.get(&key).map(String::as_str).unwrap_or("reference_only")});
- (key.0, key.1, label, projection)
- })
- .collect()
+ let hint = crate::i18n::format("render.search_appearances", &[("count", &view.total.to_string())]);
+ let query = if view.collection == 0 { &mut view.query } else { &mut view.collection_query };
+ let search = ui_kit::search_field(ui, ui.id().with("render_library_search"), query, &hint);
+ query.truncate(query.char_indices().nth(128).map_or(query.len(), |(at, _)| at));
+ crate::scenario::publish_target("render:library-search", search.rect);
+ if search.changed() {
+ view.offset = 0;
+ view.loaded = false;
+ }
+ let labels = [
+ app.tr("render.library_in_design").to_string(),
+ app.tr("render.browser_library").to_string(),
+ app.tr("render.library_recent").to_string(),
+ "★".to_string(),
+ ];
+ let mut scope = match view.collection {
+ 3 => 0,
+ 0 => 1,
+ 2 => 2,
+ _ => 3,
};
- ui.small(format!("{}: {}", app.tr("render.library_results"), if view.collection == 0 { view.total } else { entries.len() }));
- if entries.is_empty() {
- ui_kit::text(ui, app.tr("render.library_empty"), ui_kit::Text::Note("render.library_empty"));
+ if ui_kit::segmented(
+ ui,
+ &mut scope,
+ &labels.iter().map(String::as_str).collect::<Vec<_>>(),
+ ui_kit::Segments {
+ compact: true,
+ proportional: true,
+ workspace_accent: true,
+ targets: &[
+ "render:library-scope:in-design",
+ "render:library-scope:library",
+ "render:library-scope:recent",
+ "render:library-scope:favorites",
+ ],
+ ..Default::default()
+ },
+ ) {
+ view.collection = [3, 0, 2, 1].get(scope).copied().unwrap_or(0);
+ view.loaded = false;
+ view.offset = 0;
+ view.category.clear();
}
+ let document_changed =
+ view.revision != Some(app.session.revision) || view.document.as_ref().is_none_or(|doc| !Weak::ptr_eq(doc, &Arc::downgrade(&app.session.doc)));
+ if (!view.loaded || document_changed)
+ && let Err(error) = refresh(app, &mut view)
+ {
+ view.loaded = true;
+ app.set_status(error, true);
+ }
+ let mut entries: Vec<(String, String, Value)> = view
+ .entries
+ .iter()
+ .map(|entry| {
+ let appearance = view.collection == 3 || view.kind == "appearances";
+ (
+ entry["library_kind"]
+ .as_str()
+ .map(str::to_owned)
+ .unwrap_or_else(|| if appearance { "appearances".into() } else { view.kind.clone() }),
+ entry["catalog_identity"]
+ .as_str()
+ .map(str::to_owned)
+ .unwrap_or_else(|| if appearance { appearance_id(entry) } else { entry["id"].as_str().unwrap_or("").to_string() }),
+ entry.clone(),
+ )
+ })
+ .collect();
+ egui::ScrollArea::horizontal().id_salt("render_library_chips").scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden).show(
+ ui,
+ |ui| {
+ ui.horizontal(|ui| {
+ for (id, label) in [
+ ("", "ui.all"),
+ ("metal", "render.category_metal"),
+ ("plastic", "render.category_plastic"),
+ ("paint", "render.category_paint"),
+ ("wood", "render.category_wood"),
+ ] {
+ if ui_kit::choice_chip(ui, &format!("render-library-{id}"), app.tr(label), view.category == id).clicked() {
+ view.category = id.into();
+ }
+ }
+ });
+ },
+ );
+ let query = if view.collection == 0 { &view.query } else { &view.collection_query };
+ entries.retain(|(_, _, entry)| {
+ matches_entry(entry, query, "", &view.availability) && (view.category.is_empty() || category(entry) == view.category)
+ });
+ let used = app.run("appearance.list", json!({})).ok().and_then(|reply| reply["in_design"].as_array().cloned()).unwrap_or_default();
+ let selected_looks = selected_looks(app);
+ entries.sort_by_key(|(_, _, entry)| !applicable(entry, &selected_looks, &used));
+ let applicable_count = entries.iter().take_while(|(_, _, entry)| applicable(entry, &selected_looks, &used)).count();
+ let tips: Vec<_> = entries
+ .iter()
+ .map(|(_, id, entry)| {
+ let p = preview_parameters(entry);
+ let usage = usage_for(entry, &used).unwrap_or(entry);
+ let users = user_count(usage);
+ let names: Vec<_> = ["bodies", "faces", "components"]
+ .iter()
+ .filter_map(|key| usage[*key].as_array())
+ .flatten()
+ .take(128)
+ .filter_map(|user| user.as_str().or_else(|| user["body"].as_str()))
+ .collect();
+ let scalar = |value: &Value| value.as_f64().map(|n| format!("{n:.2}")).unwrap_or_else(|| "—".into());
+ format!(
+ "{}\n{}\n{}: {} · {}: {}\n{}: {} · {}: {}\n{}: {} {}\n{}",
+ entry["name"].as_str().unwrap_or(id),
+ entry["category"].as_str().or_else(|| entry["family"].as_str()).unwrap_or(app.tr("render.library_in_design")),
+ app.tr("render.library_metallic"),
+ scalar(&p["pbr"]["metallic"]),
+ app.tr("render.library_roughness"),
+ scalar(&p["pbr"]["roughness"]),
+ app.tr("render.library_ior"),
+ scalar(&p["pbr"]["dielectric_ior"]),
+ app.tr("render.library_opacity"),
+ scalar(&p["opacity"]),
+ app.tr("render.library_users"),
+ users,
+ names.join(", "),
+ availability_label(
+ app,
+ entry.pointer("/projection/status").and_then(Value::as_str).or(Some(if entry["available"] == false {
+ "blocked"
+ } else {
+ "native_appearance"
+ }))
+ )
+ )
+ })
+ .collect();
+ let identities: Vec<_> = entries.iter().map(|(_, id, _)| format!("render:library:{id}")).collect();
+ let footer = t.control_height * if view.collection == 0 && view.kind != "appearances" { 3.0 } else { 1.0 };
+ let height = (ui.available_height() - footer).max(t.control_height);
let mut selected = None;
- let t = Tokens::get();
- let note_height = ui
- .painter()
- .layout(app.tr("render.library_inspect_only").to_string(), egui::FontId::proportional(t.font_small), t.form_dim, ui.available_width())
- .size()
- .y
- + t.space_8;
- let footer_height = note_height + if view.collection == 0 { t.control_height + t.form_gap_y } else { 0.0 };
- let height = (ui.available_height() - footer_height - t.space_10).max(t.control_height);
- let row_height = crate::ui_kit::row_height() + Tokens::get().space_10;
- egui::ScrollArea::vertical()
- .id_salt(("render_library_items", &view.kind, view.collection))
- .max_height(height)
- .auto_shrink([false, false])
- .show_rows(ui, row_height, entries.len(), |ui, range| {
- for index in range {
- let Some((kind, id, name, projection)) = entries.get(index) else { continue };
- let text = if name.is_empty() { id.as_str() } else { name.as_str() };
- let identity = format!("{kind}:{id}");
- // Reuse Nathan's two-line search/menu component, artwork and
- // accessibility metadata. A blocked resource remains inspectable.
- let icon = if matches!(kind.as_str(), "surfaces" | "materials" | "selene_appearances" | "physical_profiles") {
- "appearance"
- } else {
- "render_scene"
- };
- let mut item = ui_kit::MenuItem::new(&identity, text, icon);
- item.highlighted = view.kind == *kind && view.selected.as_ref() == Some(id);
- let path = format!("{id} / {}", short_availability(app, projection["status"].as_str()));
- let query = if view.collection == 0 { &view.query } else { &view.collection_query };
- let r = item.search_row(ui, query, &path, None);
- crate::scenario::publish_target(&format!("render:library:{id}"), r.rect);
- let selected_here = r.clicked();
- let _ = r.on_hover_text(format!(
- "{text}\n{id}\n{}\n{}",
- availability_label(app, projection["status"].as_str()),
- app.tr("render.library_inspect_only")
- ));
- if selected_here {
- selected = Some((kind.clone(), id.clone()));
+ egui::ScrollArea::vertical().id_salt(("render_library_items", &view.kind, view.collection)).max_height(height).auto_shrink([false, false]).show(
+ ui,
+ |ui| {
+ if entries.is_empty() {
+ ui_kit::text(ui, app.tr("render.library_empty"), ui_kit::Text::Note("render.library_empty"));
+ }
+ if view.layout == 0 {
+ let tiles: Vec<_> = entries
+ .iter()
+ .zip(&identities)
+ .zip(&tips)
+ .map(|(((kind, id, entry), identity), tip)| ui_kit::SphereTile {
+ id: identity,
+ name: entry["name"].as_str().unwrap_or(id),
+ sphere: tile_sphere(entry),
+ selected: view.kind == *kind && view.selected.as_ref() == Some(id),
+ users: usage_for(entry, &used).map_or_else(|| user_count(entry), user_count),
+ tip,
+ })
+ .collect();
+ if applicable_count > 0 {
+ ui_kit::text(ui, app.tr("render.library_applicable"), ui_kit::Text::Inline);
+ selected = ui_kit::sphere_grid(ui, tiles.get(..applicable_count).unwrap_or_default());
+ }
+ if applicable_count < tiles.len() {
+ if applicable_count > 0 {
+ ui_kit::text(ui, app.tr("render.library_other"), ui_kit::Text::Inline);
+ }
+ let other = ui_kit::sphere_grid(ui, tiles.get(applicable_count..).unwrap_or_default()).map(|i| i + applicable_count);
+ selected = selected.or(other);
+ }
+ } else {
+ for (index, ((kind, id, entry), tip)) in entries.iter().zip(&tips).enumerate() {
+ if index == 0 && applicable_count > 0 {
+ ui_kit::text(ui, app.tr("render.library_applicable"), ui_kit::Text::Inline);
+ } else if index == applicable_count && applicable_count > 0 {
+ ui_kit::text(ui, app.tr("render.library_other"), ui_kit::Text::Inline);
+ }
+ let mut item = ui_kit::MenuItem::new(id, entry["name"].as_str().unwrap_or(id), "appearance");
+ item.highlighted = view.kind == *kind && view.selected.as_ref() == Some(id);
+ let r = item.search_row(
+ ui,
+ query,
+ &format!(
+ "{} / {}",
+ if kind == "appearances" { entry["category"].as_str().unwrap_or(app.tr("render.library_in_design")) } else { id },
+ short_availability(app, entry.pointer("/projection/status").and_then(Value::as_str))
+ ),
+ None,
+ );
+ crate::scenario::publish_target(identities.get(index).map(String::as_str).unwrap_or("render:library:item"), r.rect);
+ if r.on_hover_text(tip).clicked() {
+ selected = Some(index);
+ }
}
}
- });
- if view.collection == 0 {
- ui.horizontal(|ui| {
- if ui_kit::button(ui, app.tr("render.library_previous"), ui_kit::Button::Enabled(view.offset > 0)).clicked() {
- view.offset = view.offset.saturating_sub(48);
- view.loaded = false;
+ },
+ );
+ if !stage_card || view.kind != "appearances" {
+ let menu = ui_kit::dropdown_menu(ui, "render_library_filters", app.tr("render.library_filters"), |ui| {
+ if view.collection == 0 {
+ for &(kind, key) in KINDS {
+ let r = ui_kit::list_picker(ui, kind, app.tr(key), view.kind == kind);
+ crate::scenario::publish_target(&format!("render:library-kind:{kind}"), r.rect);
+ if r.clicked() {
+ switch_kind(&mut view, kind);
+ ui.close();
+ }
+ }
+ ui_kit::divider(ui, "render-library-availability");
}
- if ui_kit::button(ui, app.tr("render.library_next"), ui_kit::Button::Enabled(view.next.is_some())).clicked() {
- view.offset = view.next.unwrap_or(view.offset);
- view.loaded = false;
+ for (id, key) in [
+ ("all", "render.library_all_states"),
+ ("usable", "render.library_usable"),
+ ("specification", "render.library_specs"),
+ ("blocked", "render.library_blocked"),
+ ] {
+ if ui_kit::list_picker(ui, id, app.tr(key), view.availability == id).clicked() {
+ view.availability = id.into();
+ view.offset = 0;
+ view.loaded = false;
+ ui.close();
+ }
}
});
+ crate::scenario::publish_target("render:library-category", menu.rect);
+ if view.collection == 0 && view.kind != "appearances" {
+ ui.horizontal(|ui| {
+ if ui_kit::button(ui, app.tr("render.library_previous"), ui_kit::Button::Enabled(view.offset > 0)).clicked() {
+ view.offset = view.offset.saturating_sub(48);
+ view.loaded = false;
+ }
+ if ui_kit::button(ui, app.tr("render.library_next"), ui_kit::Button::Enabled(view.next.is_some())).clicked() {
+ view.offset = view.next.unwrap_or(view.offset);
+ view.loaded = false;
+ }
+ });
+ }
}
- if let Some((kind, id)) = selected
- && let Err(error) = choose(app, &mut view, &kind, &id)
- {
- app.set_status(error, true);
+ if let Some((kind, id, entry)) = selected.and_then(|index| entries.get(index)) {
+ let result =
+ choose(app, &mut view, kind, id).and_then(|()| if stage_card && kind == "appearances" { apply_look(app, entry) } else { Ok(()) });
+ if let Err(error) = result {
+ app.set_status(error, true);
+ }
+ }
+ if stage_card {
+ ui_kit::catalog_footer(ui, app.tr("render.library_apply_hint"));
+ } else {
+ ui_kit::text(ui, app.tr("render.library_inspect_only"), ui_kit::Text::Note("render.library_inspect_only"));
}
- ui_kit::text(ui, app.tr("render.library_inspect_only"), ui_kit::Text::Note("render.library_inspect_only"));
app.render_workspace.view.library = view;
}
@@ -438,7 +920,9 @@ pub(super) fn selected_kind(app: &SolveApp, kind: &str) -> bool {
}
pub(super) fn inspect_kinds(app: &mut SolveApp, ui: &mut egui::Ui, kinds: &[&str]) {
- if kinds.contains(&app.render_workspace.view.library.kind.as_str()) {
+ if kinds.contains(&app.render_workspace.view.library.kind.as_str())
+ || (kinds.contains(&"surfaces") && app.render_workspace.view.library.kind == "appearances")
+ {
inspect(app, ui);
} else {
ui_kit::text(ui, app.tr("render.library_select_hint"), ui_kit::Text::Note("render.library_select_hint"));
@@ -448,7 +932,9 @@ pub(super) fn inspect(app: &mut SolveApp, ui: &mut egui::Ui) {
let mut view = std::mem::take(&mut app.render_workspace.view.library);
if let Some(id) = view.selected.clone() {
ui.strong(view.details.as_ref().and_then(|d| d["resource"]["name"].as_str()).unwrap_or(&id));
- ui.small(&id);
+ if view.kind != "appearances" {
+ ui.small(&id);
+ }
// Native composition is an actionable review, not a long specification
// reader: keep Resolve/consent/Apply ahead of ancillary resource metadata.
let native_composition = view.kind == "native_scenes";
@@ -456,19 +942,20 @@ pub(super) fn inspect(app: &mut SolveApp, ui: &mut egui::Ui) {
super::inspector::scene_resource(app, ui, &id);
}
let key = (view.kind.clone(), id.clone());
- let favorite = view.favorites.contains(&key);
+ let favorite = app.preferences.render_library_favorites.contains(&key);
if ui_kit::button(
ui,
app.tr(if favorite { "render.library_unfavorite" } else { "render.library_favorite" }),
- ui_kit::Button::Enabled(favorite || view.favorites.len() < 256),
+ ui_kit::Button::Enabled(favorite || app.preferences.render_library_favorites.len() < 256),
)
.clicked()
{
if favorite {
- view.favorites.remove(&key);
+ app.preferences.render_library_favorites.remove(&key);
} else {
- view.favorites.insert(key);
+ app.preferences.render_library_favorites.insert(key);
}
+ view.loaded = false;
}
if let Some(detail) = &view.details {
ui.small(format!("{}: {}", app.tr("render.library_status"), availability_label(app, detail["projection"]["status"].as_str())));
@@ -555,7 +1042,7 @@ pub(super) fn controls(app: &mut SolveApp, ui: &mut egui::Ui) {
saved_surface_controls(app, ui);
let title = app.tr("render.library_title").to_string();
ui_kit::section(ui, "render_resource_library", &title, false, |ui| {
- browse(app, ui);
+ browse_contents(app, ui, false);
inspect(app, ui);
});
}
@@ -601,8 +1088,35 @@ fn resource_controls(app: &mut SolveApp, ui: &mut egui::Ui, view: &mut View, id:
// previous surface's detail with the newly selected physical profile.
return;
}
- ui_kit::text(ui, app.tr("render.library_authored_help"), ui_kit::Text::Note("render.library_authored_help"));
+ if view.kind != "appearances" {
+ ui_kit::text(ui, app.tr("render.library_authored_help"), ui_kit::Text::Note("render.library_authored_help"));
+ }
match view.kind.as_str() {
+ "appearances" => {
+ target_controls(app, ui, view);
+ if ui_kit::button(
+ ui,
+ app.tr("render.library_apply_appearance"),
+ ui_kit::Button::Enabled(current_target(app, view) && source["available"] != false),
+ )
+ .clicked()
+ && let Some(target) = &view.target
+ {
+ let params = if let Some(preset) = source["id"].as_str() {
+ json!({"bodies":[target.name],"appearance":preset})
+ } else {
+ json!({"bodies":[target.name],"name":source["name"],"color":source["color"],"opacity":source["opacity"],"pbr":source["pbr"]})
+ };
+ match app.run("appearance.assign", params) {
+ Ok(_) => {
+ view.target_revision = None;
+ view.loaded = false;
+ app.set_status(app.tr("render.library_applied").to_string(), false);
+ }
+ Err(error) => app.set_status(error, true),
+ }
+ }
+ }
"native_scenes" => super::inspector::scene_resource(app, ui, id),
"quality" => super::inspector::quality_resource(app, ui, id),
"physical_profiles" => physical_controls(app, ui, view, id, &detail),
@@ -860,6 +1374,7 @@ fn physical_controls(app: &mut SolveApp, ui: &mut egui::Ui, view: &mut View, id:
fn short_availability<'a>(app: &'a SolveApp, status: Option<&str>) -> &'a str {
app.tr(match status {
+ Some("native_appearance") => "render.library_appearance_available",
Some("native_composition") => "render.library_short_native",
Some("implemented_pending_batch_validation") => "render.library_short_projection",
Some("blocked") => "render.library_short_blocked",
@@ -870,6 +1385,7 @@ fn short_availability<'a>(app: &'a SolveApp, status: Option<&str>) -> &'a str {
fn availability_label<'a>(app: &'a SolveApp, status: Option<&str>) -> &'a str {
app.tr(match status {
+ Some("native_appearance") => "render.library_appearance_available",
Some("native_composition") => "render.availability_native",
Some("implemented_pending_batch_validation") => "render.availability_projection",
Some("blocked") => "render.library_blocked",
@@ -883,19 +1399,321 @@ mod studio_browser_tests {
use super::*;
use crate::scenario::Harness;
#[test]
- fn favorites_and_recent_keep_exact_status_without_promoting_specs_to_runtime() {
+ fn appearance_cards_select_inspect_switch_layout_and_keep_explicit_apply() {
let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Sample"})).unwrap();
+ h.app.run("appearance.assign", json!({"bodies":["Sample"],"appearance":"ABS - Red"})).unwrap();
+ super::super::enter(&mut h.app, true).unwrap();
+ h.frames(4);
let before = h.app.session.doc.to_json();
+ h.step(&json!({"click":{"handle":"render:library-scope:in-design"}})).unwrap();
+ h.frames(3);
+ assert_eq!(h.app.render_workspace.view.library.collection, 3);
+ let id = appearance_id(&h.app.render_workspace.view.library.entries[0]);
+ h.step(&json!({"click":{"handle":format!("render:library:{id}")}})).unwrap();
+ h.frames(3);
+ assert_eq!(h.app.render_workspace.view.library.selected.as_deref(), Some(id.as_str()));
+ assert_eq!(h.app.render_workspace.view.inspector.page, super::super::inspector::Page::Appearance);
+ assert_eq!(h.app.session.doc.to_json(), before, "browsing and selection must not apply appearances");
+ h.step(&json!({"widget":h.app.tr("render.library_favorite")})).unwrap();
+ assert!(h.app.preferences.render_library_favorites.contains(&("appearances".into(), id.clone())));
+ h.step(&json!({"click":{"handle":"render:library-list"}})).unwrap();
+ h.frames(3);
+ assert_eq!(h.app.render_workspace.view.library.layout, 1);
+ h.step(&json!({"click":{"handle":"render:library-grid"}})).unwrap();
+ h.frames(3);
+ assert_eq!(h.app.render_workspace.view.library.layout, 0);
+ assert_eq!(h.app.session.doc.to_json(), before);
+ let catalog = h.app.run("appearance.library", json!({})).unwrap();
+ let blue = catalog["appearances"].as_array().unwrap().iter().find(|entry| entry["name"] == "ABS - Blue").unwrap();
+ let mut view = std::mem::take(&mut h.app.render_workspace.view.library);
+ choose(&mut h.app, &mut view, "appearances", &appearance_id(blue)).unwrap();
+ refresh_targets(&mut h.app, &mut view).unwrap();
+ view.target = view.targets.first().cloned();
+ h.app.render_workspace.view.library = view;
+ h.frames(3);
+ assert_eq!(h.app.session.doc.to_json(), before);
+ h.step(&json!({"widget":h.app.tr("render.library_apply_appearance")})).unwrap();
+ assert_eq!(h.app.session.doc.appearances.bodies.get("Sample").unwrap().name, "ABS - Blue");
+ if let Some(dir) = std::env::var_os("SOLIDCRAFT_LIBRARY_EVIDENCE") {
+ std::fs::create_dir_all(&dir).unwrap();
+ h.app.run("appearance.assign", json!({"bodies":["Sample"],"appearance":"Aluminum - Anodized Blue"})).unwrap();
+ h.app.run("select.set", json!({"items":[solidcraft_engine::Sel::Body {name:"Sample".into()}]})).unwrap();
+ h.app.render_workspace.view.library.collection = 0;
+ h.app.render_workspace.view.library.loaded = false;
+ let aluminum = h.app.run("appearance.library", json!({})).unwrap()["appearances"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .find(|e| e["name"] == "Aluminum - Anodized Blue")
+ .unwrap()
+ .clone();
+ let mut view = std::mem::take(&mut h.app.render_workspace.view.library);
+ choose(&mut h.app, &mut view, "appearances", &appearance_id(&aluminum)).unwrap();
+ h.app.render_workspace.view.library = view;
+ for dark in [false, true] {
+ h.app.preferences.theme = if dark { "dark" } else { "light" }.into();
+ h.app.ui.dark = dark;
+ let ctx = egui::Context::default();
+ crate::fonts::setup_bundled_fonts(&ctx);
+ let mut textures = std::collections::HashMap::new();
+ let mut final_frame = None;
+ for frame in 0..10 {
+ let mut output = ctx.run_ui(
+ egui::RawInput {
+ screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0))),
+ time: Some(frame as f64 / 10.0),
+ focused: true,
+ ..Default::default()
+ },
+ |ui| {
+ h.app.logic(ui.ctx());
+ h.app.ui(ui);
+ },
+ );
+ ui_kit::update_test_textures(&mut textures, &output.textures_delta);
+ output.textures_delta.clear();
+ final_frame = Some(output);
+ }
+ let output = final_frame.unwrap();
+ let image = ui_kit::raster_ui(&ctx, output.shapes, output.pixels_per_point, ctx.content_rect(), &textures);
+ image.save(std::path::Path::new(&dir).join(if dark { "appearances-dark.png" } else { "appearances-light.png" })).unwrap();
+ let card = h.app.shell.workspace_panels["render:appearances"].0;
+ assert_eq!(card.width(), 266.0);
+ let card_image = image::imageops::crop_imm(
+ &image,
+ card.left().round() as u32,
+ card.top().round() as u32,
+ card.width().round() as u32,
+ card.height().round() as u32,
+ )
+ .to_image();
+ card_image.save(std::path::Path::new(&dir).join(if dark { "card-dark.png" } else { "card-light.png" })).unwrap();
+ if let Some(reference) = std::env::var_os("SOLIDCRAFT_LIBRARY_REFERENCE") {
+ let reference = image::open(reference).unwrap().to_rgba8();
+ let reference = image::imageops::crop_imm(&reference, 8, 487, 266, 356).to_image();
+ let mut pair = image::RgbaImage::new(532, card_image.height().max(reference.height()));
+ image::imageops::overlay(&mut pair, &reference, 0, 0);
+ image::imageops::overlay(&mut pair, &card_image, 266, 0);
+ pair.save(std::path::Path::new(&dir).join(if dark {
+ "reference-left-current-right-dark.png"
+ } else {
+ "reference-left-current-right-light.png"
+ }))
+ .unwrap();
+ }
+ }
+ }
+ }
+ #[test]
+ fn stage_panel_titles_follow_stage_without_mutating_the_design() {
+ let mut h = Harness::new();
+ super::super::enter(&mut h.app, true).unwrap();
+ let before = h.app.session.doc.to_json();
+ for (stage, key) in [
+ ("look", "render.appearances"),
+ ("light", "render.studios_environments"),
+ ("frame", "render.frame_presets"),
+ ("output", "render.size_presets"),
+ ] {
+ h.app.run("view.render_stage", json!({"stage":stage})).unwrap();
+ h.frames(3);
+ assert_eq!(stage_title(h.app.render_workspace.view.stage), key);
+ let browser = h.app.shell.workspace_panels["render:browser"].0;
+ let panel = h.app.shell.workspace_panels["render:appearances"].0;
+ let strip = h.app.shell.workspace_panels["render:shots_strip"].0;
+ assert_eq!(panel.top() - browser.bottom(), Tokens::get().space_8, "{stage}: {browser:?} {panel:?} {strip:?}");
+ assert_eq!(strip.top() - panel.bottom(), Tokens::get().space_8, "{stage}: {browser:?} {panel:?} {strip:?}");
+ }
+ assert_eq!(h.app.session.doc.to_json(), before);
+ }
+
+ #[test]
+ fn applicable_resources_include_used_looks_and_selected_category_or_finish_before_the_rest() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Sample"})).unwrap();
+ h.app.run("appearance.assign", json!({"bodies":["Sample"],"appearance":"ABS - Red"})).unwrap();
+ h.app.session.selection = vec![solidcraft_engine::Sel::Body { name: "Sample".into() }];
+ let selected = selected_looks(&mut h.app);
+ assert_eq!(selected.len(), 1);
+ let used = h.app.run("appearance.list", json!({})).unwrap()["in_design"].as_array().unwrap().clone();
+ let selected_match = json!({"name":"ABS - Blue","color":"#123456","opacity":1.0});
+ let finish_match = json!({"name":"Unclassified finish","color":"#123456","opacity":1.0});
+ let unrelated = json!({"name":"Wood","color":"#123456","opacity":1.0,"pbr":{"metallic":0.0,"roughness":0.95}});
+ assert!(applicable(&selected_match, &selected, &used));
+ assert!(applicable(&finish_match, &selected, &used));
+ assert!(!applicable(&unrelated, &selected, &used));
+ let mut entries = [unrelated.clone(), selected_match.clone(), used[0].clone(), finish_match.clone()];
+ entries.sort_by_key(|entry| !applicable(entry, &selected, &used));
+ assert_eq!(entries, [selected_match, used[0].clone(), finish_match, unrelated]);
+ assert!(applicable(&used[0], &[], &used), "used looks remain applicable with nothing selected");
+ }
+
+ #[test]
+ fn look_tile_click_applies_to_selection_through_assign_and_undo() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Sample"})).unwrap();
+ h.app.session.selection = vec![solidcraft_engine::Sel::Body { name: "Sample".into() }];
+ super::super::enter(&mut h.app, true).unwrap();
+ h.frames(4);
+ let blue = h.app.render_workspace.view.library.entries.iter().find(|e| e["name"] == "ABS - Blue").unwrap().clone();
+ h.app.render_workspace.view.library.query = "ABS - Blue".into();
+ h.frames(3);
+ let undo = h.app.session.undo.len();
+ h.step(&json!({"click":{"handle":format!("render:library:{}",appearance_id(&blue))}})).unwrap();
+ assert_eq!(h.app.session.doc.appearances.bodies["Sample"].name, "ABS - Blue");
+ assert_eq!(h.app.session.undo.len(), undo + 1);
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert!(!h.app.session.doc.appearances.bodies.contains_key("Sample"));
+ }
+
+ #[test]
+ fn light_tiles_apply_existing_studio_and_environment_commands_with_one_undo_each() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":20,"width":15,"height":10,"body_name":"Sample"})).unwrap();
+ super::super::enter(&mut h.app, true).unwrap();
+ let unchanged = h.app.session.doc.to_json();
+ h.app.render_workspace.view.method = ImageMethod::Raster;
+ assert!(apply_light(&mut h.app, "native_scenes", "NATIVE-STUDIO-001").is_err());
+ assert_eq!(h.app.session.doc.to_json(), unchanged);
+ h.app.render_workspace.view.method = ImageMethod::GpuRaytrace;
+ h.app.run("view.render_stage", json!({"stage":"light"})).unwrap();
+ h.frames(4);
+ let undo = h.app.session.undo.len();
+ h.step(&json!({"click":{"handle":"render:light:NATIVE-STUDIO-001"}})).unwrap();
+ assert_eq!(h.app.session.undo.len(), undo + 1);
+ let name = h.app.render_workspace.view.name.clone();
+ assert!(!h.app.session.doc.render.setups[&name].stage.is_empty());
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(h.app.session.doc.to_json(), unchanged);
+ h.app.render_workspace.view = super::super::ViewState::default();
+ super::super::select_image_method(&mut h.app, ImageMethod::GpuRaytrace);
+ h.app.run("view.render_stage", json!({"stage":"light"})).unwrap();
+ h.frames(4);
+ let panel = h.app.shell.workspace_panels["render:appearances"].0;
+ for _ in 0..40 {
+ let tile = crate::scenario::rect_of("render:light:HDR-001").unwrap();
+ if tile.top() >= panel.top() + Tokens::get().form_header_height && tile.bottom() <= panel.bottom() {
+ break;
+ }
+ h.frame_with(vec![
+ egui::Event::PointerMoved(panel.center()),
+ egui::Event::MouseWheel {
+ unit: egui::MouseWheelUnit::Point,
+ delta: egui::vec2(0.0, -80.0),
+ modifiers: egui::Modifiers::default(),
+ phase: egui::TouchPhase::Move,
+ },
+ ]);
+ h.frames(4);
+ }
+ h.frame_with(vec![egui::Event::MouseWheel {
+ unit: egui::MouseWheelUnit::Point,
+ delta: egui::Vec2::ZERO,
+ modifiers: egui::Modifiers::default(),
+ phase: egui::TouchPhase::End,
+ }]);
+ h.frames(30);
+ let tile = crate::scenario::rect_of("render:light:HDR-001").unwrap();
+ assert!(panel.contains_rect(tile), "HDR tile must be reachable through the panel scroll area");
+ assert!(light_reason(&h.app, "hdr").is_none(), "HDR is disabled: {:?}", light_reason(&h.app, "hdr"));
+ h.step(&json!({"click":{"handle":"render:light:HDR-001"}})).unwrap();
+ assert_eq!(h.app.session.undo.len(), undo + 1, "HDR click: {:?}; tile: {tile:?}; panel: {panel:?}", h.app.status);
+ assert!(!h.app.session.doc.render.resources.is_empty());
+ h.app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(h.app.session.doc.to_json(), unchanged);
+ }
+
+ #[test]
+ fn tile_finishes_follow_pbr_and_opacity_and_authored_surface_color() {
+ for (opacity, metallic, roughness, expected) in [
+ (1.0, 0.0, 0.9, ui_kit::FinishKind::Matte),
+ (1.0, 0.0, 0.5, ui_kit::FinishKind::Satin),
+ (1.0, 0.0, 0.1, ui_kit::FinishKind::Gloss),
+ (1.0, 1.0, 0.1, ui_kit::FinishKind::Metal),
+ (0.4, 1.0, 0.9, ui_kit::FinishKind::Glass),
+ ] {
+ let sphere = tile_sphere(&json!({"color":"#123456","opacity":opacity,"pbr":{"metallic":metallic,"roughness":roughness}}));
+ assert_eq!(sphere.kind, expected);
+ assert_eq!(sphere.color, egui::Color32::from_rgb(0x12, 0x34, 0x56));
+ assert_eq!(sphere.opacity, Some(opacity as f32));
+ }
+ let source = json!({"resource":{"base_linear_low":[0.0,0.5,1.0],"base_linear_high":[0.0,0.5,1.0],"metallic":1.0,"roughness":0.4}});
+ assert_eq!(tile_sphere(&source).color, egui::Color32::from_rgb(0, 188, 255));
+ let selene = json!({"resource":{"baseline_projection":{"runtime_parameters":{"color":[20,40,60],"opacity":1.0,"pbr":{"metallic":1.0,"roughness":0.3}}}}});
+ assert_eq!(tile_sphere(&selene).color, egui::Color32::from_rgb(20, 40, 60));
+ assert_eq!(tile_sphere(&selene).kind, ui_kit::FinishKind::Metal);
+ }
+ #[test]
+ fn scopes_search_categories_and_availability_filter_real_catalog_entries() {
+ let mut h = Harness::new();
+ h.app.run("solid.box", json!({"length":10,"width":10,"height":10,"body_name":"Sample"})).unwrap();
+ h.app.run("appearance.assign", json!({"bodies":["Sample"],"appearance":"ABS - Red"})).unwrap();
+ let mut view = View { collection: 3, ..Default::default() };
+ refresh(&mut h.app, &mut view).unwrap();
+ assert_eq!(view.entries.len(), 1);
+ assert_eq!(user_count(&view.entries[0]), 1);
+ assert_eq!(user_count(&json!({"bodies":["A"],"faces":[{"body":"B"}],"components":["C"]})), 3);
+ assert!(matches_entry(&view.entries[0], "rEd", "", "usable"));
+ assert!(!matches_entry(&view.entries[0], "blue", "", "all"));
+ assert!(matches_entry(&json!({"name":"Coating","resource":{"tags":["Enclosure"]}}), "enclosure", "", "all"));
+ let id = appearance_id(&view.entries[0]);
+ choose(&mut h.app, &mut view, "appearances", &id).unwrap();
+ h.app.preferences.render_library_favorites.insert(("appearances".into(), id));
+ for scope in [1, 2] {
+ view.collection = scope;
+ refresh(&mut h.app, &mut view).unwrap();
+ assert_eq!(view.entries.len(), 1);
+ assert_eq!(view.entries[0]["name"], "ABS - Red");
+ }
+ view.collection = 0;
+ refresh(&mut h.app, &mut view).unwrap();
+ assert!(view.entries.len() > 10);
+ assert!(view.entries.iter().any(|entry| matches_entry(entry, "aBs", "ABS", "all")));
+ assert!(!view.entries.iter().any(|entry| matches_entry(entry, "ABS", "missing category", "all")));
+ assert!(view.entries.iter().filter(|entry| matches_entry(entry, "", "", "blocked")).all(|entry| entry["available"] == false));
+ let source = h.app.run("render.library.describe", json!({"kind":"surfaces","id":"SURF-001"})).unwrap();
+ let entry = json!({"id":"SURF-001","name":source["resource"]["name"],"resource":source["resource"]});
+ h.app.run("render.library.appearance.apply", json!({"id":"SURF-001","variant":"uniform_opaque","bodies":["Sample"]})).unwrap();
+ let reply = h.app.run("appearance.list", json!({})).unwrap();
+ assert_eq!(user_count(usage_for(&entry, reply["in_design"].as_array().unwrap()).unwrap()), 1);
+ }
+ #[test]
+ fn preferences_round_trip_favorites_and_recent_without_saving_them_in_design() {
+ let mut h = Harness::new();
let mut view = View::default();
+ let before = h.app.session.doc.to_json();
+ choose(&mut h.app, &mut view, "surfaces", "SURF-001").unwrap();
+ h.app.preferences.render_library_favorites.insert(("surfaces".into(), "SURF-001".into()));
+ let saved = serde_json::to_value(&h.app.preferences).unwrap();
+ let prefs = crate::prefs::lenient(&saved);
+ assert_eq!(prefs.render_library_favorites, h.app.preferences.render_library_favorites);
+ assert_eq!(prefs.render_library_recent, h.app.preferences.render_library_recent);
+ assert_eq!(h.app.session.doc.to_json(), before);
+ let custom = json!({"name":"Workshop look","color":"#123456","opacity":0.5});
+ let id = appearance_id(&custom);
+ let detail = describe(&mut h.app, "appearances", &id).unwrap();
+ assert_eq!(detail["resource"]["color"], custom["color"]);
+ assert!(crate::prefs::lenient(&json!({})).render_library_favorites.is_empty());
+ let hostile = json!({"render_library_recent":vec![("surfaces","SURF-001");100],"render_library_favorites":[["surfaces",""]]});
+ let prefs = crate::prefs::lenient(&hostile);
+ assert_eq!(prefs.render_library_recent.len(), 32);
+ assert!(prefs.render_library_favorites.is_empty());
+ }
+ #[test]
+ fn favorites_and_recent_keep_exact_status_without_promoting_specs_to_runtime() {
+ let mut h = Harness::new();
+ let before = h.app.session.doc.to_json();
+ let mut view = View { kind: "surfaces".into(), ..Default::default() };
choose(&mut h.app, &mut view, "native_scenes", "NATIVE-STUDIO-002").unwrap();
let native = ("native_scenes".into(), "NATIVE-STUDIO-002".into());
- view.favorites.insert(native.clone());
+ h.app.preferences.render_library_favorites.insert(native.clone());
choose(&mut h.app, &mut view, "scenes", "SCENE-001").unwrap();
assert_eq!(view.statuses.get(&("scenes".into(), "SCENE-001".into())).map(String::as_str), Some("specification_only"));
for i in 1..=48 {
choose(&mut h.app, &mut view, "surfaces", &format!("SURF-{i:03}")).unwrap();
}
- assert_eq!(view.recent.len(), 32);
+ assert_eq!(h.app.preferences.render_library_recent.len(), 32);
assert_eq!(view.statuses.len(), 33);
assert_eq!(view.statuses.get(&native).map(String::as_str), Some("native_composition"));
assert_eq!(h.app.session.doc.to_json(), before);
@@ -904,7 +1722,7 @@ mod studio_browser_tests {
#[test]
fn physical_reference_navigation_uses_the_same_category_history() {
let mut h = Harness::new();
- let mut view = View::default();
+ let mut view = View { kind: "surfaces".into(), ..Default::default() };
choose(&mut h.app, &mut view, "surfaces", "SURF-001").unwrap();
view.query = "brushed".into();
view.offset = 48;
@@ -920,6 +1738,7 @@ mod studio_browser_tests {
#[test]
fn category_navigation_preserves_queries_pages_selection_and_declared_scope() {
let mut view = View {
+ kind: "surfaces".into(),
query: "brushed".into(),
offset: 48,
selected: Some("SURF-001".into()),
@@ -949,11 +1768,11 @@ mod studio_browser_tests {
for n in 1..=48 {
choose(&mut h.app, &mut view, "surfaces", &format!("SURF-{n:03}")).unwrap();
}
- assert_eq!(view.recent.len(), 32);
+ assert_eq!(h.app.preferences.render_library_recent.len(), 32);
assert_eq!(h.app.session.doc.to_json(), before);
assert!(h.app.session.undo.is_empty());
choose(&mut h.app, &mut view, "surfaces", "SURF-048").unwrap();
- assert_eq!(view.recent.len(), 32);
+ assert_eq!(h.app.preferences.render_library_recent.len(), 32);
assert_eq!(h.app.render_workspace.view.inspector.page, super::super::inspector::Page::Appearance);
choose(&mut h.app, &mut view, "native_scenes", "NATIVE-STUDIO-002").unwrap();
assert_eq!(h.app.render_workspace.view.inspector.page, super::super::inspector::Page::Scene);
diff --git a/crates/ui-egui/src/render_workspace_tests.rs b/crates/ui-egui/src/render_workspace_tests.rs
index 851d097a4a..8cf424fe5f 100644
--- a/crates/ui-egui/src/render_workspace_tests.rs
+++ b/crates/ui-egui/src/render_workspace_tests.rs
@@ -2917,7 +2917,7 @@ fn render_workspace_stage_shell_degrades_without_overlap_at_small_window_sizes()
["render:browser", "render:inspector"].iter().filter_map(|id| h.app.shell.workspace_panels.get(id).map(|(r, _)| *r)).collect();
if let [browser, inspector] = docks.as_slice() {
assert!((browser.top() - inspector.top()).abs() < 1.0);
- assert!((browser.bottom() - inspector.bottom()).abs() < 1.0);
+ assert!(browser.bottom() < inspector.bottom());
assert!(!browser.intersect(*inspector).is_positive());
if width >= 800 {
let compact = crate::render_ui::compact(&h.app, width as f32);
@@ -2925,7 +2925,9 @@ fn render_workspace_stage_shell_degrades_without_overlap_at_small_window_sizes()
assert_eq!(inspector.width(), if compact { crate::frame::DIALOG_MIN_W } else { 305.0 });
assert_eq!(browser.top() - bar.bottom(), 8.0);
let (strip, _) = h.app.shell.workspace_panels.get("render:shots_strip").unwrap();
- assert_eq!(strip.top() - browser.bottom(), 8.0);
+ let library = h.app.shell.workspace_panels["render:appearances"].0;
+ assert_eq!(strip.top() - library.bottom(), 8.0);
+ assert_eq!(library.top() - browser.bottom(), 8.0);
assert_eq!(strip.height(), 48.0);
}
}
@@ -2938,6 +2940,13 @@ fn render_workspace_stage_shell_degrades_without_overlap_at_small_window_sizes()
assert!(!dock.x_range().contains(h.app.viewport.rect.unwrap().center().x), "{width}: {dock:?}");
}
}
+ let mut docks = docks;
+ if let Some((panel, _)) = h.app.shell.workspace_panels.get("render:appearances") {
+ for dock in &docks {
+ assert!(!panel.intersect(*dock).is_positive());
+ }
+ docks.push(*panel);
+ }
for dock in docks {
assert!(!dock.intersect(bar).is_positive(), "{width}×{height}: {dock:?} {bar:?}");
if let Some((strip, _)) = h.app.shell.workspace_panels.get("render:shots_strip") {
@@ -2974,7 +2983,7 @@ fn render_workspace_focus_restores_docks_without_design_history_or_camera_change
assert!(crate::render_ui::focused(&h.app));
crate::shell::register_panel(&mut h.app, "render:stage_panel", Some(before), Some(crate::ui_kit::Edge::Left));
assert!(!h.app.shell.workspace_panels.contains_key("render:stage_panel"));
- for id in ["render:browser", "render:inspector", "render:shots_strip", "render:shots:show"] {
+ for id in ["render:browser", "render:appearances", "render:inspector", "render:shots_strip", "render:shots:show"] {
assert!(!h.app.shell.workspace_panels.contains_key(id));
assert!(crate::scenario::rect_of(id).is_none());
}
@@ -3387,16 +3396,18 @@ fn render_workspace_hosts_float_and_shield_input_in_both_ribbon_layouts() {
&& (shots.bottom() - history.bottom()).abs() < 1.0,
"Shots must reuse History's floating placement: {shots:?} {history:?}"
);
- for key in ["render:inspector", "render:browser", "render:shots_strip"] {
+ for key in ["render:inspector", "render:browser", "render:appearances", "render:shots_strip"] {
let (card, _) = h.app.shell.workspace_panels.get(key).unwrap();
assert!(viewport.contains_rect(*card), "{layout:?} {key}: {card:?} outside {viewport:?}");
assert!(crate::shell::covered(&h.app, card.center()), "{key} must shield the viewport");
}
let inspector = h.app.shell.workspace_panels["render:inspector"].0;
let browser = h.app.shell.workspace_panels["render:browser"].0;
+ let appearances = h.app.shell.workspace_panels["render:appearances"].0;
let ribbon_bottom = h.app.shell.cards.iter().map(|r| r.bottom()).fold(0.0, f32::max);
assert!((browser.top() - inspector.top()).abs() < 1.0);
- assert!((browser.bottom() - inspector.bottom()).abs() < 1.0);
+ assert!((appearances.bottom() - inspector.bottom()).abs() < 1.0);
+ assert!(browser.height() <= 330.0, "Browser must stay within the fixed tree height: {browser:?}");
for key in ["render:browser", "render:inspector"] {
let card = h.app.shell.workspace_panels[key].0;
assert!(
@@ -3405,12 +3416,19 @@ fn render_workspace_hosts_float_and_shield_input_in_both_ribbon_layouts() {
card.top() - ribbon_bottom
);
}
- for key in ["render:browser", "render:inspector"] {
+ for key in ["render:browser", "render:appearances", "render:inspector"] {
let card = h.app.shell.workspace_panels[key].0;
let header = crate::scenario::rect_of(&format!("{key}:header")).unwrap();
assert!((header.height() - crate::ui_kit::header_height()).abs() < 0.1, "{key}: {header:?}");
assert!((header.top() - card.top()).abs() <= 1.0, "header must have no outer content padding");
- let control = crate::scenario::rect_of(if key == "render:browser" { "render:tree:by-look" } else { "render:page:output" }).unwrap();
+ let control = crate::scenario::rect_of(if key == "render:browser" {
+ "render:tree:by-look"
+ } else if key == "render:appearances" {
+ "render:library-search"
+ } else {
+ "render:page:output"
+ })
+ .unwrap();
if key == "render:browser" {
assert!(header.contains_rect(control), "Scene lens belongs in the title band");
} else {
@@ -3418,6 +3436,9 @@ fn render_workspace_hosts_float_and_shield_input_in_both_ribbon_layouts() {
}
}
+ assert!((browser.width() - appearances.width()).abs() < 1.0);
+ assert!((appearances.top() - browser.bottom() - Tokens::get().space_8).abs() < 1.0);
+ assert!(appearances.bottom() < shots.top());
assert!(browser.left() > viewport.left() && inspector.right() < viewport.right());
assert!(inspector.bottom() < shots.top() && browser.bottom() < shots.top());
let camera = h.app.cam;
@@ -4180,8 +4201,11 @@ fn render_workspace_browser_compact_geometry_search_and_theme_evidence() {
let card = crate::scenario::rect_of("browser:card").unwrap();
assert!((card.width() - 266.0).abs() < 0.1);
let inspector = crate::scenario::rect_of("render:inspector").unwrap();
+ let stage_panel = h.app.shell.workspace_panels["render:appearances"].0;
assert!((card.top() - inspector.top()).abs() < 0.1);
- assert!((card.bottom() - inspector.bottom()).abs() < 0.1);
+ assert!((stage_panel.bottom() - inspector.bottom()).abs() < 0.1);
+ assert!((stage_panel.top() - card.bottom() - Tokens::get().space_8).abs() < 0.1);
+ assert!(card.height() <= 330.0, "Browser must stay within the fixed tree height: {card:?}");
let header = crate::scenario::rect_of("render:browser:header").unwrap();
assert!(header.contains_rect(crate::scenario::rect_of("render:tree:by-look").unwrap()));
assert!(crate::scenario::handle_at("render:browser-model").is_none());
diff --git a/crates/ui-egui/src/ui_kit/choice.rs b/crates/ui-egui/src/ui_kit/choice.rs
index 88a5c61d46..380f580f47 100644
--- a/crates/ui-egui/src/ui_kit/choice.rs
+++ b/crates/ui-egui/src/ui_kit/choice.rs
@@ -36,7 +36,8 @@ pub(crate) fn segmented(ui: &mut Ui, selected: &mut usize, options: &[&str], con
let Segments { targets, icons, workspace_accent, dense, small, states, compact, primary, intrinsic, proportional } = config;
let accent = crate::theme::TabAccent::current(ui.ctx());
let t = Tokens::get();
- let font_size = if small { t.font_small } else { t.font_label };
+ let catalog = super::layout::in_catalog(ui);
+ let font_size = if small || catalog { t.font_small } else { t.font_label };
let natural: Vec<_> = options
.iter()
.enumerate()
@@ -64,7 +65,9 @@ pub(crate) fn segmented(ui: &mut Ui, selected: &mut usize, options: &[&str], con
let (rect, _) = ui.allocate_exact_size(
vec2(
desired,
- if small {
+ if catalog {
+ t.space_16
+ } else if small {
t.control_height - t.space_4
} else if dense {
t.control_height - t.space_2
@@ -175,8 +178,13 @@ pub(crate) struct IconSegment {
/// Equal icon choices with mixed state. Tokens: `segmented tokens, space_4/12, icon/fill, accent; icon palette`.
pub(crate) fn segmented_icons(ui: &mut Ui, selected: &mut usize, options: &[IconSegment], states: &[bool]) -> bool {
let t = Tokens::get();
- let (rect, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), row_height()), egui::Sense::hover());
- ui.painter().rect_filled(rect, t.control_radius, t.control_fill);
+ let catalog = super::layout::in_catalog(ui);
+ let accent = crate::theme::TabAccent::current(ui.ctx());
+ let (rect, _) =
+ ui.allocate_exact_size(vec2(dimension(ui.available_width()), if catalog { t.space_24 } else { row_height() }), egui::Sense::hover());
+ if !catalog {
+ ui.painter().rect_filled(rect, t.control_radius, t.control_fill);
+ }
let width = rect.width() / options.len().max(1) as f32;
let mut clicked = false;
for (index, option) in options.iter().enumerate() {
@@ -190,25 +198,41 @@ pub(crate) fn segmented_icons(ui: &mut Ui, selected: &mut usize, options: &[Icon
se: if index + 1 == options.len() { t.control_radius } else { 0 },
};
if on || response.hovered() {
- ui.painter().rect_filled(segment, rounding, if on { t.selected_bg } else { t.hover });
+ ui.painter().rect_filled(
+ segment,
+ rounding,
+ if on && catalog {
+ accent.soft
+ } else if on {
+ t.selected_bg
+ } else {
+ t.hover
+ },
+ );
}
- if index > 0 {
+ if index > 0 && !catalog {
ui.painter().vline(segment.left(), segment.y_range(), t.control_border_stroke(t.control_border));
}
// A square icon area inside the segment: dash gaps and dots need the room to read apart.
let side = (segment.width().min(segment.height()) - t.space_4).max(t.space_12);
let icon_rect = egui::Rect::from_center_size(segment.center(), vec2(side, side));
- crate::icons::paint_icon(ui.painter(), icon_rect, option.icon, f32::from(t.icon.a()) / 255.0);
+ if catalog {
+ let icon_rect = egui::Rect::from_center_size(segment.center(), vec2(t.space_14, t.space_14));
+ crate::icons::paint_ink(ui.painter(), icon_rect, option.icon, if on { accent.ink } else { t.form_dim });
+ } else {
+ crate::icons::paint_icon(ui.painter(), icon_rect, option.icon, f32::from(t.icon.a()) / 255.0);
+ }
t.button_bevel_with_radius(ui, &response, on, rounding);
response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, ui.is_enabled(), on, option.key));
scenario::publish_handle(&format!("dialog:{}:{}", label(ui), option.key), segment.center());
+ scenario::publish_target(option.key, segment);
let response = response.on_hover_text(&option.tip);
if response.clicked() {
*selected = index;
clicked = true;
}
}
- if t.borders.bevel.is_none() {
+ if !catalog && t.borders.bevel.is_none() {
ui.painter().rect_stroke(rect, t.control_radius, t.control_border_stroke(t.control_border), egui::StrokeKind::Inside);
}
scenario::publish_target_as(&format!("dialog:{}", label(ui)), &format!("dialog:segments:{}", label(ui)), rect);
@@ -356,6 +380,23 @@ pub(crate) fn list_picker(ui: &mut Ui, key: &str, text: &str, selected: bool) ->
/// Intrinsic-width selection chip for horizontal lists, sharing list-picker styling.
pub(crate) fn choice_chip(ui: &mut Ui, key: &str, text: &str, selected: bool) -> egui::Response {
let t = Tokens::get();
+ if super::layout::in_catalog(ui) {
+ let accent = crate::theme::TabAccent::current(ui.ctx());
+ let width = ui.painter().layout_no_wrap(text.to_string(), crate::fonts::semibold(t.font_small), t.form_ink).size().x + t.space_16;
+ let (rect, response) = ui.allocate_exact_size(vec2(width, t.space_16 + t.space_4), egui::Sense::click());
+ ui.painter().rect_filled(rect, t.radius_xl, if selected { accent.soft } else { t.control_fill });
+ paint_text(
+ ui,
+ rect.shrink2(vec2(t.space_8, 0.0)),
+ text,
+ if selected { crate::fonts::semibold(t.font_small) } else { egui::FontId::proportional(t.font_small) },
+ if selected { accent.ink } else { t.form_ink },
+ false,
+ );
+ response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, ui.is_enabled(), selected, text));
+ crate::scenario::publish_target(&format!("dialog:list:{key}"), rect);
+ return response;
+ }
let width = (ui.painter().layout_no_wrap(text.to_owned(), crate::fonts::semibold(t.font_label), t.text).size().x + t.space_24)
.clamp(t.control_height * 2.0, t.form_card_width);
let response = ui.add_sized(vec2(width, super::row_height()), egui::Button::selectable(selected, text).truncate());
diff --git a/crates/ui-egui/src/ui_kit/fields.rs b/crates/ui-egui/src/ui_kit/fields.rs
index e4365971bd..8230f8ed5e 100644
--- a/crates/ui-egui/src/ui_kit/fields.rs
+++ b/crates/ui-egui/src/ui_kit/fields.rs
@@ -455,7 +455,23 @@ fn cell_editor_frame(ui: &mut Ui, id: egui::Id, value: &mut String, hint: &str,
/// Search input with native accessibility and a stable caller ID. Tokens: cell_editor tokens.
pub(crate) fn search_field(ui: &mut Ui, id: egui::Id, value: &mut String, hint: &str) -> Response {
- cell_editor(ui, id, value, hint, false)
+ if !super::layout::in_catalog(ui) {
+ return cell_editor(ui, id, value, hint, false);
+ }
+ let t = Tokens::get();
+ let editor = text_input(egui::TextEdit::singleline(value))
+ .id(id)
+ .char_limit(128)
+ .hint_text(hint)
+ .min_size(vec2(0.0, t.space_16 + t.space_2))
+ .margin(egui::Margin { left: t.space_24 as i8, right: t.space_8 as i8, top: 0, bottom: 0 })
+ .font(egui::FontId::proportional(t.font_small))
+ .text_color(t.form_ink);
+ let response = ui.add_sized(vec2(dimension(ui.available_width()), t.space_16 + t.space_2), editor);
+ let icon = egui::Rect::from_center_size(egui::pos2(response.rect.left() + t.space_12, response.rect.center().y), vec2(t.space_12, t.space_12));
+ crate::icons::paint_ink(ui.painter(), icon, "zoom", t.form_dim);
+ super::layout::publish_geometry(ui, &response);
+ response
}
/// Behaviour of the one kit slider. Appearance is always owned by `slider`.
diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs
index cb2398f997..5ce9e78b86 100644
--- a/crates/ui-egui/src/ui_kit/gallery.rs
+++ b/crates/ui-egui/src/ui_kit/gallery.rs
@@ -163,6 +163,48 @@ const ELEMENTS: &[Element] = &[
[TreeAction { icon: "lookat", hover_only: true, label: "Solo", reason: Some("Not available yet"), target: "gallery:tree:solo" }];
tree_row(ui, ui.id().with("tree_actions"), &Row { label: "Light", actions: &actions, ..Default::default() });
}),
+ element!("catalog_scope", |ui, state| {
+ catalog_scope(ui, |ui| {
+ search_field(ui, ui.id().with("catalog_search"), &mut state.value, "Search appearances");
+ segmented(
+ ui,
+ &mut state.selected,
+ &["In Design", "Library", "Recent", "★"],
+ Segments { compact: true, proportional: true, workspace_accent: true, ..Default::default() },
+ );
+ ui.horizontal(|ui| {
+ choice_chip(ui, "catalog_all", "All", true);
+ choice_chip(ui, "catalog_metal", "Metal", false);
+ });
+ catalog_footer(ui, "Click to apply · drag onto the model");
+ });
+ }),
+ element!("catalog_footer", |ui, _| {
+ catalog_footer(ui, "Click to apply · drag onto the model");
+ }),
+ element!("sphere_grid", |ui, _| {
+ let sphere = Sphere { color: Tokens::get().render_accent, kind: FinishKind::Satin, opacity: None };
+ let tiles = ["gallery:grid:a", "gallery:grid:b", "gallery:grid:c"].map(|id| SphereTile {
+ id,
+ name: "Satin",
+ sphere,
+ selected: id.ends_with('b'),
+ users: 1,
+ tip: "Satin",
+ });
+ sphere_grid(ui, &tiles);
+ }),
+ element!("sphere_tile", "gallery:tile", Some("gallery:tile"), |ui, _| {
+ SphereTile {
+ id: "gallery:tile",
+ name: "Satin metal",
+ sphere: Sphere { color: Tokens::get().render_accent, kind: FinishKind::Metal, opacity: None },
+ selected: true,
+ users: 3,
+ tip: "Satin metal",
+ }
+ .show(ui);
+ }),
element!("settings_form", |ui, state| {
settings_form(ui, Tokens::get().form_label_width, |ui| {
row(ui, "Sample", |ui| {
diff --git a/crates/ui-egui/src/ui_kit/layout.rs b/crates/ui-egui/src/ui_kit/layout.rs
index 55700e59e5..676f3e67de 100644
--- a/crates/ui-egui/src/ui_kit/layout.rs
+++ b/crates/ui-egui/src/ui_kit/layout.rs
@@ -44,6 +44,37 @@ pub(crate) fn scope<R>(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R {
.inner
}
+/// Compact library cards share search, segment, chip and footer metrics.
+pub(crate) fn catalog_scope<R>(ui: &mut Ui, add: impl FnOnce(&mut Ui) -> R) -> R {
+ ui.scope_builder(egui::UiBuilder::new().ui_stack_info(egui::UiStackInfo::default().with_tag("sc_catalog")), |ui| {
+ ui.spacing_mut().item_spacing.y = Tokens::get().space_8;
+ add(ui)
+ })
+ .inner
+}
+
+pub(super) fn in_catalog(ui: &Ui) -> bool {
+ ui.stack().iter().any(|node| node.tags().contains("sc_catalog"))
+}
+
+/// Quiet full-width library footer with the shared information glyph.
+pub(crate) fn catalog_footer(ui: &mut Ui, text: &str) {
+ let t = Tokens::get();
+ let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), t.control_height), egui::Sense::hover());
+ t.secondary_hline(ui.painter(), rect.x_range(), rect.top(), t.dialog_rule);
+ let icon = egui::Rect::from_center_size(egui::pos2(rect.left() + t.space_6, rect.center().y), vec2(t.space_12, t.space_12));
+ ui.painter().circle_stroke(icon.center(), t.space_4, t.control_border_stroke(t.form_dim));
+ ui.painter().text(icon.center(), egui::Align2::CENTER_CENTER, "i", crate::fonts::semibold(t.font_badge), t.form_dim);
+ paint_text(
+ ui,
+ egui::Rect::from_min_max(egui::pos2(icon.right() + t.space_6, rect.top()), rect.max),
+ text,
+ egui::FontId::proportional(t.font_small),
+ t.form_dim,
+ false,
+ );
+}
+
/// Read the enclosing row accessibility label. Tokens: `none`.
pub(crate) fn label(ui: &Ui) -> &str {
ui.stack().iter().find_map(|node| node.tags().get_downcast::<String>(LABEL)).map(String::as_str).unwrap_or("")
@@ -474,10 +505,12 @@ pub(crate) fn text(ui: &mut Ui, text: &str, style: Text<'_>) -> Response {
let fixed = matches!(style, Text::Cell | Text::NameCell(_) | Text::MonoCell | Text::Value(_, _));
let ink = match style {
Text::Hint(_) | Text::Note(_) | Text::MonoNote(_) => t.form_dim,
+ Text::Inline if in_catalog(ui) => t.form_dim,
Text::Report(_, true) | Text::Value(_, true) | Text::Error(_) => t.form_error,
_ => t.form_ink,
};
let font = match style {
+ Text::Inline if in_catalog(ui) => crate::fonts::semibold(t.font_small),
Text::NameCell(true) => crate::fonts::semibold(t.font_label),
Text::NameCell(false) => crate::fonts::medium(t.font_label),
Text::Heading(_) => crate::fonts::semibold(t.font_button),
diff --git a/crates/ui-egui/src/ui_kit/mod.rs b/crates/ui-egui/src/ui_kit/mod.rs
index 61a0cd5fb2..310cde1546 100644
--- a/crates/ui-egui/src/ui_kit/mod.rs
+++ b/crates/ui-egui/src/ui_kit/mod.rs
@@ -45,6 +45,8 @@ pub(crate) use actions::*;
pub use actions::{Button, button};
pub(crate) use assistant::*;
pub(crate) use assistant_entry::*;
+#[cfg(test)]
+pub(crate) use checks::tests::{raster as raster_ui, textures_update as update_test_textures};
pub(crate) use checks::*;
pub(crate) use choice::*;
pub(crate) use color::*;
@@ -76,6 +78,7 @@ pub(crate) use reports::*;
pub(crate) use search::{CommandSearch, SearchBadge, SearchFieldGeometry};
pub(crate) use shortcuts::*;
pub use sphere::{FinishKind, Sphere, sphere_thumbnail};
+pub(crate) use sphere::{SphereTile, sphere_grid};
pub(crate) use stages::{StageAction, StageBar};
pub(crate) use status::*;
pub(crate) use table::*;
diff --git a/crates/ui-egui/src/ui_kit/panel.rs b/crates/ui-egui/src/ui_kit/panel.rs
index 457915f60a..ced2da074a 100644
--- a/crates/ui-egui/src/ui_kit/panel.rs
+++ b/crates/ui-egui/src/ui_kit/panel.rs
@@ -30,6 +30,18 @@ fn header_impl(
collapsed: Option<&mut bool>,
closeable: bool,
on_close: impl FnOnce(),
+) {
+ header_actions(ui, icon, title, collapsed, closeable, on_close, None);
+}
+
+fn header_actions(
+ ui: &mut Ui,
+ icon: (&str, Option<egui::Color32>),
+ title: &str,
+ collapsed: Option<&mut bool>,
+ closeable: bool,
+ on_close: impl FnOnce(),
+ actions: Option<&mut dyn FnMut(&mut Ui)>,
) {
let t = Tokens::get();
let (rect, _) = ui.allocate_exact_size(vec2(dimension(ui.available_width()), header_height()), egui::Sense::hover());
@@ -38,7 +50,9 @@ fn header_impl(
egui::pos2(rect.left() + t.space_12 + t.form_icon_size / 2.0, rect.center().y),
vec2(t.form_icon_size, t.form_icon_size),
);
- if let Some(ink) = icon.1 {
+ if icon.0.is_empty() {
+ ui.painter().circle_filled(icon_rect.center(), t.space_3, crate::theme::TabAccent::current(ui.ctx()).ink);
+ } else if let Some(ink) = icon.1 {
crate::icons::paint_ink(ui.painter(), icon_rect, icon.0, ink);
} else {
crate::icons::paint_icon(ui.painter(), icon_rect, icon.0, 1.0);
@@ -54,7 +68,15 @@ fn header_impl(
on_close();
}
}
- let right = if let Some(collapsed) = collapsed {
+ let right = if let Some(actions) = actions {
+ let action_rect = egui::Rect::from_center_size(
+ egui::pos2(rect.right() - t.space_8 - t.control_height, rect.center().y),
+ vec2(t.control_height * 2.0, t.control_height),
+ );
+ let mut action_ui = ui.new_child(egui::UiBuilder::new().max_rect(action_rect));
+ actions(&mut action_ui);
+ action_rect.left() - t.space_8
+ } else if let Some(collapsed) = collapsed {
let fold = egui::Rect::from_min_size(egui::pos2(close_rect.left() - t.form_close_size - t.space_4, close_rect.top()), close_rect.size());
let response = super::disclosure_button_at(ui, fold, !*collapsed, crate::i18n::tr_label(if *collapsed { "Expand" } else { "Collapse" }));
scenario::publish_handle("dialog:collapse", response.rect.center());
@@ -69,7 +91,7 @@ fn header_impl(
};
let left = (icon_rect.right() + t.space_8).min(right);
let title_rect = egui::Rect::from_min_max(egui::pos2(left, rect.top()), egui::pos2(right.max(left), rect.bottom()));
- paint_text(ui, title_rect, title, crate::fonts::semibold(t.font_heading), t.form_ink, false);
+ paint_text(ui, title_rect, title, crate::fonts::semibold(if icon.0.is_empty() { t.font_label } else { t.font_heading }), t.form_ink, false);
let title_response = ui.interact(title_rect, ui.make_persistent_id("title_text"), egui::Sense::hover());
title_response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, ui.is_enabled(), title));
scenario::publish_rect("dialog:header", rect);
@@ -219,6 +241,8 @@ pub(crate) struct WorkspaceOptions<'a> {
pub fill_height: bool,
/// Use the minimum dock width without overwriting its remembered width.
pub compact: bool,
+ pub enabled: bool,
+ pub header_actions: Option<&'a mut dyn FnMut(&mut Ui)>,
}
pub(crate) struct FeatureOptions<'a> {
@@ -245,6 +269,21 @@ pub(crate) enum Part {
}
impl<'a> Panel<'a> {
+ /// Shared vertical dock policy: reserve room for a second card, then place it
+ /// below the measured first card with the standard container gap.
+ pub(crate) fn stack_first_bounds(mut bounds: egui::Rect) -> egui::Rect {
+ bounds.max.y = bounds.top()
+ + bounds
+ .height()
+ .min(Tokens::get().form_header_height + Tokens::get().control_height * 10.0 + Tokens::get().space_8 * 2.0)
+ .min((bounds.height() * 0.5).floor());
+ bounds
+ }
+
+ pub(crate) fn stack_next_bounds(mut bounds: egui::Rect, previous: egui::Rect) -> egui::Rect {
+ bounds.min.y = (previous.bottom() + Tokens::get().space_8).min(bounds.bottom());
+ bounds
+ }
/// Pinned inline actions inside an existing feature/card surface. This is not
/// a second window or painted card: the parent owns the chrome. Tokens:
/// control_height, space_24/8; bounded row count preserves finite geometry.
@@ -290,11 +329,12 @@ impl<'a> Panel<'a> {
/// side request, which the caller dispatches through its command. Neither gesture edits the document.
pub(crate) fn workspace<R>(
ui: &mut Ui,
- options: WorkspaceOptions<'_>,
+ mut options: WorkspaceOptions<'_>,
side: &mut String,
width: &mut f32,
add: impl FnOnce(&mut Ui) -> R,
) -> Option<egui::InnerResponse<(R, Option<&'static str>)>> {
+ let actions = options.header_actions.take();
Self::workspace_with_header(
ui,
options,
@@ -302,7 +342,7 @@ impl<'a> Panel<'a> {
width,
false,
|ui, options| {
- header_impl(ui, (options.icon, None), options.title, None, false, || {});
+ header_actions(ui, (options.icon, None), options.title, None, false, || {}, actions);
},
add,
)
@@ -353,6 +393,9 @@ impl<'a> Panel<'a> {
let (body, _) = ui.allocate_exact_size(size, egui::Sense::hover());
let mut child = ui.new_child(egui::UiBuilder::new().max_rect(body).id_salt("workspace_body"));
let ui = &mut child;
+ if !options.enabled {
+ ui.disable();
+ }
ui.set_clip_rect(ui.clip_rect().intersect(body));
ui.set_width(size.x);
ui.set_max_height(size.y);
@@ -390,7 +433,11 @@ impl<'a> Panel<'a> {
ui.ctx().request_repaint();
}
egui::Frame::NONE
- .inner_margin(if tree { egui::Margin::symmetric(0, t.space_4 as i8) } else { egui::Margin::same(t.space_12 as i8) })
+ .inner_margin(if tree {
+ egui::Margin::symmetric(0, t.space_4 as i8)
+ } else {
+ egui::Margin::same(if options.icon.is_empty() { t.space_10 } else { t.space_12 } as i8)
+ })
.show(ui, |ui| {
ui.spacing_mut().item_spacing.y = t.form_gap_y;
if tree {
diff --git a/crates/ui-egui/src/ui_kit/sphere.rs b/crates/ui-egui/src/ui_kit/sphere.rs
index 9fb290737f..fbfe9444d1 100644
--- a/crates/ui-egui/src/ui_kit/sphere.rs
+++ b/crates/ui-egui/src/ui_kit/sphere.rs
@@ -82,16 +82,26 @@ fn shade(key: Key, t: &Tokens) -> Mesh {
let z = (1.0 - r * r).max(0.0).sqrt();
let light = (-0.4 * x - 0.5 * y + 0.76 * z).max(0.0);
let specular = (-0.25 * x - 0.35 * y + 0.902 * z).max(0.0);
- let (diffuse, shine) = match key.kind {
+ let (diffuse, mut shine) = match key.kind {
FinishKind::Matte => (0.3 + 0.7 * light, 0.04 * specular.powi(8)),
FinishKind::Satin => (0.25 + 0.75 * light, 0.25 * specular.powi(16)),
FinishKind::Gloss => (0.2 + 0.8 * light, 0.85 * specular.powi(64)),
- FinishKind::Metal => (0.15 + 0.65 * light, 0.8 * specular.powi(24)),
+ FinishKind::Metal => (0.45 + 0.5 * light, 0.65 * specular.powi(16)),
FinishKind::Glass => (0.5 + 0.5 * light, (0.85 * specular.powi(64) + 0.4 * (1.0 - z).powi(3)).min(1.0)),
};
- let shaded = key.color.lerp_to_gamma(t.tab_on_fill_dark, 1.0 - diffuse);
- let highlight = if key.kind == FinishKind::Metal { key.color.lerp_to_gamma(t.on_accent, 0.65) } else { t.on_accent };
- let color = shaded.lerp_to_gamma(highlight, shine).gamma_multiply(f32::from(key.opacity) / 255.0);
+ let mut shaded = key.color.lerp_to_gamma(t.tab_on_fill_dark, 1.0 - diffuse);
+ if key.kind == FinishKind::Metal {
+ // Original studio sample: broad radial illumination, a curved horizon,
+ // a lower reflector and an oval softbox. All are bounded analytic fields.
+ let gradient = ((x + 0.28).hypot(y + 0.44) / 1.64).clamp(0.0, 1.0);
+ shaded = if gradient < 0.42 {
+ key.color.lerp_to_gamma(t.on_accent, 0.4 * (1.0 - gradient / 0.42))
+ } else {
+ key.color.lerp_to_gamma(t.tab_on_fill_dark, 0.66 * (gradient - 0.42) / 0.58)
+ };
+ shine = 0.0;
+ }
+ let color = shaded.lerp_to_gamma(t.on_accent, shine).gamma_multiply(f32::from(key.opacity) / 255.0);
mesh.colored_vertex(pos2(radius + x * radius, radius + y * radius), color);
if ring < RINGS && sector < SECTORS {
let a = ring * (SECTORS + 1) + sector;
@@ -126,6 +136,32 @@ pub(super) fn paint_sphere(ui: &Ui, rect: Rect, sphere: Sphere) {
vertex.pos = rect.min + vertex.pos.to_vec2() * scale;
}
ui.painter().add(egui::Shape::mesh(mesh));
+ if sphere.kind == FinishKind::Metal {
+ let radius = rect.width() / 2.0;
+ let at = |x: f32, y: f32| rect.center() + vec2(x, y) * radius;
+ let opacity = f32::from(key.opacity) / 255.0;
+ // Vector reflections stay smooth at small sizes without increasing cached mesh topology.
+ ui.painter().add(egui::epaint::QuadraticBezierShape::from_points_stroke(
+ [at(-0.965, 0.207), at(0.0, -0.138), at(0.965, 0.207)],
+ false,
+ Color32::TRANSPARENT,
+ egui::Stroke::new(radius * 0.069, t.tab_on_fill_dark.gamma_multiply(0.22 * opacity)),
+ ));
+ let ellipse = |center: egui::Pos2, radii: egui::Vec2, angle: f32, alpha: f32| {
+ let (sin, cos) = angle.sin_cos();
+ let points = (0..48)
+ .map(|index| {
+ let a = std::f32::consts::TAU * index as f32 / 48.0;
+ let x = radii.x * a.cos();
+ let y = radii.y * a.sin();
+ center + vec2(cos * x - sin * y, sin * x + cos * y)
+ })
+ .collect();
+ ui.painter().add(egui::Shape::convex_polygon(points, t.on_accent.gamma_multiply(alpha * opacity), egui::Stroke::NONE));
+ };
+ ellipse(at(0.0, 0.48), vec2(0.83, 0.21) * radius, 0.0, 0.16);
+ ellipse(at(-0.345, -0.483), vec2(0.38, 0.21) * radius, -32.0_f32.to_radians(), 0.55);
+ }
}
/// Clamps size to 1–96 logical points. Cache: 64 FIFO entries per egui context.
@@ -139,6 +175,82 @@ pub fn sphere_thumbnail(ui: &mut Ui, id: &str, sphere: Sphere, size: f32) -> Res
response
}
+/// A catalog sample: 48 pt sphere in a 56 pt cell, two-line caption and optional
+/// usage badge. The surrounding chrome follows the active workspace accent.
+pub(crate) struct SphereTile<'a> {
+ pub id: &'a str,
+ pub name: &'a str,
+ pub sphere: Sphere,
+ pub selected: bool,
+ pub users: usize,
+ pub tip: &'a str,
+}
+
+impl SphereTile<'_> {
+ pub(crate) fn show(&self, ui: &mut Ui) -> Response {
+ let t = Tokens::get();
+ let accent = crate::theme::TabAccent::current(ui.ctx());
+ let side = t.control_height * 2.0;
+ let height = side + t.space_3 + t.font_small * 2.5 + t.space_4;
+ let (rect, _) = ui.allocate_exact_size(vec2(ui.available_width(), height), Sense::hover());
+ let response = ui.interact(rect, ui.make_persistent_id(self.id), Sense::click());
+ let cell = Rect::from_min_size(pos2(rect.center().x - side / 2.0, rect.top() + t.space_4), vec2(side, side));
+ ui.painter().rect_filled(cell, t.radius_xl, t.control_fill);
+ ui.painter().rect_stroke(cell, t.radius_xl, t.control_border_stroke(t.dialog_rule), egui::StrokeKind::Inside);
+ if self.selected || response.hovered() || response.has_focus() {
+ ui.painter().rect_stroke(cell.expand(t.space_2), t.radius_xl, egui::Stroke::new(t.space_2, accent.ink), egui::StrokeKind::Outside);
+ }
+ paint_sphere(ui, cell.shrink(t.space_4), self.sphere);
+ if self.users > 0 {
+ let text = if self.users > 99 { "99+".into() } else { self.users.to_string() };
+ let galley = ui.painter().layout_no_wrap(text, crate::fonts::semibold(t.font_badge), t.on_accent);
+ let width = (galley.size().x + t.space_8).max(t.space_16);
+ let badge = Rect::from_min_size(pos2(cell.right() + t.space_2 - width, cell.top() - t.space_2), vec2(width, t.space_16));
+ ui.painter().rect_filled(badge, t.radius_lg, accent.ink);
+ ui.painter().galley(badge.center() - galley.size() / 2.0, galley, t.on_accent);
+ }
+ let label = Rect::from_min_max(pos2(rect.left(), cell.bottom() + t.space_3), rect.max);
+ let font = if self.selected { crate::fonts::semibold(t.font_small) } else { egui::FontId::proportional(t.font_small) };
+ let mut job = egui::text::LayoutJob::simple(self.name.to_owned(), font, t.form_ink, label.width());
+ job.halign = egui::Align::Center;
+ job.wrap.max_rows = 2;
+ job.wrap.break_anywhere = false;
+ let galley = ui.painter().layout_job(job);
+ ui.painter().with_clip_rect(ui.clip_rect().intersect(label)).galley(
+ pos2(label.center().x - galley.rect.center().x, label.top() - galley.rect.top()),
+ galley,
+ t.form_ink,
+ );
+ response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::Button, ui.is_enabled(), self.selected, self.name));
+ scenario::publish_target(self.id, rect);
+ let mut tip = egui::Tooltip::for_enabled(&response);
+ tip.popup = tip.popup.frame(super::Container::new(ui.ctx(), super::Surface::Toast).tooltip_frame(ui.ctx()));
+ tip.show(|ui| {
+ ui.label(self.tip);
+ });
+ response
+ }
+}
+
+/// Fixed-column catalog composition. Tile geometry and gaps stay with the kit.
+pub(crate) fn sphere_grid(ui: &mut Ui, tiles: &[SphereTile<'_>]) -> Option<usize> {
+ let t = Tokens::get();
+ let mut clicked = None;
+ ui.spacing_mut().item_spacing = vec2(t.space_2, t.space_8);
+ for (row, chunk) in tiles.chunks(3).enumerate() {
+ ui.columns(3, |columns| {
+ for (column, tile) in chunk.iter().enumerate() {
+ if let Some(ui) = columns.get_mut(column)
+ && tile.show(ui).clicked()
+ {
+ clicked = Some(row * 3 + column);
+ }
+ }
+ });
+ }
+ clicked
+}
+
#[cfg(test)]
#[path = "sphere_tests.rs"]
mod tests;
diff --git a/crates/ui-egui/src/ui_kit/sphere_tests.rs b/crates/ui-egui/src/ui_kit/sphere_tests.rs
index ca3f1da20d..65a4033053 100644
--- a/crates/ui-egui/src/ui_kit/sphere_tests.rs
+++ b/crates/ui-egui/src/ui_kit/sphere_tests.rs
@@ -1,5 +1,53 @@
use super::*;
+#[test]
+fn tiles_keep_three_columns_cell_sphere_badge_and_selection_in_both_themes() {
+ for dark in [false, true] {
+ crate::theme::set_dark(dark);
+ let ctx = crate::fonts::test_context();
+ let t = Tokens::get();
+ let output = crate::test_support::frame(
+ &ctx,
+ egui::RawInput { screen_rect: Some(Rect::from_min_size(egui::Pos2::ZERO, vec2(320.0, 400.0))), ..Default::default() },
+ |ui| {
+ ui.set_width(240.0);
+ super::super::scope(ui, |ui| {
+ let tiles = ["a", "b", "c"].map(|id| SphereTile {
+ id,
+ name: "Satin",
+ sphere: Sphere { color: t.render_accent, kind: FinishKind::Satin, opacity: None },
+ selected: id == "b",
+ users: usize::from(id == "a"),
+ tip: "Hover details",
+ });
+ assert!(sphere_grid(ui, &tiles).is_none());
+ });
+ },
+ );
+ assert!(
+ !output.shapes.iter().any(|shape| matches!(&shape.shape,egui::Shape::Text(text) if text.galley.job.text.contains("Hover details"))),
+ "hover cards must stay closed without a pointer"
+ );
+ let a = crate::scenario::rect_of("a").unwrap();
+ let b = crate::scenario::rect_of("b").unwrap();
+ let c = crate::scenario::rect_of("c").unwrap();
+ assert_eq!(a.top(), b.top());
+ assert_eq!(b.top(), c.top());
+ assert!(a.right() < b.left() && b.right() < c.left());
+ fn meshes(shape: &egui::Shape) -> usize {
+ match shape {
+ egui::Shape::Mesh(_) => 1,
+ egui::Shape::Vec(shapes) => shapes.iter().map(meshes).sum(),
+ _ => 0,
+ }
+ }
+ assert_eq!(output.shapes.iter().map(|shape| meshes(&shape.shape)).sum::<usize>(), 3);
+ let accent = crate::theme::TabAccent::current(&ctx);
+ assert!(output.shapes.iter().any(|shape| matches!(&shape.shape,egui::Shape::Rect(r) if r.stroke.color==accent.ink && r.rect.width()==60.0)));
+ assert!(output.shapes.iter().any(|shape| matches!(&shape.shape,egui::Shape::Rect(r) if r.rect.size()==vec2(56.0,56.0))));
+ }
+}
+
#[test]
fn cache_bounds_a_thousand_distinct_inputs_and_evicts_oldest() {
let t = Tokens::light();
diff --git a/crates/ui-egui/tests/scenarios/render_workspace_shell.json b/crates/ui-egui/tests/scenarios/render_workspace_shell.json
index b450c3c4da..ac749d745a 100644
--- a/crates/ui-egui/tests/scenarios/render_workspace_shell.json
+++ b/crates/ui-egui/tests/scenarios/render_workspace_shell.json
@@ -3,12 +3,13 @@
{"call":"ui.resize","params":{"width":1440,"height":1000}},
{"call":"engine.execute","params":{"command":"solid.box","params":{"length":20,"width":15,"height":10}}},
{"call":"ui.workspace","params":{"workspace":"render"}},
- {"expect":{"shown_handles":["render:stage:look","render:stage:light","render:stage:frame","render:stage:output","render:stage:render.start","render:stage:render.cancel","ribbon:search","render:shots:hide","render:inspector:grip","render:browser:grip"],"hidden_handles":["tab:RENDER","tab:RENDER APPEARANCE","ribbon:section:RENDER:IMAGE"],"errors":0}},
+ {"expect":{"shown_handles":["render:stage:look","render:stage:light","render:stage:frame","render:stage:output","render:stage:render.start","render:stage:render.cancel","ribbon:search","render:shots:hide","render:inspector:grip","render:browser:grip","render:appearances:grip","render:library-search","render:library-grid","render:library-list"],"hidden_handles":["tab:RENDER","tab:RENDER APPEARANCE","ribbon:section:RENDER:IMAGE"],"errors":0}},
{"click":{"handle":"render:stage:look"}},
{"click":{"handle":"render:stage:light"}},
{"click":{"handle":"render:stage:frame"}},
{"click":{"handle":"render:stage:output"}},
{"expect":{"disjoint":["render:browser:header","render:tree:environment"]}},
+ {"expect":{"disjoint":["render:browser:header","render:appearances:header"]}},
{"expect":{"disjoint":["render:inspector:header","render:page:output"]}},
{"click":{"handle":"render:shots:hide"}},
{"expect":{"shown_handles":["render:shots:show"],"hidden_handles":["render:shots:hide"]}},
diff --git a/docs/render-workspace.md b/docs/render-workspace.md
index 93ad643a28..5595a855e5 100644
--- a/docs/render-workspace.md
+++ b/docs/render-workspace.md
@@ -33,14 +33,31 @@ light coordinate frame remains disabled with its reason in this checkout. Frame
uses the existing explicit camera command for projection; Output shows the current
size/format and directs edits to the Output Inspector. No completion ticks are inferred.
-The Browser and Inspector float in both shell layouts, share top and bottom edges,
-and clear the bar and Shots strip by 8 pt. Their default outer widths are 266 pt and 305 pt, with the shared resize bounds.
-The 48 pt Shots strip has an 8 pt gap from the docks. The 110 pt compass uses the
-free canvas beside the Inspector and the navigation bar keeps its shared navigation handler. Narrow
-rows scroll horizontally; docks shrink together or disappear if no usable space
-remains. The Shots strip's independent `view.shots_strip` preference is unchanged.
-The current model/library Browser can reveal model bodies for Look; scene-specific
-Lights, Shots and Output expansion awaits the scene Browser change.
+The Browser and Inspector float in both shell layouts and share a top edge, 8 pt
+below the bar. Their default outer widths are 266 pt and 305 pt, with shared resize
+bounds. The Browser keeps the upper left card (up to ten compact scene rows); its
+stage panel fills the remaining height below it, ending 8 pt above the 48 pt Shots
+strip. Both cards share width and side preferences. Narrow windows shorten the
+Browser to reserve library space, then omit cards that cannot fit safely.
+
+Look hosts Appearances: search with the actual catalog count, In Design / Library /
+Recent / favorites scopes, horizontally scrolling category chips and a three-column
+sphere grid or list. Resources used in the design or matching a selected look's
+finish family or category appear first. Clicking a look applies through
+`appearance.assign` to selected bodies, faces or components; with no target it
+only inspects. Favorites and recent history live in user preferences. Explicit
+catalog navigation from the Inspector retains the read-only resource browser.
+
+Light hosts the existing native studios and HDR environments in the same tile grid.
+A click runs `render.preset.apply` or `render.library.environment.apply`, preserving
+those commands' validation and undo behavior. Studios require an explicitly selected
+GPU path setup; environments require CPU or GPU ray tracing. Frame and Output show
+faded Frame presets / Size presets placeholders with their Shot editor / Output
+editor reasons. Stage navigation itself never applies a resource.
+
+The 110 pt compass uses the free canvas beside the Inspector; the navigation bar
+keeps its shared handler. The Shots strip's independent `view.shots_strip`
+preference is unchanged.
`view.render_focus {on: true}` hides the Browser, Inspector and Shots strip and
releases their canvas reservations. Tab toggles focus while Render is active and
diff --git a/docs/ui-kit.md b/docs/ui-kit.md
index 15190a3ea9..2f44ed0a67 100644
--- a/docs/ui-kit.md
+++ b/docs/ui-kit.md
@@ -52,8 +52,10 @@ rules. Its compass is 110 pt; the 48 pt Shots strip clears the docks by 8 pt.
Panel/Window header and padded body, with no second top inset below the ribbon.
Persistent workspace cards omit the close action. `Panel::workspace_with_header` lets tree cards
compose the shared `tree_header` (title, compact lens and quiet search action). Its tree policy
- shares the full dock height and lets rows own their 8 pt side insets; header navigation
- retains a separate title grip. `Panel::bottom_strip`
+ caps the card at ten 28 pt rows and lets rows own their 8 pt side insets; header navigation
+ retains a separate title grip. Optional header actions share the same title band.
+ `stack_first_bounds` reserves a bounded Browser above its companion;
+ `stack_next_bounds` places that companion with the shared gap. `Panel::bottom_strip`
uses `Container::bottom_strip_rect`, the same placement as Design History.
`Container::navigation_card` supplies the shared Navigation surface for anchored HUDs.
Register measured card rectangles and reserved edges with `shell::register_panel` so
@@ -156,6 +158,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
| `tool_choices`, `ToolChoice`, `toggle_icon` | Wrapped command modes or independent icon toggles | sketch mode/icon tokens, `accent` |
| `list_picker` | Selectable row with caller identity and native checked state | `control_height`, form selection tokens |
| `popup_list`, `PopupOption` | Focus-neutral suggestions; owner retains keyboard routing | `space_2`, `form_label_width`, `control_height`, form tokens |
+| sphere: `sphere_thumbnail`, `SphereTile`, `sphere_grid` | Deterministic lit material samples; matte/satin/gloss/metal/glass finishes. Catalog tiles centre a 48 pt sphere in a 56 pt rounded cell with a two-line name, active-tab selection ring, user-count badge and shared Container tooltip. The grid owns three columns and token gaps. | `control_height`, `radius_xl`, `space_2/3/4/8/16`, `font_small/badge`, `control_fill`, `dialog_rule`, active-tab accent, `on_accent` |
| `color_swatch`, `swatch_grid`, `color_thumbnail` | 30 pt draggable samples, 6 pt grid step gap, selected outer ring and checker pattern under transparent colours; caller payloads retained; local-library thumbnails use 16 pt | `control_height/radius`, `border`, `form_primary`, `control_fill`, `space_2/6/8` |
| `assistant_entry`, `AssistantEntryState` | Application-bar chat icon with quiet, ready, busy, auth, stopped and approval count marks; caller owns state and target | `app_bar`, `agent_ok/busy`, `warning/error`, `font_badge` |
| actions: `button`, `Button` | Secondary action: `Normal`, `Small`, or `Enabled(bool)` | native sizing, form font/control tokens |
@@ -711,3 +714,9 @@ with Body active, and an empty chain with Face active in both themes.
For CPU-rendered review images, run
`SOLIDCRAFT_MATERIAL_WIDGET_EVIDENCE=/tmp/material-widgets cargo test -p solidcraft-ui-egui ui_kit::gallery::material_widgets_board_in_both_themes`.
+
+`catalog_scope` supplies compact catalog metrics to the shared search field, segments,
+icon segments and category chips. `catalog_footer` draws the quiet information hint.
+Catalog title marks use the active workspace accent; tile captions, usage badges and
+selection outlines share the sphere widgets. Feature code supplies data and commands,
+while the kit owns every dimension, colour and inset.