修复小壹后台制作时详情页视口移出画布
This commit is contained in:
parent
6f0d56060d
commit
727affa3bd
@ -1377,7 +1377,12 @@ impl Workspace {
|
||||
let locate = |item: &CanvasFeedback| {
|
||||
let current = app.session.active()?;
|
||||
if current.doc.id.0 != item.doc { return None; }
|
||||
location(¤t.doc, rows, &item.target, width, &self.agent_images)
|
||||
let [x, y, w, h] = location(¤t.doc, rows, &item.target, width, &self.agent_images)?;
|
||||
// Automatic feedback follows the part of the target that can actually be drawn.
|
||||
let on_canvas = Rect::from_min_size(pos2(x, y), vec2(w, h)).intersect(
|
||||
Rect::from_min_size(pos2(0.0, 0.0), vec2(current.doc.size.width as f32, current.doc.size.height as f32)),
|
||||
);
|
||||
on_canvas.is_positive().then(|| [on_canvas.min.x, on_canvas.min.y, on_canvas.width(), on_canvas.height()])
|
||||
};
|
||||
if state.feedback_display.as_ref().is_some_and(|display|
|
||||
display.feedback.doc != doc || display.motion.is_none() && now - display.arrived >= FEEDBACK_DISPLAY)
|
||||
@ -6322,6 +6327,31 @@ pub(super) mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canvas_feedback_does_not_move_the_view_to_pixels_outside_the_document() {
|
||||
let (mut w, mut app, _, _, _) = native_fixture();
|
||||
let mut pixels = photocraft_raster::Surface::new(photocraft_color::PixelFormat::RGBA8);
|
||||
pixels.fill_rect(photocraft_geom::Rect::new(-5000, -5000, -4900, -4900), &[0.2, 0.4, 0.6, 1.0]);
|
||||
let layer = photocraft_doc::Layer::new("画布外图层", LayerContent::Raster(pixels));
|
||||
let id = layer.id.0;
|
||||
app.session.edit("添加图层", move |doc, _| {
|
||||
doc.layers.push(layer);
|
||||
Ok(())
|
||||
}).unwrap();
|
||||
let doc = app.session.active().unwrap().doc.id.0;
|
||||
w.queue_canvas_feedback(doc, json!({"nativeLayerId":id}), "图层已更新");
|
||||
|
||||
let ctx = egui::Context::default();
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
let xf = ViewXform {
|
||||
rect: Rect::from_min_size(pos2(0.0, 0.0), vec2(800.0, 600.0)),
|
||||
zoom: 0.403, center: [400.0, 600.0], flip: false, rotation: 0.0, aspect: 1.0,
|
||||
};
|
||||
assert!(w.canvas_feedback(&app, ui, xf, doc, &[], 1440.0, false).is_none());
|
||||
}).drop_without_applying_deltas();
|
||||
assert!(w.canvas_workspace.feedback_display.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn canvas_feedback_waits_for_idle_and_for_the_camera_to_arrive() {
|
||||
let (mut w, mut app, requests, _, _) = native_fixture();
|
||||
let layer = add_visible_edit_target(&mut app);
|
||||
|
||||
@ -284,10 +284,13 @@ impl Workspace {
|
||||
{
|
||||
return action(self, app);
|
||||
}
|
||||
// The native tab ID is shared, but its camera belongs to the mounted output.
|
||||
worker.swap(self, app);
|
||||
worker.swap_camera(app);
|
||||
self.product_target_hidden = true;
|
||||
let result = action(self, app);
|
||||
self.product_target_hidden = false;
|
||||
worker.swap_camera(app);
|
||||
worker.swap(self, app);
|
||||
self.product_views.worker = Some(worker);
|
||||
result
|
||||
@ -679,7 +682,7 @@ impl Workspace {
|
||||
}
|
||||
app.canvases.retain(|(id, _), _| *id != doc_id);
|
||||
app.channel_views.remove(&doc_id.0);
|
||||
app.redraws.remove(&doc_id);
|
||||
crate::background_redraw::cancel(app, doc_id);
|
||||
if let Some(pending) = &mut app.product_cpu_texture {
|
||||
pending.key = None;
|
||||
}
|
||||
@ -709,17 +712,15 @@ impl Canvas {
|
||||
fn swap_view(&mut self, w: &mut Workspace, app: &mut PhotocraftApp) {
|
||||
w.canvas_workspace.finish_reference_intro();
|
||||
self.swap(w, app);
|
||||
self.swap_camera(app);
|
||||
}
|
||||
|
||||
fn swap_camera(&mut self, app: &mut PhotocraftApp) {
|
||||
if let Some(index) = app.session.active_index()
|
||||
&& let Some(view) = app.ui.views.get_mut(index)
|
||||
{
|
||||
let previous = view.clone();
|
||||
if let Some(target) = self.camera.take() {
|
||||
*view = target;
|
||||
} else {
|
||||
view.fit_pending = true;
|
||||
view.fill_pending = false;
|
||||
}
|
||||
self.camera = Some(previous);
|
||||
let target = self.camera.take().unwrap_or_default();
|
||||
self.camera = Some(std::mem::replace(view, target));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3237,6 +3238,45 @@ mod tests {
|
||||
]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn background_output_edits_keep_the_visible_canvas_camera() {
|
||||
use super::canvas_workspace::tests::native_fixture;
|
||||
|
||||
let (mut w, mut app, _, _, _) = native_fixture();
|
||||
let index = app.session.active_index().unwrap();
|
||||
let visible = app.session.active().unwrap().doc.clone();
|
||||
w.open_projects.insert(visible.id.0, w.local_identity("project"));
|
||||
let mut other = visible.as_ref().clone();
|
||||
other.size = photocraft_doc::Size::new(8000, 8000);
|
||||
w.product_views.worker = Some(Canvas {
|
||||
document: DocState::new(other, None),
|
||||
workflow: json!({"outputId":"main_images","variantId":"wood"}),
|
||||
workspace: canvas_workspace::State::default(),
|
||||
camera: None,
|
||||
});
|
||||
app.ui.views[index].center = [150.0, 120.0];
|
||||
app.ui.views[index].zoom = 0.403;
|
||||
app.ui.views[index].fit_pending = false;
|
||||
let foreground_camera = app.ui.views[index].clone();
|
||||
|
||||
w.with_product_target(&mut app, |_, app| {
|
||||
app.session.execute("layer.new.layer", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
let (request, _) = crate::control::ControlRequest::new("ui.set", json!({"center":[4000,4000]}));
|
||||
let crate::control::Outcome::Done(result) = crate::control::handle(app, &ctx, &request) else {
|
||||
panic!("camera command should complete immediately");
|
||||
};
|
||||
assert_eq!(result["ok"], true, "{result}");
|
||||
});
|
||||
assert!(Arc::ptr_eq(&app.session.active().unwrap().doc, &visible));
|
||||
assert_eq!(app.ui.views[index], foreground_camera);
|
||||
|
||||
let mut worker = w.product_views.worker.take().unwrap();
|
||||
worker.swap_view(&mut w, &mut app);
|
||||
assert_eq!(app.ui.views[index].center, [4000.0, 4000.0]);
|
||||
assert_eq!(app.session.active().unwrap().doc.layers.len(), visible.layers.len() + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shared_tab_keeps_sku_writes_and_visible_detail_edits_on_their_own_canvases() {
|
||||
use super::super::{pi_bridge, workflow_bridge};
|
||||
@ -3495,10 +3535,13 @@ mod tests {
|
||||
assert_eq!(super::super::product_document_key(&snapshot.document), w.pi_request_scope["documentKey"]);
|
||||
assert_eq!(text(&snapshot.document), "详情更新");
|
||||
assert_eq!(text(&app.session.active().unwrap().doc), "主图标题");
|
||||
let previous = &app.session.active().unwrap().doc;
|
||||
app.gpu_redraws.insert(previous.id, crate::background_redraw::GpuRedraw::new(previous.bounds(), None));
|
||||
w.slot_action(&app, "slot-skeleton", json!({"outputId":"detail","variantId":"wood"})).unwrap();
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| w.product_view_tick(&mut app, ui.ctx())).drop_without_applying_deltas();
|
||||
assert_eq!(app.session.active().unwrap().doc.name, "小壹已更新详情");
|
||||
assert_eq!(text(&app.session.active().unwrap().doc), "详情更新");
|
||||
assert!(app.gpu_redraws.is_empty());
|
||||
assert!(!w.product_view_detached());
|
||||
assert_eq!(w.pi_run.as_deref(), Some("original-run"));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user