Skip to content

PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust

M7: hold an applied paragraph's look until every tile is drawn, and not after a turn

komo1iddin764439bbcc94
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 2f73aa84c..47410d404 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -1046,6 +1046,12 @@ impl DocView {
self.pages.get(&page).map(|p| p.tex.id())
}
+ /// Whether `page` is still drawn, somewhere, as it was before its last change: its whole-page
+ /// raster (a tiled page's backdrop too) or any of its tiles waits for a replacement.
+ pub(crate) fn page_out_of_date(&self, page: usize) -> bool {
+ self.pages.get(&page).is_some_and(|p| p.tag == STALE_TAG) || self.stale_tiles.iter().any(|k| k.0 == page)
+ }
+
/// The print preview's picture of `page`: the sheet raster when it has arrived, otherwise the
/// thumbnail.
pub(crate) fn page_preview(&self, page: usize) -> Option<egui::TextureId> {
@@ -1879,6 +1885,9 @@ impl DocView {
self.forms.unbaked.retain(|(_, p)| *p != page);
self.comments.page_rendered(page);
}
+ if !self.page_out_of_date(page) {
+ self.text_background.page_received(page);
+ }
} else if r.request.tag & PRINT_TAG != 0 {
let tex = ctx.load_texture(
format!("print-{:?}-{page}", self.id),
@@ -1898,7 +1907,9 @@ impl DocView {
self.pages.insert(page, PageTex { tag: r.request.tag, tex });
self.signature_drag.page_received(page);
self.move_background.page_received(page);
- self.text_background.page_received(page);
+ if !self.page_out_of_date(page) {
+ self.text_background.page_received(page);
+ }
self.comments.page_rendered(page);
self.waiting_since.remove(&page);
if !self.stale_tiles.iter().any(|k| k.0 == page) {
diff --git a/crates/ui-egui/src/edit_text_ui.rs b/crates/ui-egui/src/edit_text_ui.rs
index bb2a6bbc4..197f80c89 100644
--- a/crates/ui-egui/src/edit_text_ui.rs
+++ b/crates/ui-egui/src/edit_text_ui.rs
@@ -40,7 +40,7 @@ pub(crate) struct TextBackground {
}
/// A paragraph editor's text as last drawn: its laid-out rows, where they were on the page (in
-/// the page's 0..1 coordinates) and at what page width on screen.
+/// the page's 0..1 coordinates), and the page's width and turn on screen then.
struct EditorLook {
page: usize,
block: usize,
@@ -48,6 +48,7 @@ struct EditorLook {
at: (f32, f32),
color: Color32,
page_width: f32,
+ rot: u16,
}
impl TextBackground {
@@ -57,7 +58,7 @@ impl TextBackground {
/// The open paragraph's editor drew `galley` at `pos` this frame.
pub fn remember(&mut self, xf: &PageXform, page: usize, block: usize, galley: Arc<egui::Galley>, pos: Pos2, color: Color32) {
- self.look = Some(EditorLook { page, block, galley, at: xf.screen_to_norm(pos), color, page_width: xf.rect.width() });
+ self.look = Some(EditorLook { page, block, galley, at: xf.screen_to_norm(pos), color, page_width: xf.rect.width(), rot: xf.rot });
}
/// An edit was applied. When it is the open paragraph's, its last look stays up over the
@@ -164,9 +165,10 @@ impl TextBackground {
editor: Option<&LineEditor>,
draft: Option<&crate::content_ui::TextDraft>,
) {
- // A zoom since the paragraph was applied would misplace its rows: the page raster
- // (with the old text) shows until the new one arrives instead.
- let settled = self.settling.as_ref().filter(|look| look.page == page && (look.page_width - xf.rect.width()).abs() < 0.5);
+ // A zoom or a turn of the view since the paragraph was applied would misplace its rows:
+ // the page raster (with the old text) shows until the new one arrives instead.
+ let settled =
+ self.settling.as_ref().filter(|look| look.page == page && look.rot == xf.rot && (look.page_width - xf.rect.width()).abs() < 0.5);
let ready = editor.is_some_and(|ed| ed.page == page && self.ready(page, ed.block))
|| draft.is_some_and(|d| d.page == page && d.index.is_some_and(|index| self.ready_added(page, index)))
|| settled.is_some();