Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge #818: fix: drop the background render when a display option changes (#730)

aiongg769b7f56d060
diff --cc crates/ui-egui/src/canvas.rs
index 0b6c5717f,a681fca91..0d73f39ff
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@@ -567,23 -365,52 +567,69 @@@ fn screen_options(app: &DesignApp, layo
}
}
+/// The area each spread's document grid covers, in spread coordinates: the full-width band of
+/// the pasteboard nearest that spread, the band in which `CanvasLayout::spread_at` (and so
+/// snapping) picks it.
+fn grid_areas(layout: &CanvasLayout) -> Vec<(designcraft_doc::SpreadRef, DRect)> {
+ let pb = layout.pasteboard;
+ let slots = &layout.slots;
+ slots
+ .iter()
+ .enumerate()
+ .map(|(i, slot)| {
+ let lo = i.checked_sub(1).and_then(|j| slots.get(j)).map_or(pb.y0, |prev| (prev.bounds.y1 + slot.bounds.y0) / 2.0);
+ let hi = slots.get(i + 1).map_or(pb.y1, |next| (slot.bounds.y1 + next.bounds.y0) / 2.0);
+ (slot.spread, slot.xf.inverse().transform_rect_bbox(DRect::new(pb.x0, lo, pb.x1, hi)))
+ })
+ .collect()
+}
+
+ /// The display options that change how the canvas texture looks without touching the document.
+ #[derive(Clone, Copy, Debug, PartialEq)]
+ pub struct DisplayKey {
+ quality: designcraft_render::DisplayQuality,
+ separation: Option<u8>,
+ rich_black: bool,
+ overprint_preview: bool,
+ proof_colors: bool,
+ tag_markers: bool,
+ highlight_substituted_fonts: bool,
+ highlight_hj: bool,
+ show_note_anchors: bool,
+ show_added_text: bool,
+ highlight_keeps: bool,
+ highlight_custom_tracking: bool,
+ }
+
+ fn display_key(app: &DesignApp) -> DisplayKey {
+ let (ui, prefs) = (&app.ui, &app.session.prefs);
+ DisplayKey {
+ quality: ui.display_quality,
+ separation: ui.separation,
+ rich_black: ui.rich_black,
+ overprint_preview: ui.overprint_preview,
+ proof_colors: ui.proof_colors,
+ tag_markers: ui.tag_markers,
+ highlight_substituted_fonts: prefs.highlight_substituted_fonts,
+ highlight_hj: prefs.highlight_hj,
+ show_note_anchors: prefs.show_note_anchors,
+ show_added_text: prefs.show_added_text,
+ highlight_keeps: prefs.highlight_keeps,
+ highlight_custom_tracking: prefs.highlight_custom_tracking,
+ }
+ }
+
+ /// When a display option changed, drop the texture and any render in flight: they were drawn with the old options.
+ fn invalidate_on_display_change(app: &mut DesignApp) {
+ let key = display_key(app);
+ if app.canvas.display_key != Some(key) {
+ app.canvas.display_key = Some(key);
+ app.canvas.shown = None;
+ app.canvas.pending = None;
+ app.canvas.pending_doc = None;
+ }
+ }
+
/// Keep the canvas texture current. Panning inside the overscanned region just shifts the
/// texture; zooming shows the old texture scaled until the background render arrives; document
/// edits render synchronously so editing never lags.