Render shots: strip with thumbnails, Update and Revert for camera changes (#6430)
This commit is contained in:
1 parent
ad182057b9
commit
c1dee61482
25 files changed
+1139
-57
No files matched your search
@@ -0,0 +1,83 @@
|
||||
{
|
||||
"en": {
|
||||
"render.shots_camera_changed": "Camera changed since this shot was saved",
|
||||
"render.shots_name_help": "Enter a unique name for the current shot.",
|
||||
"render.shots_no_result": "No render yet",
|
||||
"render.shots_result": "Render {number} · {width} × {height}",
|
||||
"render.shots_revert": "Revert",
|
||||
"render.shots_save": "Save Shot",
|
||||
"render.shots_update": "Update shot"
|
||||
},
|
||||
"de": {
|
||||
"render.shots_camera_changed": "Die Kamera wurde seit dem Speichern dieser Aufnahme geändert",
|
||||
"render.shots_name_help": "Geben Sie einen eindeutigen Namen für die aktuelle Aufnahme ein.",
|
||||
"render.shots_no_result": "Noch kein Renderbild",
|
||||
"render.shots_result": "Rendering {number} · {width} × {height}",
|
||||
"render.shots_revert": "Zurücksetzen",
|
||||
"render.shots_save": "Aufnahme speichern",
|
||||
"render.shots_update": "Aufnahme aktualisieren"
|
||||
},
|
||||
"ja": {
|
||||
"render.shots_camera_changed": "このショットの保存後にカメラが変更されました",
|
||||
"render.shots_name_help": "現在のショットに一意の名前を入力してください。",
|
||||
"render.shots_no_result": "レンダリング結果なし",
|
||||
"render.shots_result": "レンダー {number} · {width} × {height}",
|
||||
"render.shots_revert": "元に戻す",
|
||||
"render.shots_save": "ショットを保存",
|
||||
"render.shots_update": "ショットを更新"
|
||||
},
|
||||
"zh": {
|
||||
"render.shots_camera_changed": "相机已在此镜头保存后发生变化",
|
||||
"render.shots_name_help": "请输入当前镜头的唯一名称。",
|
||||
"render.shots_no_result": "尚无渲染结果",
|
||||
"render.shots_result": "渲染 {number} · {width} × {height}",
|
||||
"render.shots_revert": "还原",
|
||||
"render.shots_save": "保存镜头",
|
||||
"render.shots_update": "更新镜头"
|
||||
},
|
||||
"ko": {
|
||||
"render.shots_camera_changed": "이 샷을 저장한 후 카메라가 변경되었습니다",
|
||||
"render.shots_name_help": "현재 샷의 고유한 이름을 입력하세요.",
|
||||
"render.shots_no_result": "렌더링 결과 없음",
|
||||
"render.shots_result": "렌더 {number} · {width} × {height}",
|
||||
"render.shots_revert": "되돌리기",
|
||||
"render.shots_save": "샷 저장",
|
||||
"render.shots_update": "샷 업데이트"
|
||||
},
|
||||
"ar": {
|
||||
"render.shots_camera_changed": "تغيّرت الكاميرا منذ حفظ هذه اللقطة",
|
||||
"render.shots_name_help": "أدخل اسمًا فريدًا للقطة الحالية.",
|
||||
"render.shots_no_result": "لا يوجد تصيير بعد",
|
||||
"render.shots_result": "التصيير {number} · {width} × {height}",
|
||||
"render.shots_revert": "استرجاع",
|
||||
"render.shots_save": "حفظ اللقطة",
|
||||
"render.shots_update": "تحديث اللقطة"
|
||||
},
|
||||
"he": {
|
||||
"render.shots_camera_changed": "המצלמה השתנתה מאז שמירת הצילום",
|
||||
"render.shots_name_help": "הזן שם ייחודי לצילום הנוכחי.",
|
||||
"render.shots_no_result": "עדיין אין רינדור",
|
||||
"render.shots_result": "רינדור {number} · {width} × {height}",
|
||||
"render.shots_revert": "שחזר",
|
||||
"render.shots_save": "שמור צילום",
|
||||
"render.shots_update": "עדכן צילום"
|
||||
},
|
||||
"vi": {
|
||||
"render.shots_camera_changed": "Máy ảnh đã đổi kể từ khi lưu cảnh chụp này",
|
||||
"render.shots_name_help": "Nhập tên duy nhất cho cảnh chụp hiện tại.",
|
||||
"render.shots_no_result": "Chưa kết xuất",
|
||||
"render.shots_result": "Kết xuất {number} · {width} × {height}",
|
||||
"render.shots_revert": "Hoàn nguyên",
|
||||
"render.shots_save": "Lưu cảnh chụp",
|
||||
"render.shots_update": "Cập nhật cảnh chụp"
|
||||
},
|
||||
"da": {
|
||||
"render.shots_camera_changed": "Kameraet er ændret, siden denne optagelse blev gemt",
|
||||
"render.shots_name_help": "Indtast et unikt navn til den aktuelle optagelse.",
|
||||
"render.shots_no_result": "Ingen rendering endnu",
|
||||
"render.shots_result": "Rendering {number} · {width} × {height}",
|
||||
"render.shots_revert": "Gendan",
|
||||
"render.shots_save": "Gem optagelse",
|
||||
"render.shots_update": "Opdater optagelse"
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ CommandSpec::new("view.render_stage", "Render Stage", render_stage)
|
||||
.icon("render_scene").noundo().doc_only()
|
||||
.params("stage: look|light|frame|output → {stage}; per-document UI state, never edits or evaluates the design; headless validation only"),
|
||||
CommandSpec::new("view.shots_strip", "Shots Strip", shots_strip)
|
||||
.at("RENDER CAMERA", "SHOTS").icon("camera").noundo().doc_only()
|
||||
.icon("camera").noundo().doc_only()
|
||||
.params("visible: bool → {visible}; Render Shots strip UI preference. Headless echo only, no document edits or undo"),
|
||||
CommandSpec::new("view.render_dock", "Move Render Dock", crate::checked!("view.render_dock", render_dock))
|
||||
.at("RENDER", "SCENE").icon("settings").noundo().doc_only()
|
||||
|
||||
@@ -689,7 +689,6 @@ mod tests {
|
||||
"BATCH",
|
||||
"Shots",
|
||||
"Shots Strip",
|
||||
"Strip",
|
||||
"Pick",
|
||||
"Component",
|
||||
"The live preview shows direct light only and no shadows.",
|
||||
@@ -710,6 +709,10 @@ mod tests {
|
||||
"render.tree_browser",
|
||||
"render.tree_search",
|
||||
"render.tree_more",
|
||||
"render.shots_save",
|
||||
"render.shots_name_help",
|
||||
"render.shots_no_result",
|
||||
"render.shots_result",
|
||||
"render.studios_environments",
|
||||
"render.frame_presets",
|
||||
"render.size_presets",
|
||||
|
||||
@@ -154,6 +154,17 @@ fn stage_tools(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
{
|
||||
app.set_status(error, true);
|
||||
}
|
||||
if let Some(command) = solidcraft_engine::find_command("render.settings.set") {
|
||||
let info = crate::render_workspace::interactive_command_info(app, command);
|
||||
let response = ui_kit::compact_icon_label_button(ui, app.tr("render.shots_save"), command.icon, info.enabled);
|
||||
crate::scenario::publish_target("render:stage:save_shot", response.rect);
|
||||
if response.clicked() {
|
||||
app.start(command.id);
|
||||
}
|
||||
if let Some(reason) = info.disabled_reason {
|
||||
response.on_disabled_hover_text(reason);
|
||||
}
|
||||
}
|
||||
}
|
||||
Stage::Output => {
|
||||
ui.add_enabled_ui(false, |ui| {
|
||||
@@ -227,8 +238,7 @@ fn shots_pill(app: &mut SolveApp, ui: &mut egui::Ui, free: Rect) {
|
||||
free.left_bottom() + vec2(Tokens::get().space_8, -Tokens::get().space_8),
|
||||
egui::Align2::LEFT_BOTTOM,
|
||||
|ui| {
|
||||
let response =
|
||||
ui_kit::button(ui, crate::i18n::tr_label("Shots"), ui_kit::Button::Normal).on_hover_text(crate::i18n::tr_label("Show Shots strip"));
|
||||
let response = ui_kit::strip_toggle(ui, false, crate::i18n::tr_label("Shots")).on_hover_text(crate::i18n::tr_label("Show Shots strip"));
|
||||
crate::scenario::publish_target("render:shots:show", response.rect);
|
||||
if response.clicked() {
|
||||
let _ = app.run("view.shots_strip", serde_json::json!({"visible":true}));
|
||||
@@ -245,40 +255,8 @@ pub(crate) fn shots_strip(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
return;
|
||||
}
|
||||
let available = ui.available_rect_before_wrap();
|
||||
let content = ui_kit::Panel::bottom_strip(ui, "sc_render_shots_strip", available, 48.0, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let hide = ui_kit::button(ui, crate::i18n::tr_label("Hide"), ui_kit::Button::Normal)
|
||||
.on_hover_text(crate::i18n::tr_label("Hide Shots strip"));
|
||||
crate::scenario::publish_target("render:shots:hide", hide.rect);
|
||||
if hide.clicked() {
|
||||
let _ = app.run("view.shots_strip", serde_json::json!({"visible":false}));
|
||||
}
|
||||
let ready = crate::render_workspace::job_ready(app, "render.start");
|
||||
let render = ui_kit::button(ui, app.tr("render.image_start"), ui_kit::Button::Enabled(ready.is_ok()));
|
||||
let render = if let Err(reason) = ready { render.on_disabled_hover_text(reason) } else { render };
|
||||
crate::scenario::publish_target("render:shots:render", render.rect);
|
||||
if render.clicked() {
|
||||
app.start("render.start");
|
||||
}
|
||||
let names: Vec<_> = app.session.doc.render.setups.keys().cloned().collect();
|
||||
egui::ScrollArea::horizontal()
|
||||
.id_salt("render_shots_names")
|
||||
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden)
|
||||
.show(ui, |ui| {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui_kit::text(ui, crate::i18n::tr_label("Shots"), ui_kit::Text::Inline);
|
||||
for name in names {
|
||||
let shot = ui_kit::choice_chip(ui, &name, &name, name == app.render_workspace.view.name);
|
||||
crate::scenario::publish_target(&format!("render:shots:setup:{name}"), shot.rect);
|
||||
if shot.clicked() {
|
||||
crate::render_workspace::switch_shot(app, name);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
let content = ui_kit::Panel::bottom_strip(ui, "sc_render_shots_strip", available, Tokens::get().form_footer_height, |ui| {
|
||||
crate::render_workspace::shots::contents(app, ui);
|
||||
});
|
||||
let rect = content.map(|c| c.response.rect);
|
||||
crate::shell::register_panel(app, "render:shots_strip", rect, Some(Edge::Bottom));
|
||||
|
||||
@@ -43,6 +43,9 @@ mod materials;
|
||||
#[path = "render_workspace_setups.rs"]
|
||||
mod setups;
|
||||
|
||||
#[path = "render_workspace_shots.rs"]
|
||||
pub(crate) mod shots;
|
||||
|
||||
#[path = "render_ui/scene.rs"]
|
||||
pub(crate) mod scene;
|
||||
|
||||
@@ -51,6 +54,9 @@ mod studio;
|
||||
#[path = "render_workspace_transport.rs"]
|
||||
mod transport;
|
||||
|
||||
#[path = "render_workspace_thumbnails.rs"]
|
||||
mod thumbnails;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "render_workspace_tests.rs"]
|
||||
mod tests;
|
||||
@@ -58,6 +64,7 @@ mod tests;
|
||||
type PathFactory = Box<dyn FnOnce() -> Result<ImageHost, String> + Send>;
|
||||
|
||||
pub struct State {
|
||||
thumbnails: thumbnails::Cache,
|
||||
pending_setup: Option<PathFactory>,
|
||||
pub host: Option<ExecutorDescriptor>,
|
||||
pub path_host: PathHost,
|
||||
@@ -259,6 +266,8 @@ pub enum RenderSelection {
|
||||
/// Small per-document editor state; GPU uploads and host capabilities stay outside tabs.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ViewState {
|
||||
job_shot: Option<String>,
|
||||
save_shot_name: Option<String>,
|
||||
pub name: String,
|
||||
pub selection: RenderSelection,
|
||||
pub(crate) stage: Stage,
|
||||
@@ -318,6 +327,8 @@ impl ImageMethod {
|
||||
impl Default for ViewState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
job_shot: None,
|
||||
save_shot_name: None,
|
||||
name: "Studio".into(),
|
||||
selection: RenderSelection::Nothing,
|
||||
stage: Stage::Look,
|
||||
@@ -353,6 +364,7 @@ impl Default for ViewState {
|
||||
impl Default for State {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
thumbnails: Default::default(),
|
||||
host: None,
|
||||
path_host: PathHost::default(),
|
||||
pending_setup: None,
|
||||
@@ -521,6 +533,7 @@ pub(crate) fn invalidate_images(app: &mut SolveApp) {
|
||||
}
|
||||
|
||||
pub fn invalidate_scene(app: &mut SolveApp) {
|
||||
app.render_workspace.thumbnails = Default::default();
|
||||
app.render_workspace.revision = u64::MAX;
|
||||
app.render_workspace.scene_signature = None;
|
||||
app.render_workspace.scene = None;
|
||||
|
||||
@@ -415,6 +415,7 @@ fn perform_action(app: &mut SolveApp, action: PendingAction) -> Result<(), Strin
|
||||
Ok(())
|
||||
}
|
||||
fn confirmation(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
super::shots::confirmation(app, ctx);
|
||||
let Some(pending) = app.render_workspace.view.inspector.pending.clone() else { return };
|
||||
if pending.revision != app.session.revision || !Weak::ptr_eq(&pending.document, &Arc::downgrade(&app.session.doc)) {
|
||||
app.render_workspace.view.inspector.pending = None;
|
||||
@@ -662,6 +663,27 @@ pub(super) fn apply_camera_draft(app: &mut SolveApp, camera: solidcraft_engine::
|
||||
}
|
||||
|
||||
fn camera_controls(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
if super::shots::camera_modified(app, &app.render_workspace.view.name) {
|
||||
ui_kit::banner(ui, ui_kit::AssistantTone::Warning, |ui| {
|
||||
ui_kit::text(ui, app.tr("render.shots_camera_changed"), ui_kit::Text::Note("render.shots_camera_changed"));
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
let update = ui_kit::primary_button(ui, app.tr("render.shots_update"));
|
||||
crate::scenario::publish_target("render:shots:update", update.rect);
|
||||
if update.clicked()
|
||||
&& let Err(error) = super::shots::update_camera(app)
|
||||
{
|
||||
app.set_status(error, true);
|
||||
}
|
||||
let revert = ui_kit::button(ui, app.tr("render.shots_revert"), ui_kit::Button::Normal);
|
||||
crate::scenario::publish_target("render:shots:revert", revert.rect);
|
||||
if revert.clicked()
|
||||
&& let Err(error) = restore_camera(app)
|
||||
{
|
||||
app.set_status(error, true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
ui_kit::text(ui, app.tr("render.camera_exact_help"), ui_kit::Text::Note("render.camera_exact_help"));
|
||||
let before = app.cam;
|
||||
let mut camera = before;
|
||||
@@ -1133,7 +1155,7 @@ fn camera_actions(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
|
||||
pub(super) fn confirmation_open(app: &SolveApp) -> bool {
|
||||
app.render_workspace.view.inspector.pending.is_some()
|
||||
app.render_workspace.view.inspector.pending.is_some() || app.render_workspace.view.save_shot_name.is_some()
|
||||
}
|
||||
pub(super) fn reveal(app: &mut SolveApp, section: &'static str) {
|
||||
app.render_workspace.view.inspector.reveal = Some(section);
|
||||
|
||||
@@ -133,6 +133,7 @@ pub(super) fn perform_job(app: &mut SolveApp, id: &str) -> Result<(), String> {
|
||||
let job = serde_json::from_value(reply["job"].clone())
|
||||
.map_err(|e| crate::i18n::format("render.error_job_identity", &[("error", &e.to_string())]))?;
|
||||
app.render_workspace.view.job = Some(job);
|
||||
app.render_workspace.view.job_shot = Some(app.render_workspace.view.name.clone());
|
||||
}
|
||||
"render.result.regrade" => {
|
||||
let source = app.render_workspace.view.completed.ok_or_else(|| app.tr("render.ribbon_no_result").to_string())?;
|
||||
@@ -213,7 +214,7 @@ fn navigate(app: &mut SolveApp, id: &str) -> Result<(), String> {
|
||||
focus(app, Page::Scene, None);
|
||||
inspector::reveal(app, "render_shot_manager");
|
||||
}
|
||||
"render.settings.set" => setups::save(app)?,
|
||||
"render.settings.set" => app.render_workspace.view.save_shot_name = Some(String::new()),
|
||||
"render.library.appearance.apply" | "render.optics.bind" | "render.optics.unbind" => focus(app, Page::Appearance, Some("surfaces")),
|
||||
"render.library.surface.bind" | "render.library.surface.prepare" | "render.library.surface.unbind" => {
|
||||
focus(app, Page::Appearance, Some("surfaces"));
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
//! Shot strip adapters. Commands own saved intent; the kit owns every control and layout.
|
||||
use crate::{SolveApp, ui_kit};
|
||||
use serde_json::json;
|
||||
use solidcraft_engine::{doc::render_settings::RenderSettings, render::job::Phase};
|
||||
|
||||
pub(super) const SIZE_PRESETS: [(&str, u32, u32); 3] = [("HD", 1280, 720), ("Full HD", 1920, 1080), ("4K UHD", 3840, 2160)];
|
||||
|
||||
pub(super) fn camera_modified(app: &SolveApp, name: &str) -> bool {
|
||||
app.session.doc.render.setups.get(name).is_some_and(|setup| setup.camera != app.cam)
|
||||
}
|
||||
|
||||
/// Update just the saved camera, preserving all the shot's other saved intent.
|
||||
pub(super) fn update_camera(app: &mut SolveApp) -> Result<(), String> {
|
||||
let name = app.render_workspace.view.name.clone();
|
||||
app.run("render.settings.set", json!({"name":name,"set":{"camera":app.cam}}))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn contents(app: &mut SolveApp, ui: &mut egui::Ui) {
|
||||
super::thumbnails::refresh(app, ui.ctx());
|
||||
let status = app.render_workspace.view.job.and_then(|job| app.session.render_job_handle(job).ok()).and_then(|handle| handle.status().ok());
|
||||
let progress = status
|
||||
.as_ref()
|
||||
.filter(|s| matches!(s.progress.phase, Phase::Queued | Phase::Preparing | Phase::Running | Phase::Encoding | Phase::Cancelling))
|
||||
.map(|s| (s.progress.done as f64 / s.progress.total.max(1) as f64).clamp(0.0, 1.0) as f32);
|
||||
if progress.is_some() {
|
||||
ui.ctx().request_repaint_after(std::time::Duration::from_millis(100));
|
||||
}
|
||||
let ready = super::job_ready(app, "render.start");
|
||||
let draft = &app.render_workspace.view.draft;
|
||||
let size_label = format!("{} × {}", draft.width, draft.height);
|
||||
let completed = app
|
||||
.render_workspace
|
||||
.view
|
||||
.completed
|
||||
.and_then(|job| app.session.render_job_handle(job).ok())
|
||||
.and_then(|handle| handle.frame().ok().flatten())
|
||||
.map(|frame| frame.info.clone());
|
||||
let result_label = completed
|
||||
.as_ref()
|
||||
.map(|frame| {
|
||||
crate::i18n::format(
|
||||
"render.shots_result",
|
||||
&[("number", &frame.job.serial.to_string()), ("width", &frame.width.to_string()), ("height", &frame.height.to_string())],
|
||||
)
|
||||
})
|
||||
.unwrap_or_else(|| app.tr("render.shots_no_result").to_string());
|
||||
let (mut hide, mut start, mut save, mut chosen, mut size) = (false, false, false, None, None);
|
||||
let mut visible = Vec::new();
|
||||
ui_kit::Panel::strip_contents(
|
||||
ui,
|
||||
|ui| {
|
||||
let response = ui_kit::strip_toggle(ui, true, crate::i18n::tr_label("Hide Shots strip"));
|
||||
crate::scenario::publish_target("render:shots:hide", response.rect);
|
||||
hide = response.clicked();
|
||||
let response = ui_kit::icon_label_action(ui, app.tr("cmd.render_start"), Some("play"), ready.is_ok(), true);
|
||||
let response = if let Err(reason) = &ready { response.on_disabled_hover_text(reason) } else { response };
|
||||
crate::scenario::publish_target("render:shots:render", response.rect);
|
||||
start = response.clicked();
|
||||
let response = ui_kit::compact_dropdown_menu(ui, "render_shots_size", &size_label, |ui| {
|
||||
for (label, width, height) in SIZE_PRESETS {
|
||||
if ui_kit::list_picker(ui, label, &format!("{label} · {width} × {height}"), draft.width == width && draft.height == height)
|
||||
.clicked()
|
||||
{
|
||||
size = Some((width, height));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
crate::scenario::publish_target("render:shots:size", response.rect);
|
||||
let response = ui_kit::completion_text(ui, &result_label, completed.is_some());
|
||||
crate::scenario::publish_rect("render:shots:status", response.rect);
|
||||
},
|
||||
|ui| {
|
||||
let heading = ui_kit::StripHeading::new(ui.painter(), crate::i18n::tr_label("Shots"));
|
||||
let response = heading.show(ui);
|
||||
crate::scenario::publish_rect("render:shots:heading", response.rect);
|
||||
let response = ui.add_enabled_ui(super::setups::snapshot(app).is_ok(), |ui| ui_kit::add_choice(ui, app.tr("render.shots_save"))).inner;
|
||||
crate::scenario::publish_target("render:shots:save", response.rect);
|
||||
save = response.clicked();
|
||||
for name in app.session.doc.render.setups.keys() {
|
||||
let active = name == &app.render_workspace.view.name;
|
||||
let response = ui_kit::thumbnail_choice(
|
||||
ui,
|
||||
&format!("shot:{name}"),
|
||||
name,
|
||||
ui_kit::ThumbnailChoice {
|
||||
texture: app.render_workspace.thumbnails.texture(name),
|
||||
selected: active,
|
||||
modified: active && camera_modified(app, name),
|
||||
progress: if app.render_workspace.view.job_shot.as_ref() == Some(name) { progress } else { None },
|
||||
},
|
||||
);
|
||||
crate::scenario::publish_target(&format!("render:shots:setup:{name}"), response.rect);
|
||||
if visible.len() < super::thumbnails::LIMIT && response.rect.intersects(ui.clip_rect()) {
|
||||
visible.push(name.clone());
|
||||
}
|
||||
if response.clicked() {
|
||||
chosen = Some(name.clone());
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
app.render_workspace.thumbnails.show(visible, ui.ctx());
|
||||
if hide {
|
||||
let _ = app.run("view.shots_strip", json!({"visible":false}));
|
||||
}
|
||||
if start {
|
||||
app.start("render.start");
|
||||
}
|
||||
if save {
|
||||
app.start("render.settings.set");
|
||||
}
|
||||
if let Some(name) = chosen {
|
||||
super::switch_shot(app, name);
|
||||
}
|
||||
if let Some((width, height)) = size {
|
||||
app.render_workspace.view.draft.width = width;
|
||||
app.render_workspace.view.draft.height = height;
|
||||
app.render_workspace.view.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn confirmation(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
let Some(mut name) = app.render_workspace.view.save_shot_name.take() else { return };
|
||||
let valid = RenderSettings::validate_name(name.trim()).is_ok() && !app.session.doc.render.setups.contains_key(name.trim());
|
||||
let title = app.tr("render.shots_save").to_string();
|
||||
let cancel = app.tr("ui.cancel").to_string();
|
||||
let (closed, answer) =
|
||||
ui_kit::Confirm::new(egui::Id::new("render_save_shot"), "save", &title).actions(&title, &cancel, None).show(ctx, valid, |ui| {
|
||||
ui_kit::text(ui, app.tr("render.shots_name_help"), ui_kit::Text::Note("render.shots_name_help"));
|
||||
ui_kit::row(ui, app.tr("render.shot_new_name"), |ui| {
|
||||
ui_kit::focused_text_field(ui, &mut name, "");
|
||||
});
|
||||
});
|
||||
if closed || answer == ui_kit::Action::Cancel {
|
||||
return;
|
||||
}
|
||||
if answer == ui_kit::Action::Ok {
|
||||
let previous = app.render_workspace.view.name.clone();
|
||||
app.render_workspace.view.name = name.trim().to_owned();
|
||||
if let Err(error) = super::setups::save(app) {
|
||||
app.render_workspace.view.name = previous;
|
||||
app.set_status(error, true);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
app.render_workspace.view.save_shot_name = Some(name);
|
||||
}
|
||||
@@ -2820,7 +2820,10 @@ fn render_workspace_stage_commands_keep_registered_actions_without_a_ribbon() {
|
||||
let mut h = Harness::new();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
assert!(crate::workspace::visible_tabs(&h.app).is_empty());
|
||||
for command in solidcraft_engine::command_specs().into_iter().filter(|c| c.id.starts_with("render.") || c.tab.starts_with("RENDER")) {
|
||||
for command in solidcraft_engine::command_specs()
|
||||
.into_iter()
|
||||
.filter(|c| c.id.starts_with("render.") || c.tab.starts_with("RENDER") || c.id == "view.shots_strip")
|
||||
{
|
||||
assert!(solidcraft_engine::find_command(command.id).is_some());
|
||||
assert!(crate::workspace::destination(command).is_none(), "{} has a ribbon destination", command.id);
|
||||
}
|
||||
@@ -3277,6 +3280,10 @@ fn render_workspace_shots_toggle_persists_and_design_roundtrip_preserves_state()
|
||||
h.frames(3);
|
||||
assert!(crate::scenario::rect_of("render:shots_strip").is_none());
|
||||
assert!(crate::scenario::rect_of("render:shots:show").is_some());
|
||||
h.step(&json!({"click":{"handle":"render:shots:show"}})).unwrap();
|
||||
assert!(h.app.preferences.render_shots_strip);
|
||||
h.step(&json!({"click":{"handle":"render:shots:hide"}})).unwrap();
|
||||
assert!(!h.app.preferences.render_shots_strip);
|
||||
let saved = h.app.prefs();
|
||||
let mut next = Harness::new();
|
||||
next.app.load_prefs(&saved);
|
||||
@@ -4264,3 +4271,286 @@ fn render_workspace_browser_compact_geometry_search_and_theme_evidence() {
|
||||
}
|
||||
crate::theme::set_dark(previous);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_shots_modified_dot_update_and_revert_follow_only_camera() {
|
||||
let mut h = Harness::new();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.frames(3);
|
||||
setups::save(&mut h.app).unwrap();
|
||||
h.app.render_workspace.view.inspector.page = inspector::Page::Camera;
|
||||
h.frames(3);
|
||||
assert!(!shots::camera_modified(&h.app, "Studio"));
|
||||
assert!(crate::scenario::rect_of("dialog:list:shot:Studio:modified").is_none());
|
||||
let saved = h.app.session.doc.render.setups["Studio"].clone();
|
||||
h.app.render_workspace.view.draft.width = 317;
|
||||
h.frames(2);
|
||||
assert!(!shots::camera_modified(&h.app, "Studio"), "output settings must not mark the camera");
|
||||
h.app.cam.yaw += 0.3;
|
||||
h.frames(3);
|
||||
assert!(crate::scenario::rect_of("dialog:list:shot:Studio:modified").is_some());
|
||||
assert!(crate::scenario::handle_at("render:shots:update").is_some());
|
||||
h.step(&json!({"click":{"handle":"render:shots:update"}})).unwrap();
|
||||
h.frames(2);
|
||||
let mut expected = saved.clone();
|
||||
expected.camera = h.app.cam;
|
||||
assert_eq!(h.app.session.doc.render.setups["Studio"], expected, "Update must preserve saved output and lighting");
|
||||
assert_eq!(h.app.render_workspace.view.draft.width, 317, "Update must preserve the editor draft");
|
||||
assert!(!shots::camera_modified(&h.app, "Studio"));
|
||||
assert!(crate::scenario::rect_of("dialog:list:shot:Studio:modified").is_none());
|
||||
assert!(crate::scenario::handle_at("render:shots:update").is_none());
|
||||
h.app.cam.roll += 0.2;
|
||||
h.frames(3);
|
||||
let document = h.app.session.doc.clone();
|
||||
let undo = h.app.session.undo.len();
|
||||
h.step(&json!({"click":{"handle":"render:shots:revert"}})).unwrap();
|
||||
h.frames(2);
|
||||
assert_eq!(h.app.cam, expected.camera);
|
||||
assert!(!shots::camera_modified(&h.app, "Studio"));
|
||||
assert_eq!(h.app.session.doc, document);
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_shots_save_prompt_and_size_dropdown_use_existing_commands() {
|
||||
let mut h = Harness::new();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.frames(3);
|
||||
h.step(&json!({"click":{"handle":"render:shots:save"}})).unwrap();
|
||||
assert!(inspector::confirmation_open(&h.app));
|
||||
h.app.render_workspace.view.save_shot_name = Some("Hero".into());
|
||||
h.frames(3);
|
||||
assert_eq!(crate::scenario::count_of("dialog:ok:enabled"), Some(1.0));
|
||||
h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap();
|
||||
assert!(h.app.session.doc.render.setups.contains_key("Hero"));
|
||||
assert_eq!(h.app.render_workspace.view.name, "Hero");
|
||||
assert!(!inspector::confirmation_open(&h.app));
|
||||
assert_eq!(h.app.session.doc.render.setups["Hero"].camera, h.app.cam);
|
||||
let doc = h.app.session.doc.clone();
|
||||
let undo = h.app.session.undo.len();
|
||||
h.step(&json!({"click":{"handle":"render:shots:size"}})).unwrap();
|
||||
h.step(&json!({"click":{"handle":"dialog:list:Full HD"}})).unwrap();
|
||||
assert_eq!((h.app.render_workspace.view.draft.width, h.app.render_workspace.view.draft.height), (1920, 1080));
|
||||
assert_eq!(h.app.session.doc, doc);
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[test]
|
||||
fn render_workspace_shots_thumbnails_bound_invalidate_and_never_replace_results_or_history() {
|
||||
use std::time::{Duration, Instant};
|
||||
let mut h = Harness::new();
|
||||
h.app.run("solid.box", json!({"length":20,"width":15,"height":10})).unwrap();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
for index in 0..20 {
|
||||
h.app.run("render.settings.set", json!({"name":format!("Shot {index:02}"),"set":{"camera":h.app.cam}})).unwrap();
|
||||
}
|
||||
// A real completed frame stays available, including its exact PNG and retained texture.
|
||||
let id = completed_preview(&mut h, [20, 40, 60]);
|
||||
h.app.render_workspace.view.job = Some(id);
|
||||
cache_render_images(&mut h.app, &h.ctx);
|
||||
h.app.render_workspace.view.job = None;
|
||||
let png = h.app.session.render_job_handle(id).unwrap().frame().unwrap().unwrap().png().to_vec();
|
||||
let retained = h.app.render_workspace.image.as_ref().unwrap().1.as_ref().unwrap().id();
|
||||
let doc = h.app.session.doc.clone();
|
||||
let undo = h.app.session.undo.len();
|
||||
let deadline = Instant::now() + Duration::from_secs(20);
|
||||
while h.app.render_workspace.thumbnails.entries.len() < thumbnails::LIMIT {
|
||||
assert!(Instant::now() < deadline, "thumbnail worker did not complete");
|
||||
thumbnails::refresh(&mut h.app, &h.ctx);
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
assert_eq!(h.app.render_workspace.thumbnails.entries.len(), 16);
|
||||
assert!(h.app.render_workspace.thumbnails.entries.values().all(|texture| texture.as_ref().is_some_and(|texture| texture.size() == [104, 60])));
|
||||
assert_eq!(h.app.render_workspace.image.as_ref().unwrap().1.as_ref().unwrap().id(), retained);
|
||||
assert_eq!(h.app.render_workspace.view.completed, Some(id));
|
||||
assert_eq!(h.app.session.render_job_handle(id).unwrap().frame().unwrap().unwrap().png(), png);
|
||||
assert!(h.app.render_workspace.view.job.is_none());
|
||||
assert_eq!(h.app.session.doc, doc);
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
// Later shots must get previews on selection/scrolling rather than keeping the first 16 forever.
|
||||
h.app.render_workspace.view.name = "Shot 19".into();
|
||||
h.app.render_workspace.thumbnails.show(vec!["Shot 18".into(), "Shot 19".into()], &h.ctx);
|
||||
thumbnails::refresh(&mut h.app, &h.ctx);
|
||||
while h.app.render_workspace.thumbnails.texture("Shot 19").is_none() || h.app.render_workspace.thumbnails.texture("Shot 18").is_none() {
|
||||
assert!(Instant::now() < deadline, "visible thumbnail worker did not complete");
|
||||
thumbnails::refresh(&mut h.app, &h.ctx);
|
||||
assert!(h.app.render_workspace.thumbnails.entries.len() <= 16);
|
||||
std::thread::sleep(Duration::from_millis(2));
|
||||
}
|
||||
let old = h.app.render_workspace.thumbnails.entries.keys().cloned().collect::<Vec<_>>();
|
||||
// Camera, scene revision and visibility invalidate stale previews.
|
||||
let camera = Camera { yaw: 0.7, ..h.app.cam };
|
||||
h.app.run("render.settings.set", json!({"name":"Shot 00","set":{"camera":camera}})).unwrap();
|
||||
thumbnails::refresh(&mut h.app, &h.ctx);
|
||||
assert!(h.app.render_workspace.thumbnails.entries.keys().all(|key| !old.contains(key)));
|
||||
h.app.session.visibility.hidden_bodies.push("Body1".into());
|
||||
thumbnails::refresh(&mut h.app, &h.ctx);
|
||||
invalidate_scene(&mut h.app);
|
||||
assert!(h.app.render_workspace.thumbnails.entries.is_empty());
|
||||
thumbnails::refresh(&mut h.app, &h.ctx);
|
||||
reset_document(&mut h.app);
|
||||
assert!(h.app.render_workspace.thumbnails.entries.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_shots_running_ring_stays_with_the_submitted_shot() {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("solid.box", json!({"length":20,"width":15,"height":10})).unwrap();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.app.render_workspace.view.name = "A".into();
|
||||
setups::save(&mut h.app).unwrap();
|
||||
h.app.run("render.settings.set", json!({"name":"B","set":{}})).unwrap();
|
||||
h.app.start("render.start");
|
||||
assert_eq!(h.app.render_workspace.view.job_shot.as_deref(), Some("A"));
|
||||
h.app.render_workspace.view.name = "B".into();
|
||||
h.frames(2);
|
||||
assert!(crate::scenario::rect_of("dialog:list:shot:A:progress").is_some());
|
||||
assert!(crate::scenario::rect_of("dialog:list:shot:B:progress").is_none());
|
||||
h.app.start("render.cancel");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_shots_thumbnail_keys_include_name_scene_revision_and_complete_camera() {
|
||||
let camera = Camera::default();
|
||||
let key = thumbnails::Key::new("Hero".into(), 1, 2, camera);
|
||||
assert_eq!(key, thumbnails::Key::new("Hero".into(), 1, 2, camera));
|
||||
assert_ne!(key, thumbnails::Key::new("Front".into(), 1, 2, camera));
|
||||
assert_ne!(key, thumbnails::Key::new("Hero".into(), 2, 2, camera));
|
||||
assert_ne!(key, thumbnails::Key::new("Hero".into(), 1, 3, camera));
|
||||
for changed in [
|
||||
Camera { yaw: camera.yaw + 0.1, ..camera },
|
||||
Camera { roll: camera.roll + 0.1, ..camera },
|
||||
Camera { fov: 0.7, ..camera },
|
||||
Camera { up: solidcraft_engine::render::UpAxis::Y, ..camera },
|
||||
] {
|
||||
assert_ne!(key, thumbnails::Key::new("Hero".into(), 1, 2, changed));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_shots_heading_matches_design_history_typography_and_strip_baseline() {
|
||||
fn heading(h: &mut Harness, title: &str, strip: &str) -> (egui::FontId, Color32) {
|
||||
let mut output = h.ctx.run_ui(
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 1000.0))), ..Default::default() },
|
||||
|ui| {
|
||||
h.app.logic(ui.ctx());
|
||||
h.app.ui(ui);
|
||||
},
|
||||
);
|
||||
let rect = crate::scenario::rect_of(strip).unwrap();
|
||||
let text = crate::test_support::text_shapes(&output).find(|text| text.galley.text() == title && rect.contains(text.pos)).unwrap();
|
||||
let format = &text.galley.job.sections.first().unwrap().format;
|
||||
assert!((text.pos.y + text.galley.size().y / 2.0 - rect.center().y).abs() <= 1.0, "{title} centred on its strip");
|
||||
let appearance = (format.font_id.clone(), format.color);
|
||||
output.textures_delta.clear();
|
||||
appearance
|
||||
}
|
||||
let mut h = Harness::new();
|
||||
h.app.run("solid.box", json!({"length":10,"width":10,"height":10})).unwrap();
|
||||
h.app.ui.layout = crate::shell::LayoutMode::Docked;
|
||||
h.app.preferences.timeline_left = false;
|
||||
h.app.ui.show_timeline = true;
|
||||
h.frames(3);
|
||||
let history = heading(&mut h, "History", "history:strip");
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.frames(3);
|
||||
assert_eq!(heading(&mut h, "Shots", "render:shots_strip"), history);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_frame_save_shot_dispatches_without_a_ribbon_or_document_edits() {
|
||||
let mut h = Harness::new();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
let document = h.app.session.doc.clone();
|
||||
let undo = h.app.session.undo.len();
|
||||
h.frames(3);
|
||||
assert!(crate::scenario::handle_at("render:stage:save_shot").is_none());
|
||||
h.app.run("view.render_stage", json!({"stage":"frame"})).unwrap();
|
||||
h.frames(3);
|
||||
h.step(&json!({"click":{"handle":"render:stage:save_shot"}})).unwrap();
|
||||
assert!(inspector::confirmation_open(&h.app));
|
||||
assert_eq!(h.app.session.doc, document);
|
||||
assert_eq!(h.app.session.undo.len(), undo);
|
||||
h.app.render_workspace.view.save_shot_name = Some("Frame shot".into());
|
||||
h.frames(3);
|
||||
h.step(&json!({"click":{"handle":"dialog:ok"}})).unwrap();
|
||||
assert_eq!(h.app.session.doc.render.setups["Frame shot"].camera, h.app.cam);
|
||||
h.app.render_workspace.view.save_shot_name = None;
|
||||
assert!(h.app.run("render.settings.set", json!({})).is_err());
|
||||
assert!(!inspector::confirmation_open(&h.app));
|
||||
assert!(crate::workspace::destination(solidcraft_engine::find_command("view.shots_strip").unwrap()).is_none());
|
||||
assert!(crate::workspace::RIBBON_LABELS.iter().all(|(id, _)| *id != "view.shots_strip"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_workspace_shots_strip_geometry_and_theme_evidence() {
|
||||
let previous = crate::theme::is_dark();
|
||||
for dark in [false, true] {
|
||||
let mut h = Harness::new();
|
||||
h.app.run("solid.box", json!({"length":20,"width":15,"height":10})).unwrap();
|
||||
enter(&mut h.app, true).unwrap();
|
||||
h.app.pending_fit = None;
|
||||
for (name, yaw) in [("Hero", 0.5), ("Front", 0.0), ("Detail", 0.8)] {
|
||||
h.app.run("render.settings.set", json!({"name":name,"set":{"camera":Camera {yaw,..h.app.cam}}})).unwrap();
|
||||
}
|
||||
switch_shot(&mut h.app, "Hero".into());
|
||||
h.app.render_workspace.view.draft.width = 1920;
|
||||
h.app.render_workspace.view.draft.height = 1080;
|
||||
let reply = h.app.session.execute("render.start", &json!({"settings":{"width":1920,"height":1080}})).unwrap();
|
||||
let id = serde_json::from_value(reply["job"].clone()).unwrap();
|
||||
let host = h.app.session.render_job_host().unwrap().clone();
|
||||
for _ in 0..10_000 {
|
||||
host.pump(16_384).unwrap();
|
||||
if h.app.session.render_job_handle(id).unwrap().frame().unwrap().is_some() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert!(h.app.session.render_job_handle(id).unwrap().frame().unwrap().is_some());
|
||||
h.app.render_workspace.view.job = Some(id);
|
||||
cache_render_images(&mut h.app, &h.ctx);
|
||||
h.app.render_workspace.view.job = None;
|
||||
h.app.ui.dark = dark;
|
||||
let ctx = crate::fonts::test_context();
|
||||
let bounds = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1440.0, 900.0));
|
||||
let mut textures = std::collections::HashMap::new();
|
||||
for frame in 0..12 {
|
||||
crate::scenario::clear_handles();
|
||||
let mut output = ctx.run_ui(
|
||||
egui::RawInput { screen_rect: Some(bounds), time: Some(ctx.cumulative_frame_nr() as f64 / 60.0), ..Default::default() },
|
||||
|ui| {
|
||||
h.app.logic(ui.ctx());
|
||||
h.app.ui(ui);
|
||||
},
|
||||
);
|
||||
crate::ui_kit::test_textures_update(&mut textures, &output.textures_delta);
|
||||
output.textures_delta.clear();
|
||||
if frame == 11 {
|
||||
let strip = crate::scenario::rect_of("render:shots_strip").unwrap();
|
||||
assert!((strip.height() - 48.0).abs() < 1.0, "{strip:?}");
|
||||
let mut last = crate::scenario::rect_of("render:shots:heading").unwrap();
|
||||
for target in [
|
||||
"render:shots:save",
|
||||
"render:shots:setup:Detail",
|
||||
"render:shots:setup:Front",
|
||||
"render:shots:setup:Hero",
|
||||
"render:shots:status",
|
||||
"render:shots:size",
|
||||
"render:shots:render",
|
||||
"render:shots:hide",
|
||||
] {
|
||||
let rect = crate::scenario::rect_of(target).unwrap();
|
||||
assert!(strip.contains_rect(rect), "{target}: {rect:?} in {strip:?}");
|
||||
assert!(rect.left() >= last.right(), "{target} overlaps preceding control");
|
||||
last = rect;
|
||||
}
|
||||
if let Ok(dir) = std::env::var("SOLIDCRAFT_SHOTS_EVIDENCE") {
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let image = crate::ui_kit::test_raster(&ctx, output.shapes, output.pixels_per_point, bounds, &textures);
|
||||
image.save(std::path::Path::new(&dir).join(format!("shots-{}.png", if dark { "dark" } else { "light" }))).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
crate::theme::set_dark(previous);
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
//! Ephemeral shot previews. One cancellable CPU task; no host, job identity or document edits.
|
||||
use std::collections::BTreeMap;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use crate::SolveApp;
|
||||
use solidcraft_engine::render::{Camera, job::CancelToken};
|
||||
|
||||
pub(super) const LIMIT: usize = 16;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
const SIZE: [u32; 2] = [104, 60];
|
||||
|
||||
// Cancellation is cooperative. Keep a single process-wide worker permit so rapid tab/document
|
||||
// changes cannot accumulate detached workers while the previous task finishes its bounded step.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
static WORKER_ACTIVE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
struct WorkerPermit;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl Drop for WorkerPermit {
|
||||
fn drop(&mut self) {
|
||||
WORKER_ACTIVE.store(false, std::sync::atomic::Ordering::Release);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub(super) struct Key {
|
||||
pub name: String,
|
||||
revision: u64,
|
||||
scene: u64,
|
||||
camera: u64,
|
||||
}
|
||||
|
||||
impl Key {
|
||||
pub(super) fn new(name: String, revision: u64, scene: u64, camera: Camera) -> Self {
|
||||
let mut hash = std::collections::hash_map::DefaultHasher::new();
|
||||
// Camera's complete serialized numerical intent, including roll, projection and up axis.
|
||||
if let Ok(bytes) = serde_json::to_vec(&camera) {
|
||||
bytes.hash(&mut hash);
|
||||
}
|
||||
Self { name, revision, scene, camera: hash.finish() }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct Cache {
|
||||
pub entries: BTreeMap<Key, Option<egui::TextureHandle>>,
|
||||
visible: Vec<String>,
|
||||
pending: Option<Pending>,
|
||||
}
|
||||
struct Pending {
|
||||
key: Key,
|
||||
cancel: CancelToken,
|
||||
result: std::sync::mpsc::Receiver<Option<egui::ColorImage>>,
|
||||
}
|
||||
impl Drop for Cache {
|
||||
fn drop(&mut self) {
|
||||
if let Some(pending) = &self.pending {
|
||||
pending.cancel.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Cache {
|
||||
pub fn show(&mut self, names: Vec<String>, ctx: &egui::Context) {
|
||||
let names = names.into_iter().take(LIMIT).collect::<Vec<_>>();
|
||||
if self.visible != names {
|
||||
self.visible = names;
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn texture(&self, name: &str) -> Option<egui::TextureId> {
|
||||
self.entries.iter().find(|(key, _)| key.name == name).and_then(|(_, value)| value.as_ref().map(egui::TextureHandle::id))
|
||||
}
|
||||
|
||||
pub fn retain(&mut self, keys: &[Key]) {
|
||||
self.entries.retain(|key, _| keys.iter().take(LIMIT).any(|wanted| wanted == key));
|
||||
if let Some(pending) = &self.pending
|
||||
&& !keys.iter().take(LIMIT).any(|key| key == &pending.key)
|
||||
{
|
||||
// Keep the receiver until the worker exits: invalidation cannot spawn extra workers.
|
||||
pending.cancel.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
fn poll(&mut self, ctx: &egui::Context, keys: &[Key]) {
|
||||
let Some(pending) = &self.pending else { return };
|
||||
let image = match pending.result.try_recv() {
|
||||
Ok(image) => image,
|
||||
Err(std::sync::mpsc::TryRecvError::Empty) => {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(100));
|
||||
return;
|
||||
}
|
||||
Err(std::sync::mpsc::TryRecvError::Disconnected) => None,
|
||||
};
|
||||
if let Some(pending) = self.pending.take()
|
||||
&& keys.iter().take(LIMIT).any(|key| key == &pending.key)
|
||||
&& !pending.cancel.is_cancelled()
|
||||
{
|
||||
self.entries.insert(pending.key, image.map(|image| ctx.load_texture("shot_thumbnail", image, egui::TextureOptions::LINEAR)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn refresh(app: &mut SolveApp, ctx: &egui::Context) {
|
||||
let mut scene = std::collections::hash_map::DefaultHasher::new();
|
||||
app.session.visibility.hidden_bodies.hash(&mut scene);
|
||||
app.session.visibility.hidden_occurrences.hash(&mut scene);
|
||||
(std::sync::Arc::as_ptr(&app.session.world_state()) as usize).hash(&mut scene);
|
||||
let scene = scene.finish();
|
||||
let mut keys = Vec::new();
|
||||
for name in std::iter::once(&app.render_workspace.view.name)
|
||||
.chain(app.render_workspace.thumbnails.visible.iter())
|
||||
.chain(app.session.doc.render.setups.keys())
|
||||
{
|
||||
if keys.len() == LIMIT {
|
||||
break;
|
||||
}
|
||||
if keys.iter().any(|key: &Key| &key.name == name) {
|
||||
continue;
|
||||
}
|
||||
if let Some(setup) = app.session.doc.render.setups.get(name) {
|
||||
keys.push(Key::new(name.clone(), app.session.revision, scene, setup.camera));
|
||||
}
|
||||
}
|
||||
let cache = &mut app.render_workspace.thumbnails;
|
||||
cache.retain(&keys);
|
||||
cache.poll(ctx, &keys);
|
||||
if cache.pending.is_some() {
|
||||
return;
|
||||
}
|
||||
let Some(key) = keys.into_iter().find(|key| !cache.entries.contains_key(key)) else { return };
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
if WORKER_ACTIVE.compare_exchange(false, true, std::sync::atomic::Ordering::Acquire, std::sync::atomic::Ordering::Relaxed).is_err() {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(100));
|
||||
return;
|
||||
}
|
||||
let permit = WorkerPermit;
|
||||
let Some(setup) = app.session.doc.render.setups.get(&key.name) else { return };
|
||||
let request = solidcraft_engine::render::job::ImageRequest {
|
||||
camera: setup.camera,
|
||||
width: SIZE[0],
|
||||
height: SIZE[1],
|
||||
background: setup.background,
|
||||
transparent_background: false,
|
||||
integrator: Default::default(),
|
||||
raytrace: None,
|
||||
environment: None,
|
||||
textures: None,
|
||||
};
|
||||
let scene = solidcraft_engine::product_scene::extract(&app.session);
|
||||
let cancel = CancelToken::default();
|
||||
let worker_cancel = cancel.clone();
|
||||
let (send, result) = std::sync::mpsc::sync_channel(1);
|
||||
let worker = std::thread::Builder::new().name("shot-thumbnail".into()).spawn(move || {
|
||||
let _permit = permit;
|
||||
let image = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
||||
let scene = scene.ok()?;
|
||||
let mut task = solidcraft_engine::render::job::ImageTask::new(scene, request, worker_cancel).ok()?;
|
||||
loop {
|
||||
match task.step(1024).ok()? {
|
||||
solidcraft_engine::render::job::TaskPoll::Pending(_) => {}
|
||||
solidcraft_engine::render::job::TaskPoll::Complete(png) => {
|
||||
let image = image::load_from_memory(&png).ok()?.to_rgba8();
|
||||
return Some(egui::ColorImage::from_rgba_unmultiplied([SIZE[0] as usize, SIZE[1] as usize], image.as_raw()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}))
|
||||
.ok()
|
||||
.flatten();
|
||||
let _ = send.send(image);
|
||||
});
|
||||
if worker.is_ok() {
|
||||
app.render_workspace.thumbnails.pending = Some(Pending { key, cancel, result });
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(100));
|
||||
} else {
|
||||
app.render_workspace.thumbnails.entries.insert(key, None);
|
||||
}
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
cache.entries.insert(key, None);
|
||||
}
|
||||
@@ -499,12 +499,11 @@ fn timeline_contents(app: &mut SolveApp, ui: &mut egui::Ui, floating: bool) {
|
||||
let grip = crate::ui_kit::panel_grip(&mut grip_ui).rect;
|
||||
x += t.space_10 + t.space_8;
|
||||
let mut drag_rect = grip;
|
||||
let label = p.layout_no_wrap(crate::i18n::tr("ui.history_title").to_string(), crate::fonts::semibold(t.font_heading), t.text);
|
||||
if x + label.size().x + t.space_12 + crate::ui_kit::history_transport_width() <= r.right() {
|
||||
let title_rect = Rect::from_min_size(pos2(x, r.center().y - label.size().y / 2.0), label.size());
|
||||
p.galley(title_rect.min, label.clone(), t.text);
|
||||
let heading = crate::ui_kit::StripHeading::new(&p, crate::i18n::tr("ui.history_title"));
|
||||
if x + heading.width() + crate::ui_kit::history_transport_width() <= r.right() {
|
||||
let title_rect = heading.paint(&p, Rect::from_min_max(pos2(x, r.top()), r.right_bottom()));
|
||||
drag_rect = drag_rect.union(title_rect);
|
||||
x += label.size().x + t.space_12;
|
||||
x += heading.width();
|
||||
}
|
||||
let response = ui.interact(drag_rect, egui::Id::new("sc_history_dock_grip"), Sense::drag());
|
||||
crate::scenario::publish_handle("history:grip", drag_rect.center());
|
||||
|
||||
@@ -585,7 +585,7 @@ pub(super) fn icon_label_width(ui: &Ui, label: &str, icon: Option<&str>, primary
|
||||
+ if icon.is_some() { t.space_14 + t.space_6 } else { 0.0 }
|
||||
}
|
||||
|
||||
pub(super) fn icon_label_action(ui: &mut Ui, label: &str, icon: Option<&str>, enabled: bool, primary: bool) -> Response {
|
||||
pub(crate) fn icon_label_action(ui: &mut Ui, label: &str, icon: Option<&str>, enabled: bool, primary: bool) -> Response {
|
||||
icon_label_presentation(ui, label, icon, enabled, primary, false, false)
|
||||
}
|
||||
|
||||
|
||||
@@ -319,6 +319,11 @@ pub(crate) fn assistant_empty<R>(ui: &mut Ui, title: &str, body: &str, add: impl
|
||||
/// Semantic warning/error/information band with caller-owned text and actions.
|
||||
#[cfg(any(not(target_arch = "wasm32"), test))]
|
||||
pub(crate) fn assistant_banner<R>(ui: &mut Ui, tone: AssistantTone, add: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
|
||||
banner(ui, tone, add)
|
||||
}
|
||||
|
||||
/// Shared semantic notice band, also available to workspace inspectors on wasm.
|
||||
pub(crate) fn banner<R>(ui: &mut Ui, tone: AssistantTone, add: impl FnOnce(&mut Ui) -> R) -> InnerResponse<R> {
|
||||
let t = Tokens::get();
|
||||
let (_, fill) = tone.colors(&t);
|
||||
egui::Frame::NONE.fill(fill).stroke(t.container_border(t.dialog_rule)).corner_radius(t.radius_lg).inner_margin(t.space_10).show(ui, |ui| {
|
||||
|
||||
@@ -404,6 +404,100 @@ pub(crate) fn choice_chip(ui: &mut Ui, key: &str, text: &str, selected: bool) ->
|
||||
response
|
||||
}
|
||||
|
||||
/// Thumbnail variant of the shared selection chip. No document or render-job ownership.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct ThumbnailChoice {
|
||||
pub texture: Option<egui::TextureId>,
|
||||
pub selected: bool,
|
||||
pub modified: bool,
|
||||
pub progress: Option<f32>,
|
||||
}
|
||||
|
||||
pub(crate) fn thumbnail_choice(ui: &mut Ui, key: &str, text: &str, state: ThumbnailChoice) -> egui::Response {
|
||||
let t = Tokens::get();
|
||||
let thumb_size = vec2(t.control_height + t.space_24, t.control_height + t.space_2);
|
||||
let height = thumb_size.y + t.space_8;
|
||||
let font = crate::fonts::semibold(t.font_small);
|
||||
let width = ui.painter().layout_no_wrap(text.to_owned(), font.clone(), t.form_ink).size().x.min(t.form_label_width * 2.0)
|
||||
+ thumb_size.x
|
||||
+ t.space_8
|
||||
+ t.space_14;
|
||||
let (rect, response) = ui.allocate_exact_size(vec2(width, height), egui::Sense::click());
|
||||
let accent = crate::theme::TabAccent::current(ui.ctx());
|
||||
let ink = if state.selected { accent.ink } else { t.form_ink };
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
t.control_radius,
|
||||
if state.selected {
|
||||
accent.soft
|
||||
} else if response.hovered() {
|
||||
t.hover
|
||||
} else {
|
||||
t.control_fill
|
||||
},
|
||||
egui::Stroke::new(if state.selected { 1.5 } else { 1.0 }, if state.selected { accent.ink } else { t.control_border }),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
let thumb = egui::Rect::from_min_size(rect.min + vec2(t.space_4, t.space_4), thumb_size);
|
||||
ui.painter().rect_filled(thumb, t.radius_sm, t.dialog_footer);
|
||||
if let Some(texture) = state.texture {
|
||||
egui::Image::new((texture, thumb.size())).corner_radius(t.radius_sm).paint_at(ui, thumb);
|
||||
} else {
|
||||
// Deterministic placeholder while loading, or when a worker is unavailable.
|
||||
ui.painter().hline(thumb.shrink(t.space_8).x_range(), thumb.center().y, t.control_border_stroke(t.control_border));
|
||||
}
|
||||
super::text::paint_text(
|
||||
ui,
|
||||
egui::Rect::from_min_max(egui::pos2(thumb.right() + t.space_8, rect.top()), rect.max - vec2(t.space_10, 0.0)),
|
||||
text,
|
||||
font,
|
||||
ink,
|
||||
false,
|
||||
);
|
||||
if state.modified {
|
||||
let dot = egui::pos2(rect.right() - t.space_6, rect.top() + t.space_6);
|
||||
ui.painter().circle_filled(dot, t.space_3, t.warning);
|
||||
crate::scenario::publish_rect(&format!("dialog:list:{key}:modified"), egui::Rect::from_center_size(dot, vec2(t.space_6, t.space_6)));
|
||||
}
|
||||
if let Some(progress) = state.progress {
|
||||
let center = thumb.center();
|
||||
let radius = t.space_8;
|
||||
ui.painter().circle_filled(center, radius + t.space_3, t.dialog_body);
|
||||
ui.painter().circle_stroke(center, radius, egui::Stroke::new(t.space_2, t.control_border));
|
||||
let fraction = if progress.is_finite() { progress.clamp(0.0, 1.0) } else { 0.0 };
|
||||
let points: Vec<_> = (0..=32)
|
||||
.map(|i| {
|
||||
let angle = -std::f32::consts::FRAC_PI_2 + std::f32::consts::TAU * fraction.max(0.03) * i as f32 / 32.0;
|
||||
center + radius * vec2(angle.cos(), angle.sin())
|
||||
})
|
||||
.collect();
|
||||
ui.painter().add(egui::Shape::line(points, egui::Stroke::new(t.space_2, accent.ink)));
|
||||
crate::scenario::publish_rect(&format!("dialog:list:{key}:progress"), thumb);
|
||||
}
|
||||
response.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, ui.is_enabled(), state.selected, text));
|
||||
crate::scenario::publish_target(&format!("dialog:list:{key}"), response.rect);
|
||||
response.on_hover_text(text)
|
||||
}
|
||||
|
||||
/// Dashed add variant for thumbnail strips, sharing control tokens and button semantics.
|
||||
pub(crate) fn add_choice(ui: &mut Ui, label: &str) -> egui::Response {
|
||||
let t = Tokens::get();
|
||||
let side = t.control_height + t.space_8;
|
||||
let (rect, response) = ui.allocate_exact_size(vec2(side, side), egui::Sense::click());
|
||||
if response.hovered() {
|
||||
ui.painter().rect_filled(rect, t.control_radius, t.hover);
|
||||
}
|
||||
let r = rect.shrink(t.space_2);
|
||||
let mut outline = super::preferences::rounded_perimeter(r, f32::from(t.control_radius));
|
||||
if let Some(first) = outline.first().copied() {
|
||||
outline.push(first);
|
||||
}
|
||||
ui.painter().add(egui::Shape::dashed_line(&outline, egui::Stroke::new(1.0, t.control_border), t.space_3, t.space_3));
|
||||
ui.painter().text(rect.center(), egui::Align2::CENTER_CENTER, "+", egui::FontId::proportional(t.font_subtitle), t.form_dim);
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), label));
|
||||
response.on_hover_text(label)
|
||||
}
|
||||
|
||||
/// A reusable draggable document-colour sample; caller supplies the existing domain payload.
|
||||
/// Tokens: control_height/radius, border, accent, hover.
|
||||
pub(crate) fn color_swatch<T: Send + Sync + 'static>(
|
||||
|
||||
@@ -157,3 +157,74 @@ fn stage_chips_reserve_the_selected_weight_for_complete_labels_in_all_five_catal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thumbnail_choice_states_share_geometry_and_publish_modified_and_running_indicators() {
|
||||
let ctx = crate::fonts::test_context();
|
||||
let previous = crate::theme::is_dark();
|
||||
for dark in [false, true] {
|
||||
crate::theme::set_dark(dark);
|
||||
crate::theme::apply(&ctx);
|
||||
let mut dimensions = Vec::new();
|
||||
for (selected, modified, progress) in [(false, false, None), (true, false, None), (true, true, Some(0.4))] {
|
||||
scenario::clear_handles();
|
||||
frame(&ctx, vec![], |ui| {
|
||||
let response = thumbnail_choice(ui, "shot", "Hero", ThumbnailChoice { selected, modified, progress, ..Default::default() });
|
||||
dimensions.push(response.rect.size());
|
||||
});
|
||||
assert_eq!(scenario::rect_of("dialog:list:shot:modified").is_some(), modified);
|
||||
assert_eq!(scenario::rect_of("dialog:list:shot:progress").is_some(), progress.is_some());
|
||||
}
|
||||
assert!(dimensions.iter().all(|size| *size == dimensions[0]));
|
||||
assert_eq!(dimensions[0].y, 38.0);
|
||||
}
|
||||
crate::theme::set_dark(previous);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn thumbnail_choices_with_ready_images_preserve_names_and_full_chip_stride() {
|
||||
let ctx = crate::fonts::test_context();
|
||||
let texture = ctx.load_texture("shot", egui::ColorImage::filled([104, 60], egui::Color32::GRAY), Default::default());
|
||||
frame(&ctx, vec![], |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
let first = thumbnail_choice(ui, "detail", "Detail", ThumbnailChoice { texture: Some(texture.id()), ..Default::default() });
|
||||
let second = thumbnail_choice(ui, "front", "Front", ThumbnailChoice { texture: Some(texture.id()), ..Default::default() });
|
||||
assert!(first.rect.right() <= second.rect.left(), "loaded images must not move the cursor back over the preceding name");
|
||||
assert!(first.rect.width() > 52.0 + 24.0, "reserve the shot name beside the thumbnail");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_shot_dashes_leave_rounded_corners_at_the_chip_radius() {
|
||||
fn endpoints(shape: &egui::Shape, color: egui::Color32, points: &mut Vec<egui::Pos2>) {
|
||||
match shape {
|
||||
egui::Shape::Vec(shapes) => {
|
||||
for shape in shapes {
|
||||
endpoints(shape, color, points);
|
||||
}
|
||||
}
|
||||
egui::Shape::LineSegment { points: line, stroke } if stroke.color == color => points.extend(line),
|
||||
egui::Shape::Path(path) if matches!(path.stroke.color, egui::epaint::ColorMode::Solid(ink) if ink == color) => {
|
||||
points.extend(&path.points)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let ctx = crate::fonts::test_context();
|
||||
let mut rect = egui::Rect::NOTHING;
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
rect = add_choice(ui, "Save Shot").rect;
|
||||
});
|
||||
let t = crate::theme::Tokens::get();
|
||||
let mut points = Vec::new();
|
||||
for shape in &output.shapes {
|
||||
endpoints(&shape.shape, t.control_border, &mut points);
|
||||
}
|
||||
assert!(!points.is_empty());
|
||||
let border = rect.shrink(t.space_2);
|
||||
for corner in [border.left_top(), border.right_top(), border.right_bottom(), border.left_bottom()] {
|
||||
assert!(points.iter().all(|point| point.distance(corner) > f32::from(t.control_radius) / 4.0), "dashes must follow the rounded perimeter");
|
||||
}
|
||||
output.textures_delta.clear();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
//! One disclosure drawing for sections, trees, cards and window folds.
|
||||
use crate::theme::Tokens;
|
||||
use egui::{Color32, Painter, Pos2, Rect, Response, Ui, vec2};
|
||||
use egui::{Color32, Painter, Pos2, Rect, Response, Ui, pos2, vec2};
|
||||
|
||||
/// Content visible: down. Content hidden: right. No animation, matching kit sections.
|
||||
/// Tokens: form_section_icon_size; the caller supplies a semantic ink token.
|
||||
@@ -44,6 +44,29 @@ pub(crate) fn dropdown_indicator(painter: &Painter, rect: Rect, ink: Color32) {
|
||||
crate::icons::paint_ink(painter, rect, "chevron", ink);
|
||||
}
|
||||
|
||||
/// Bottom-strip fold action: down to hide, matching up chevron and title to restore.
|
||||
pub(crate) fn strip_toggle(ui: &mut Ui, expanded: bool, label: &str) -> Response {
|
||||
let t = Tokens::get();
|
||||
let title = (!expanded).then(|| ui.painter().layout_no_wrap(label.to_owned(), egui::FontId::proportional(t.font_label), t.form_ink));
|
||||
let width = t.control_height + title.as_ref().map_or(0.0, |title| title.size().x + t.space_6);
|
||||
let (rect, response) = ui.allocate_exact_size(vec2(width, t.control_height), egui::Sense::click());
|
||||
if response.hovered() {
|
||||
ui.painter().rect_filled(rect, t.control_radius, t.hover);
|
||||
}
|
||||
let ink = if response.hovered() || response.has_focus() { t.form_ink } else { t.form_dim };
|
||||
let icon = Rect::from_min_size(rect.min, vec2(t.control_height, t.control_height)).shrink(t.form_icon_inset);
|
||||
if expanded {
|
||||
crate::icons::paint_ink(ui.painter(), icon, "chevron", ink);
|
||||
} else {
|
||||
crate::icons::paint_ink_flipped(ui.painter(), icon, "chevron", ink);
|
||||
}
|
||||
if let Some(title) = title {
|
||||
ui.painter().galley(pos2(rect.left() + t.control_height + t.space_6, rect.center().y - title.size().y / 2.0), title, t.form_ink);
|
||||
}
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), label));
|
||||
response.on_hover_cursor(egui::CursorIcon::PointingHand).on_hover_text(label)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "disclosure_tests.rs"]
|
||||
mod tests;
|
||||
@@ -99,3 +99,39 @@ fn section_card_and_floating_window_folds_render_down_when_open_right_when_close
|
||||
}
|
||||
crate::theme::set_dark(previous);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strip_fold_and_restore_share_the_chevron_texture_with_opposite_orientation() {
|
||||
for expanded in [true, false] {
|
||||
let ctx = crate::fonts::test_context();
|
||||
let mut rect = Rect::NOTHING;
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
rect = strip_toggle(ui, expanded, "Shots").rect;
|
||||
});
|
||||
let icon =
|
||||
Rect::from_min_size(rect.min, vec2(Tokens::get().control_height, Tokens::get().control_height)).shrink(Tokens::get().form_icon_inset);
|
||||
let size = icon.width().round() as u32;
|
||||
let expected = icon_svg::render(
|
||||
icon_svg::doc_for(icon_svg::resolve("chevron").master, size).unwrap(),
|
||||
icon_svg::Look { dark: true, accent: None, vision: crate::theme::vision(), palette: None },
|
||||
size,
|
||||
)
|
||||
.unwrap();
|
||||
let mut expected = ColorImage::from_rgba_premultiplied([size as usize, size as usize], expected.data());
|
||||
for pixel in &mut expected.pixels {
|
||||
*pixel = Tokens::get().form_dim.gamma_multiply(f32::from(pixel.a()) / 255.0);
|
||||
}
|
||||
let mut textures = std::collections::HashMap::new();
|
||||
super::super::checks::tests::textures_update(&mut textures, &output.textures_delta);
|
||||
let texture = textures.iter().find_map(|(id, image)| (image == &expected).then_some(*id)).expect("shared chevron artwork");
|
||||
let primitives = ctx.tessellate(output.shapes.clone(), output.pixels_per_point);
|
||||
assert!(
|
||||
primitives.iter().any(|primitive| {
|
||||
let egui::epaint::Primitive::Mesh(mesh) = &primitive.primitive else { return false };
|
||||
mesh.texture_id == texture && mesh.vertices.iter().all(|vertex| ((vertex.pos.y < icon.center().y) == (vertex.uv.y < 0.5)) == expanded)
|
||||
}),
|
||||
"hide points down and restore points up"
|
||||
);
|
||||
output.textures_delta.clear();
|
||||
}
|
||||
}
|
||||
@@ -290,6 +290,22 @@ pub(crate) fn dropdown_menu_with_close_behavior(
|
||||
current: &str,
|
||||
close_behavior: egui::PopupCloseBehavior,
|
||||
add: impl FnOnce(&mut Ui),
|
||||
) -> Response {
|
||||
dropdown_menu_width(ui, id, current, false, close_behavior, add)
|
||||
}
|
||||
|
||||
/// Intrinsic-width variant for horizontal toolbars and bottom strips.
|
||||
pub(crate) fn compact_dropdown_menu(ui: &mut Ui, id: impl egui::AsIdSalt, current: &str, add: impl FnOnce(&mut Ui)) -> Response {
|
||||
dropdown_menu_width(ui, id, current, true, egui::PopupCloseBehavior::CloseOnClick, add)
|
||||
}
|
||||
|
||||
fn dropdown_menu_width(
|
||||
ui: &mut Ui,
|
||||
id: impl egui::AsIdSalt,
|
||||
current: &str,
|
||||
compact: bool,
|
||||
close_behavior: egui::PopupCloseBehavior,
|
||||
add: impl FnOnce(&mut Ui),
|
||||
) -> Response {
|
||||
crate::prefs_search::note_current(ui, current);
|
||||
// Only a search probe may skip the real control. A dialog's first frame is not visible yet,
|
||||
@@ -299,8 +315,14 @@ pub(crate) fn dropdown_menu_with_close_behavior(
|
||||
{
|
||||
return crate::prefs_search::hidden_response(ui);
|
||||
}
|
||||
let t = Tokens::get();
|
||||
let width = if compact {
|
||||
ui.painter().layout_no_wrap(current.to_owned(), egui::FontId::proportional(t.font_label), t.form_ink).size().x + t.space_24 + t.space_8
|
||||
} else {
|
||||
dimension(ui.available_width())
|
||||
};
|
||||
let response = egui::ComboBox::from_id_salt(id)
|
||||
.width(dimension(ui.available_width()))
|
||||
.width(width)
|
||||
.height(Tokens::get().space_24 * 14.0)
|
||||
.selected_text(current)
|
||||
.icon(dropdown_arrow)
|
||||
|
||||
@@ -131,6 +131,13 @@ const ELEMENTS: &[Element] = &[
|
||||
assert_eq!(tree_row(ui, ui.id().with(("tree_geometry", index)), row).rect, Some(rect));
|
||||
}
|
||||
}),
|
||||
element!("icon_label_action", |ui, _| {
|
||||
icon_label_action(ui, "Render Image", Some("play"), true, true);
|
||||
}),
|
||||
element!("completion_text", |ui, _| {
|
||||
completion_text(ui, "Render 1 · 1920 × 1080", true);
|
||||
completion_text(ui, "No completed image", false);
|
||||
}),
|
||||
element!("tree_row", |ui, _| {
|
||||
let actions = [TreeAction { icon: "plus", hover_only: false, label: "Add", reason: None, target: "gallery:tree:add" }];
|
||||
tree_row(ui, ui.id().with("tree_plain"), &Row { label: "Objects", fold: Some(true), actions: &actions, ..Default::default() });
|
||||
@@ -205,6 +212,33 @@ const ELEMENTS: &[Element] = &[
|
||||
}
|
||||
.show(ui);
|
||||
}),
|
||||
element!("strip_toggle", |ui, _| {
|
||||
ui.horizontal(|ui| {
|
||||
strip_toggle(ui, true, "Hide Shots strip");
|
||||
strip_toggle(ui, false, "Shots");
|
||||
});
|
||||
}),
|
||||
element!("strip_heading", |ui, _| {
|
||||
StripHeading::new(ui.painter(), "History").show(ui);
|
||||
}),
|
||||
element!("choice_chip_selected", |ui, _| {
|
||||
choice_chip(ui, "saved", "Hero", true);
|
||||
}),
|
||||
element!("add_choice", |ui, _| {
|
||||
add_choice(ui, "Save Shot");
|
||||
}),
|
||||
element!("compact_dropdown_menu", |ui, _| {
|
||||
compact_dropdown_menu(ui, "gallery_strip_size", "1920 × 1080", |ui| {
|
||||
list_picker(ui, "full_hd", "Full HD", true);
|
||||
});
|
||||
}),
|
||||
element!("thumbnail_choice", |ui, _| {
|
||||
ui.horizontal(|ui| {
|
||||
thumbnail_choice(ui, "hero", "Hero", ThumbnailChoice { selected: true, modified: true, ..Default::default() });
|
||||
thumbnail_choice(ui, "front", "Front", ThumbnailChoice { progress: Some(0.6), ..Default::default() });
|
||||
add_choice(ui, "Save Shot");
|
||||
});
|
||||
}),
|
||||
element!("settings_form", |ui, state| {
|
||||
settings_form(ui, Tokens::get().form_label_width, |ui| {
|
||||
row(ui, "Sample", |ui| {
|
||||
|
||||
@@ -8,6 +8,34 @@ use egui::{Painter, Rect, Stroke, pos2, vec2};
|
||||
/// Browser and named history rows use the same density.
|
||||
pub(crate) const TREE_ROW_HEIGHT: f32 = 26.0;
|
||||
|
||||
/// Shared bottom-strip title: History's typography, centred baseline and trailing gap.
|
||||
pub(crate) struct StripHeading(std::sync::Arc<egui::Galley>);
|
||||
|
||||
impl StripHeading {
|
||||
pub fn new(painter: &Painter, title: &str) -> Self {
|
||||
let t = Tokens::get();
|
||||
Self(painter.layout_no_wrap(title.to_owned(), crate::fonts::semibold(t.font_heading), t.text))
|
||||
}
|
||||
|
||||
pub fn width(&self) -> f32 {
|
||||
self.0.size().x + Tokens::get().space_12
|
||||
}
|
||||
|
||||
pub fn paint(&self, painter: &Painter, rect: Rect) -> Rect {
|
||||
let text = Rect::from_min_size(pos2(rect.left(), rect.center().y - self.0.size().y / 2.0), self.0.size());
|
||||
painter.galley(text.min, self.0.clone(), Tokens::get().text);
|
||||
text
|
||||
}
|
||||
|
||||
pub fn show(&self, ui: &mut egui::Ui) -> egui::Response {
|
||||
let width = self.width() - ui.spacing().item_spacing.x;
|
||||
let (rect, response) = ui.allocate_exact_size(vec2(width.max(self.0.size().x), Tokens::get().control_height), egui::Sense::hover());
|
||||
self.paint(ui.painter(), rect);
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, ui.is_enabled(), self.0.text()));
|
||||
response
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub(crate) enum HistoryStyle {
|
||||
Bottom,
|
||||
|
||||
@@ -298,6 +298,22 @@ impl<'a> Panel<'a> {
|
||||
.show(ui, add)
|
||||
}
|
||||
|
||||
/// Shared strip composition reserves actions at the right and scrolls choices at the left.
|
||||
pub(crate) fn strip_contents(ui: &mut egui::Ui, right: impl FnOnce(&mut egui::Ui), choices: impl FnOnce(&mut egui::Ui)) {
|
||||
ui.spacing_mut().item_spacing.x = Tokens::get().space_8;
|
||||
ui.horizontal_centered(|ui| {
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
right(ui);
|
||||
egui::ScrollArea::horizontal()
|
||||
.id_salt("strip_choices")
|
||||
.scroll_bar_visibility(egui::scroll_area::ScrollBarVisibility::AlwaysHidden)
|
||||
.show(ui, |ui| {
|
||||
ui.with_layout(egui::Layout::left_to_right(egui::Align::Center), choices);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Floating workspace strip using the same bottom rectangle and chrome as History.
|
||||
pub(crate) fn bottom_strip<R>(
|
||||
ui: &mut Ui,
|
||||
|
||||
@@ -60,3 +60,31 @@ pub(crate) fn progress(ui: &mut egui::Ui, key: &str, fraction: f32) -> egui::Res
|
||||
crate::scenario::publish_rect(&format!("dialog:progress:{key}"), bar);
|
||||
response
|
||||
}
|
||||
|
||||
/// Compact completion readout for a strip. The caller owns the result identity.
|
||||
/// Tokens: font_small, form_ink/success/dim, control_height and space_4.
|
||||
pub(crate) fn completion_text(ui: &mut egui::Ui, label: &str, complete: bool) -> egui::Response {
|
||||
let t = Tokens::get();
|
||||
let font = egui::FontId::proportional(t.font_small);
|
||||
let text = ui.painter().layout_no_wrap(label.to_owned(), font.clone(), t.form_ink);
|
||||
let tick_width = if complete { t.space_14 + t.space_4 } else { 0.0 };
|
||||
let (rect, response) = ui.allocate_exact_size(vec2(text.size().x + tick_width, t.control_height), egui::Sense::hover());
|
||||
if complete {
|
||||
super::checks::paint_check_glyph(
|
||||
ui.painter(),
|
||||
egui::Rect::from_center_size(rect.left_center() + vec2(t.space_14 / 2.0, 0.0), vec2(t.space_14, t.space_14)),
|
||||
false,
|
||||
t.form_success,
|
||||
);
|
||||
}
|
||||
super::text::paint_text(
|
||||
ui,
|
||||
egui::Rect::from_min_max(rect.min + vec2(tick_width, 0.0), rect.max),
|
||||
label,
|
||||
font,
|
||||
if complete { t.form_ink } else { t.form_dim },
|
||||
false,
|
||||
);
|
||||
response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Label, ui.is_enabled(), label));
|
||||
response
|
||||
}
|
||||
@@ -349,7 +349,7 @@ const LEGACY_RENDER_SECTIONS: &[Section] = &[
|
||||
tab: "RENDER CAMERA",
|
||||
panel: "SHOTS",
|
||||
promoted: 3,
|
||||
ids: &["render.settings.get", "render.settings.set", "view.shots_strip", "render.shot.duplicate", "render.shot.rename", "render.shot.remove"],
|
||||
ids: &["render.settings.get", "render.settings.set", "render.shot.duplicate", "render.shot.rename", "render.shot.remove"],
|
||||
},
|
||||
Section { tab: "RENDER CAMERA", panel: "VIEW", promoted: 2, ids: &["render.settings.apply", "render.scene"] },
|
||||
Section { tab: "RENDER CAMERA", panel: "LENS", promoted: 1, ids: &["render.camera.get", "render.camera.set"] },
|
||||
@@ -368,7 +368,6 @@ const LEGACY_RENDER_SECTIONS: &[Section] = &[
|
||||
/// Compact source labels for painted big buttons only. Menus, search and tooltips
|
||||
/// retain the engine label. Route these through `tr_label`, like other UI labels.
|
||||
pub const RIBBON_LABELS: &[(&str, &str)] = &[
|
||||
("view.shots_strip", "Strip"),
|
||||
("appearance.paint", "Paint"),
|
||||
("appearance.pick_up", "Pick Up"),
|
||||
("appearance.replace", "Replace"),
|
||||
|
||||
@@ -30,7 +30,8 @@ Render, Cancel and the shared command search (S) occupy the top row. The Pick co
|
||||
icon-text Body/Face/Component segments, Paint/Pick Up actions and direct-light
|
||||
preview information chip occupy Look's second row with 8 pt side padding. Changing the
|
||||
light coordinate frame remains disabled with its reason in this checkout. Frame
|
||||
uses the existing explicit camera command for projection; Output shows the current
|
||||
uses the existing explicit camera command for projection and the registered Save Shot
|
||||
action opens the shared naming confirmation; 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 and share a top edge, 8 pt
|
||||
|
||||
+8
-5
@@ -117,14 +117,15 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
|
||||
|
||||
| Module / element | Use and options | Main tokens |
|
||||
| --- | --- | --- |
|
||||
| assistant: `assistant_header`, `assistant_controls`, `assistant_badge`, `assistant_bubble`, `assistant_prose`, `assistant_tool_frame/row/detail/status`, `AssistantToolState`, `assistant_approval/actions`, `assistant_composer/footer`, `assistant_input`, `assistant_send`, `assistant_empty`, `assistant_banner`, `AssistantTone` | Shared Assistant presentation: 40 pt header, 22 pt state pill, right-aligned user messages limited to 86% width, unboxed assistant prose, bordered tool groups and command detail, tinted approval heading, rounded focused composer with one unframed growing editor and pinned footer, centred setup copy and semantic notices. Closures preserve existing permission choices, protocol routing, queue actions and scenario handles. | `form_header_height/close_size`, `font_label/small/body`, `dialog_body/footer/rule`, `control_fill/border/radius`, `form_ink/dim/primary/success/error`, `accent_soft/selected_ink`, `warning`, radii and spacing |
|
||||
| history: `HistoryChip`, `HistoryStyle`, `history_drop_bar`, `history_marker`, `HistorySeam`, `history_seam` | One painter family for bottom chips, 38 pt vertical icon chips and single-line 26 pt name rows (the browser's shared `TREE_ROW_HEIGHT`). Selected items use the active tab tint/ink/border; all variants retain multi-tone feature artwork using one shared kind-to-accent rule (Sketch green, Surface orange, Mesh yellow, Form purple, solids base blue); rolled-back items have 42% opacity; a reference row (a sketch listed under another feature, #6489) has its name in secondary text. Error/warning badges, suppression strikes, horizontal/vertical drop bars and rollback line/hollow circle are shared. No connector lines. | `control_height`, `space_2/3/4/6/8/10/12/14/16/24`, radii, typography, `TabAccent`, `timeline_item`, `control_border`, `text/dim`, `form_error/fill` |
|
||||
| assistant: `assistant_header`, `assistant_controls`, `assistant_badge`, `assistant_bubble`, `assistant_prose`, `assistant_tool_frame/row/detail/status`, `AssistantToolState`, `assistant_approval/actions`, `assistant_composer/footer`, `assistant_input`, `assistant_send`, `assistant_empty`, `assistant_banner`/`banner`, `AssistantTone` | Shared Assistant presentation: 40 pt header, 22 pt state pill, right-aligned user messages limited to 86% width, unboxed assistant prose, bordered tool groups and command detail, tinted approval heading, rounded focused composer with one unframed growing editor and pinned footer, centred setup copy and semantic notices. Closures preserve existing permission choices, protocol routing, queue actions and scenario handles. | `form_header_height/close_size`, `font_label/small/body`, `dialog_body/footer/rule`, `control_fill/border/radius`, `form_ink/dim/primary/success/error`, `accent_soft/selected_ink`, `warning`, radii and spacing |
|
||||
| history: `StripHeading`, `HistoryChip`, `HistoryStyle`, `history_drop_bar`, `history_marker`, `HistorySeam`, `history_seam` | Shared strip headings use semibold `font_heading`, `text`, a centred baseline and `space_12` trailing gap. One painter family for bottom chips, 38 pt vertical icon chips and single-line 26 pt name rows (the browser's shared `TREE_ROW_HEIGHT`). Selected items use the active tab tint/ink/border; all variants retain multi-tone feature artwork using one shared kind-to-accent rule (Sketch green, Surface orange, Mesh yellow, Form purple, solids base blue); rolled-back items have 42% opacity; a reference row (a sketch listed under another feature, #6489) has its name in secondary text. Error/warning badges, suppression strikes, horizontal/vertical drop bars and rollback line/hollow circle are shared. No connector lines. | `control_height`, `space_2/3/4/6/8/10/12/14/16/24`, radii, typography, `TabAccent`, `timeline_item`, `control_border`, `text/dim`, `form_error/fill` |
|
||||
| tree: `tree_row`, `Row`, `TreeAction` | Shared Browser rows with disclosure, visibility, activation, selection, appearance swatches, optional subtitle and trailing actions. Compact scene rows are 28 pt, with inline right-aligned summaries, circular swatches, trailing eyes and full-width selection tint. Actions use quiet icons and can appear on hover. Disabled actions retain their reasons and cannot select or fold the row. Browser automation records the same row geometry. | `TREE_ROW_HEIGHT`, `font_label/small`, spacing, control radius/border, `text/dim`, workspace selection tint |
|
||||
| search: `CommandSearch`, `MenuItem::search_row` | Ribbon search composition: one persistent ribbon editor expands from 28 to 40 pt and to 520 pt wide with its right edge anchored, magnifier and S/Esc keycap, 38 pt two-line menu row with 26 pt icon tile, accent bold substring, path, shortcut/kind keycap, counts, JSON detail box and footer. The ordinary 30 pt menu row cannot fit a second line; this variant keeps its enabled/selected states and scenario IDs. Ranking and dispatch stay with the caller. | `form_card_width × 2 − space_8` (520 pt), `control_height`, `space_2/3/4/6/8/10/12/14/16/24`, `radius_xl/control_radius`, `control_fill`, `dialog_body/footer/rule/border`, `form_ink/dim/primary/error/error_fill/success/success_fill`, `selected_ink`, `accent_soft`, typography |
|
||||
| menu: `Menu`, `MenuItem` | Shared popup, 30 pt rows, 28 pt icon column, clipped labels, right-aligned mono shortcuts, submenu chevrons, checked/unchecked and document swatches, inert 40% disabled rows and danger ink; headings and separators; ribbon drag/pin targets retained | `dialog_body/border/rule`, `radius_xl`, `control_height/radius`, `form_ink/dim/primary/error`, `accent_soft`, typography and spacing |
|
||||
| radial: `radial_menu` | Eight rounded annular sectors, parallel 4 pt gaps, 9 pt circular corner joins, tab-accent artwork and hover, centre label/key; existing hold/flick/release dispatch | `dialog_body/border`, `form_ink/dim`, `TabAccent`, icon palette, font/spacing tokens |
|
||||
| panel: `Window`, `WindowPage` | Shared card frame, header, optional page list, bounded content and footer with a left action | `form_header/footer_height`, `form_card_width`, `form_label_width`, `control_height`, `dialog_footer/rule`, `selected_bg/ink`, spacing |
|
||||
| confirm: `Confirm`, `Tone` | Modal warning/danger/info, title/message, mono detail and ghost/cancel/primary actions | `warning`, `form_error/fill`, `accent_soft`, `form_primary`, `on_accent`, `tab_on_fill_dark`, `font_subtitle`, spacing |
|
||||
| status: `completion_text` | Compact strip readout with an optional green completion tick and caller-supplied result identity | `font_small`, `control_height`, `form_ink/success/dim`, `space_4/14` |
|
||||
| metrics: `row_height`, `table_row_height`, `header_height` | Shared control/header heights | `control_height`, `space_8`, `form_header_height` |
|
||||
| layout: `scope`, `row` | Form styling and aligned label/control columns | `form_label_width`, `form_gap_y`, `control_*`, `font_label`, `dialog_label`, `space_4/8` |
|
||||
| `caption` | Dim caption aligned beneath a control | `font_small`, `text_dim`, label-column tokens |
|
||||
@@ -141,7 +142,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
|
||||
| `message_field` | Growing message editor; owner retains scroll and Enter routing | field tokens |
|
||||
| `cell_editor`, `bounded_cell_editor`, `search_field`, `library_cell` | Stable-ID inline/search editors; bounded variant caps Unicode characters; `library_cell` attaches a Library dropdown inside the editor border | field tokens, `text/error` |
|
||||
| `text_area` | Bounded multiline JSON/data editor | field tokens |
|
||||
| `dropdown`, `dropdown_menu` | Indexed choices or caller-supplied menu controls | `control_height`, `text_dim`, form tokens |
|
||||
| `dropdown`, `dropdown_menu`, `compact_dropdown_menu` | Indexed choices or caller-supplied menu controls | `control_height`, `text_dim`, form tokens |
|
||||
| `searchable_dropdown`, `SearchOption` | Filtered choices, custom-value action and pending message | dropdown tokens |
|
||||
| `selection_field`, `Selection` | Selection chip with explicit `active` and `filled` state, in three looks: the active input (where the next pick goes) has a `form_primary` border and `selected_bg` tint; a filled inactive one a quiet neutral tint, a stronger neutral border and its count in `form_ink`; an empty inactive one the plain control with a dim prompt | `selected_bg/ink`, `form_primary/ink/dim`, `control_*`, `form_inset`, `space_2/8/24` |
|
||||
| `value_pair` | Paired captions/expressions; optional independent field names | row/field tokens, `space_8` |
|
||||
@@ -157,6 +158,7 @@ table. Panel/Window/Confirm compositions also have dedicated geometry and intera
|
||||
| `text_emphasis` | Bold/italic with translated accessible names | form control/font tokens |
|
||||
| `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 |
|
||||
| `thumbnail_choice`, `ThumbnailChoice`, `add_choice` | Shared selection-chip variant with 52 × 30 preview, selected tab accent, modified dot, progress ring and dashed add action for bottom strips; `Panel::strip_contents` reserves right actions and scrolls choices | `control_height`, spacing, radii, `TabAccent`, control/semantic 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` |
|
||||
@@ -451,8 +453,9 @@ closed** (content hidden). Only `ui_kit::disclosure` draws them, using the origi
|
||||
(as in kit section headers). Sections, nested groups, Browser trees, card headers,
|
||||
window folds and the Assistant strip all follow this rule. Keep existing scenario
|
||||
handles, including `dialog:collapse`, and translated Collapse/Expand tooltips.
|
||||
Dropdown arrows always point down; submenu arrows point right. Playback, reorder,
|
||||
window management and overflow controls are not disclosures. The source guard scans
|
||||
Dropdown arrows always point down; submenu arrows point right. Bottom-strip hide/restore
|
||||
actions use `strip_toggle` with the same down chevron and its vertical flip for up.
|
||||
Playback, reorder, window management and overflow controls are not disclosures. The source guard scans
|
||||
UI, apps and compiled asset glyphs without caller allowances; render tests inspect
|
||||
the actual icon textures used by sections, card folds and window folds.
|
||||
|
||||
|
||||
Reference in new issue
Block a user