Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4b7861c7f | ||
|
|
7d09480552 | ||
|
|
07f28df03f | ||
|
|
cde1fc8e91 | ||
|
|
b1e725ed52 | ||
|
|
406e7701ce |
No files matched your search
Generated
+1
-1
@@ -1540,7 +1540,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ink-notes"
|
||||
version = "0.45.3"
|
||||
version = "0.45.6"
|
||||
dependencies = [
|
||||
"ab_glyph",
|
||||
"android_logger",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "ink-notes"
|
||||
version = "0.45.3"
|
||||
version = "0.45.6"
|
||||
edition = "2021"
|
||||
description = "Notizbuch-App für Stift, Touch und Maus unter Linux"
|
||||
repository = "https://gitea.pansi.eu/harald/ink-notes"
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ Die Oberfläche gibt es auf Deutsch und Englisch; ink-notes folgt der Systemspra
|
||||
### Seiten und Ansicht
|
||||
- **Hintergründe:** blanko, kariert (5 mm), liniert (7,5 mm), Punktraster (5 mm). Die **Farbe von Karos, Linien und Punkten** ist wählbar (hell, mittel, kräftig, blau, grün) und gilt auch im Export.
|
||||
- **Papierfarbe** der Anzeige: weiß, creme, dunkelgrau, schwarz; auf dunklem Papier werden dunkle Stiftfarben auf Wunsch aufgehellt. Gespeichert und exportiert wird immer auf weißem Papier.
|
||||
- **Durchgehendes Scrollen, endlose Fläche oder feste Seiten, je Notizbuch:** Beim Anlegen wählbar (Vorgabe: durchgehend; oder endlos), im ☰-Menü umschaltbar – dort auch auf feste Seiten (Seite für Seite blättern mit Pfeilen in der Werkzeugleiste). Durchgehend hängen die Seiten lückenlos untereinander, eine dunkle Linie markiert die Grenze; schnelles Wischen gleitet nach, und mit der Bildlaufleiste am Rand gegenüber der Werkzeugleiste springt man samt Seitenzahl durch lange PDFs; wer im unteren Fünftel der letzten Seite schreibt, bekommt automatisch eine neue Seite. Endlos ist eine einzige Fläche ohne Rand, die oben links beginnt und nach rechts und unten beliebig weitergeht; der PDF-Export enthält nur den beschriebenen Bereich.
|
||||
- **Durchgehendes Scrollen, endlose Fläche oder feste Seiten, je Notizbuch:** Beim Anlegen wählbar (Vorgabe: durchgehend; oder endlos), im ☰-Menü umschaltbar – dort auch auf feste Seiten (Seite für Seite blättern mit Pfeilen in der Werkzeugleiste). Durchgehend hängen die Seiten lückenlos untereinander, eine dunkle Linie markiert die Grenze; schnelles Wischen gleitet nach, und mit der Bildlaufleiste neben der Werkzeugleiste (abseits der Schreibhand) springt man samt Seitenzahl durch lange PDFs; wer im unteren Fünftel der letzten Seite schreibt, bekommt automatisch eine neue Seite. Endlos ist eine einzige Fläche ohne Rand, die oben links beginnt und nach rechts und unten beliebig weitergeht; der PDF-Export enthält nur den beschriebenen Bereich.
|
||||
- **Seiten einfügen und löschen:** ➕ in der Werkzeugleiste fügt nach der aktuellen Seite eine leere Seite ein. Löschen im ☰-Menü (mit Rückfrage); die zuletzt gelöschte Seite lässt sich dort wiederherstellen, solange die App läuft.
|
||||
- **Zoom** von 25 % bis 1000 % (`Strg + Mausrad`, zwei Finger, `Strg + +/-/0`), Verschieben mit mittlerer Maustaste, `Leertaste + Ziehen` oder einem Finger.
|
||||
- **Seiten** anhängen oder direkt nach der aktuellen Seite einfügen, **Seitentitel** vergeben; die Seitenübersicht zeigt Vorschaubilder (samt importierter PDF-Seite) oder ein Inhaltsverzeichnis. Seitentitel werden im PDF zu Lesezeichen.
|
||||
|
||||
@@ -60,7 +60,7 @@ The interface is available in English and German; ink-notes follows the system l
|
||||
### Pages and view
|
||||
- **Backgrounds:** blank, squared (5 mm), ruled (7.5 mm), dot grid (5 mm). The **color of squares, lines and dots** is selectable (light, medium, strong, blue, green) and also applies to exports.
|
||||
- **Paper color** on screen: white, cream, dark gray, black; on dark paper, dark pen colors can optionally be brightened. Saving and exporting always use white paper.
|
||||
- **Continuous scrolling, endless canvas or fixed pages, per notebook:** chosen when creating a notebook (default: continuous; or endless) and switchable in the ☰ menu – where fixed pages are available too (page by page with arrows in the toolbar). In continuous mode the pages hang seamlessly below each other with a dark line marking the boundary. A quick swipe keeps gliding, and the scrollbar on the edge opposite the toolbar jumps through long PDFs with the page number shown. Writing in the bottom fifth of the last page adds a new page automatically. Endless is a single borderless canvas that grows to the right and down as far as you like, starting at the top left; the PDF export only contains the area you used.
|
||||
- **Continuous scrolling, endless canvas or fixed pages, per notebook:** chosen when creating a notebook (default: continuous; or endless) and switchable in the ☰ menu – where fixed pages are available too (page by page with arrows in the toolbar). In continuous mode the pages hang seamlessly below each other with a dark line marking the boundary. A quick swipe keeps gliding, and the scrollbar beside the toolbar (away from the writing hand) jumps through long PDFs with the page number shown. Writing in the bottom fifth of the last page adds a new page automatically. Endless is a single borderless canvas that grows to the right and down as far as you like, starting at the top left; the PDF export only contains the area you used.
|
||||
- **Insert and delete pages:** ➕ in the toolbar inserts an empty page after the current one. Delete it in the ☰ menu (with confirmation); the most recently deleted page can be restored there while the app is running.
|
||||
- **Zoom** from 25 % to 1000 % (`Ctrl + mouse wheel`, two fingers, `Ctrl + +/-/0`), pan with the middle mouse button, `Space + drag` or one finger.
|
||||
- **Pages** can be appended or inserted right after the current page, and given **page titles**; the page overview shows thumbnails (including the imported PDF page) or a table of contents. Page titles become bookmarks in the PDF.
|
||||
|
||||
@@ -101,7 +101,7 @@ Alle Koordinaten beziehen sich auf die **aktuelle Seite**. `PageStack` (`viewpor
|
||||
|
||||
Nach dem Scrollen wird die Seite in der Fenstermitte zur aktuellen Seite; die Kamera wird dabei so verschoben, dass sich das Bild nicht bewegt. Während eines Strichs, einer Auswahl, beim Ziehen des Lineals oder beim Schreiben von Text wird nicht gewechselt. Wer auf einer sichtbaren Nachbarseite zu zeichnen beginnt, wechselt zuerst auf diese Seite.
|
||||
|
||||
Schnelles Wischen mit dem Finger gleitet nach (`Fling` in `viewport.rs`): Die Geschwindigkeit wird über die letzten 100 ms vor dem Abheben gemessen und nimmt danach exponentiell ab. Die Bildlaufleiste am Rand gegenüber der Werkzeugleiste springt direkt an eine Stelle im Notizbuch.
|
||||
Schnelles Wischen mit dem Finger gleitet nach (`Fling` in `viewport.rs`): Die Geschwindigkeit wird über die letzten 100 ms vor dem Abheben gemessen und nimmt danach exponentiell ab. Die Bildlaufleiste neben der Werkzeugleiste (zur Seitenmitte hin, abseits der Schreibhand) springt direkt an eine Stelle im Notizbuch.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ All coordinates refer to the **current page**. `PageStack` (`viewport.rs`) place
|
||||
|
||||
After scrolling, the page in the middle of the window becomes the current page; the camera is shifted so that the picture does not move. There is no switch during a stroke, a selection, while dragging the ruler or while typing text. Starting to draw on a visible neighboring page switches to that page first.
|
||||
|
||||
A quick finger swipe keeps gliding (`Fling` in `viewport.rs`): the speed is measured over the last 100 ms before the finger lifts and then decays exponentially. The scrollbar on the edge opposite the toolbar jumps directly to a position in the notebook.
|
||||
A quick finger swipe keeps gliding (`Fling` in `viewport.rs`): the speed is measured over the last 100 ms before the finger lifts and then decays exponentially. The scrollbar beside the toolbar (on its inner side, away from the writing hand) jumps directly to a position in the notebook.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -178,6 +178,7 @@ Liegen die Notizbücher in einem Ordner, den Nextcloud, Google Drive, Syncthing
|
||||
- Solange alle lokalen Änderungen gespeichert sind, prüft die App den Ordner alle 3 Sekunden (und wenn das Fenster den Fokus bekommt). Geänderte Seitendateien werden neu geladen, ein geändertes `manifest.json` bringt neue, entfernte oder umsortierte Seiten und Titel mit.
|
||||
- Konfliktkopien der Sync-Clients (`page_<id> (….json`, `page_<id>_….json`, `page_<id>.sync-conflict-….json`) werden als neue Seiten hinter dem Original eingefügt und in `<name>.imported` umbenannt.
|
||||
- Bevor die App eine Seitendatei überschreibt, die sich seit ihrem letzten Lesen oder Schreiben geändert hat, sichert sie den vorgefundenen Inhalt als `page_<id> (conflict <Unix-Zeit>).json` – außer sie hat selbst nichts geändert (dann bleibt die Datei, wie sie ist).
|
||||
- Dasselbe gilt für `manifest.json`, nur werden die beiden Fassungen zusammengeführt statt kopiert: Auf beiden Seiten hinzugefügte oder entfernte Seiten, Titel und Zähler werden kombiniert, mit dem zuletzt von der App gelesenen oder geschriebenen Manifest als gemeinsamem Vorgänger.
|
||||
|
||||
### Neuere Versionen
|
||||
Dateien mit einer höheren `format_version` als der unterstützten werden nicht geöffnet – so kann eine ältere App-Version keine Inhalte verlieren, die sie nicht kennt.
|
||||
|
||||
@@ -178,6 +178,7 @@ If the notebooks are kept in a folder synced by Nextcloud, Google Drive, Syncthi
|
||||
- While all local changes are saved, the app checks the folder every 3 seconds (and when the window gets the focus). Changed page files are reloaded, a changed `manifest.json` brings in new, removed or reordered pages and titles.
|
||||
- Conflict copies of sync clients (`page_<id> (….json`, `page_<id>_….json`, `page_<id>.sync-conflict-….json`) are added as new pages after the original and renamed to `<name>.imported`.
|
||||
- Before the app overwrites a page file that changed since it last read or wrote it, it keeps the content found there as `page_<id> (conflict <unix time>).json`, unless it has no changes of its own (then the file is left as it is).
|
||||
- The same goes for `manifest.json`, except that the two versions are merged instead of copied: pages added or removed on either side, titles and counters are combined, with the manifest the app last read or wrote as common ancestor.
|
||||
|
||||
### Newer versions
|
||||
Files with a higher `format_version` than supported are not opened – this way an older app version cannot lose content it does not know.
|
||||
|
||||
@@ -84,6 +84,21 @@
|
||||
</branding>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="0.45.6" date="2026-11-16">
|
||||
<description>
|
||||
<p>The scrollbar of the continuous view now sits beside the toolbar, where the writing hand no longer touches it by accident.</p>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.45.5" date="2026-11-14">
|
||||
<description>
|
||||
<p>Extremely full pages, for example on an endless notebook, no longer end the app when they are opened.</p>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.45.4" date="2026-11-14">
|
||||
<description>
|
||||
<p>A page added on another device is no longer dropped from the notebook when a change is saved here at the same moment.</p>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.45.3" date="2026-11-14">
|
||||
<description>
|
||||
<p>Undo on a following page after "make space" no longer adds a stroke a second time.</p>
|
||||
|
||||
@@ -84,6 +84,21 @@
|
||||
</branding>
|
||||
<content_rating type="oars-1.1" />
|
||||
<releases>
|
||||
<release version="0.45.6" date="2026-11-16">
|
||||
<description>
|
||||
<p>The scrollbar of the continuous view now sits beside the toolbar, where the writing hand no longer touches it by accident.</p>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.45.5" date="2026-11-14">
|
||||
<description>
|
||||
<p>Extremely full pages, for example on an endless notebook, no longer end the app when they are opened.</p>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.45.4" date="2026-11-14">
|
||||
<description>
|
||||
<p>A page added on another device is no longer dropped from the notebook when a change is saved here at the same moment.</p>
|
||||
</description>
|
||||
</release>
|
||||
<release version="0.45.3" date="2026-11-14">
|
||||
<description>
|
||||
<p>Undo on a following page after "make space" no longer adds a stroke a second time.</p>
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
Notebook app for pen, touch and mouse on Linux (tested on Zorin OS 18 / Ubuntu 24.04).
|
||||
|
||||
### Highlights:
|
||||
- **Scrollbar away from the writing hand**: The scrollbar of the continuous view sat on the edge opposite the toolbar, right where the writing hand rests, so a palm could make the view jump (left-handers with the toolbar on the right were hit hardest). It now sits directly beside the toolbar (#58)
|
||||
- **Extremely full pages**: A page with so many strokes that they no longer fit into one graphics buffer (possible on an endless notebook) ended the app when it was opened. Such pages are now drawn from several buffers
|
||||
- **Sync while writing, page list**: If another device added a page just while you were writing, saving here could drop that page from the notebook's page list. The two page lists are now merged: pages added or removed on either device, titles and counters are combined
|
||||
- **Undo after "make space"**: Making space moves the content of the following pages, sometimes onto the next page. Undoing and redoing an older step on such a page could then add a stroke a second time. The older steps of the following pages are now set aside while the space is there and come back when making space is undone
|
||||
- **Sync while writing**: If a change from another device reached a page just while you were writing on it, saving your stroke overwrote that change. Now your version is saved and theirs is kept as a page of its own ("Conflict copy: …"), as for other sync conflicts; if you changed nothing on the page, their version is simply taken over
|
||||
- **Safer notes**: A review of the whole project fixed a number of rare errors. Notebooks deleted after not being edited for 30 days were removed from the trash at the next start instead of 30 days later. If saving failed while switching notebooks, pages could end up in the other notebook, and an open text field moved along; the app now saves first and stays in the notebook if that fails. A copied notebook folder is a notebook of its own instead of opening the original. Strokes keep their width after scaling and a restart, shapes are exported to PDF with their line width, and a page that could not be loaded always shows its warning. Importing broken Rnote, Saber, SVG or PDF files can no longer make a page unreadable or stop the PDF display. One invalid value in the settings file no longer resets all settings, and updates are only installed if the signed package is newer than the running version
|
||||
|
||||
+330
-77
@@ -160,8 +160,120 @@ struct NeighborPage {
|
||||
/// Papier (Dreiecke) und Muster (Rechteck für `fs_pattern`)
|
||||
paper_buffer: wgpu::Buffer,
|
||||
pattern_buffer: Option<wgpu::Buffer>,
|
||||
vertex_buffer: Option<wgpu::Buffer>,
|
||||
stroke_ranges: Vec<Range<u32>>,
|
||||
strokes: StrokeBuffers,
|
||||
}
|
||||
|
||||
/// Part of a page's stroke vertices that goes into one GPU buffer.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
struct ChunkPlan {
|
||||
/// Position in the page's vertex cache
|
||||
vertices: Range<usize>,
|
||||
/// The strokes in it, relative to the start of the chunk
|
||||
strokes: Vec<Range<u32>>,
|
||||
}
|
||||
|
||||
/// Splits the strokes of a page (ranges in its vertex cache) into runs of at most
|
||||
/// `max_vertices`, without cutting a stroke. Nearly every page is a single run; only a huge
|
||||
/// one, in practice an endless page, needs more than one buffer. A single stroke larger than
|
||||
/// a buffer cannot be drawn and is left out.
|
||||
fn plan_stroke_chunks(stroke_ranges: &[Range<u32>], max_vertices: usize) -> Vec<ChunkPlan> {
|
||||
let mut chunks: Vec<ChunkPlan> = Vec::new();
|
||||
for range in stroke_ranges {
|
||||
let (start, end) = (range.start as usize, range.end as usize);
|
||||
if end <= start || end - start > max_vertices {
|
||||
continue;
|
||||
}
|
||||
let fits = chunks
|
||||
.last()
|
||||
.is_some_and(|c| c.vertices.end == start && end - c.vertices.start <= max_vertices);
|
||||
if !fits {
|
||||
chunks.push(ChunkPlan {
|
||||
vertices: start..start,
|
||||
strokes: Vec::new(),
|
||||
});
|
||||
}
|
||||
if let Some(chunk) = chunks.last_mut() {
|
||||
let offset = (start - chunk.vertices.start) as u32;
|
||||
chunk.strokes.push(offset..offset + (end - start) as u32);
|
||||
chunk.vertices.end = end;
|
||||
}
|
||||
}
|
||||
chunks
|
||||
}
|
||||
|
||||
struct StrokeChunk {
|
||||
buffer: wgpu::Buffer,
|
||||
/// In vertices
|
||||
capacity: usize,
|
||||
strokes: Vec<Range<u32>>,
|
||||
}
|
||||
|
||||
/// The finished strokes of a page on the GPU, in as many vertex buffers as the size limit
|
||||
/// of the device requires (one buffer beyond the limit is a validation error that ends the
|
||||
/// app).
|
||||
#[derive(Default)]
|
||||
struct StrokeBuffers {
|
||||
chunks: Vec<StrokeChunk>,
|
||||
/// Chunks holding the current content; further ones are kept for their capacity
|
||||
used: usize,
|
||||
}
|
||||
|
||||
impl StrokeBuffers {
|
||||
/// Uploads the vertex cache of a page. `spare` leaves room for more strokes (at least
|
||||
/// that many vertices and twice the need), so drawing does not reallocate every time.
|
||||
fn upload(
|
||||
&mut self,
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
vertices: &[InkVertex],
|
||||
stroke_ranges: &[Range<u32>],
|
||||
spare: Option<usize>,
|
||||
) {
|
||||
let vertex_size = std::mem::size_of::<InkVertex>();
|
||||
let max_vertices = (device.limits().max_buffer_size / vertex_size as u64) as usize;
|
||||
let mut used = 0;
|
||||
for part in plan_stroke_chunks(stroke_ranges, max_vertices) {
|
||||
let Some(data) = vertices.get(part.vertices.clone()) else {
|
||||
continue;
|
||||
};
|
||||
if self
|
||||
.chunks
|
||||
.get(used)
|
||||
.is_none_or(|c| c.capacity < data.len())
|
||||
{
|
||||
let capacity = match spare {
|
||||
Some(initial) => grown_vertex_capacity(data.len(), initial, max_vertices),
|
||||
None => data.len(),
|
||||
};
|
||||
let chunk = StrokeChunk {
|
||||
buffer: device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Strokes Vertex Buffer"),
|
||||
size: (capacity * vertex_size) as u64,
|
||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
}),
|
||||
capacity,
|
||||
strokes: Vec::new(),
|
||||
};
|
||||
if used < self.chunks.len() {
|
||||
self.chunks[used] = chunk;
|
||||
} else {
|
||||
self.chunks.push(chunk);
|
||||
}
|
||||
}
|
||||
let chunk = &mut self.chunks[used];
|
||||
queue.write_buffer(&chunk.buffer, 0, bytemuck::cast_slice(data));
|
||||
chunk.strokes = part.strokes;
|
||||
used += 1;
|
||||
}
|
||||
self.used = used;
|
||||
// Keep the first buffer for the next page, give the memory of the others back
|
||||
self.chunks.truncate(used.max(1));
|
||||
}
|
||||
|
||||
fn in_use(&self) -> &[StrokeChunk] {
|
||||
&self.chunks[..self.used.min(self.chunks.len())]
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CanvasState {
|
||||
@@ -238,10 +350,7 @@ pub struct CanvasState {
|
||||
pub spline_config: SplineConfig,
|
||||
|
||||
// Pipeline-Trennung: Abgeschlossene Striche der aktuellen Seite
|
||||
pub committed_vertex_buffer: wgpu::Buffer,
|
||||
pub committed_vertex_capacity: usize,
|
||||
pub committed_vertex_count: u32,
|
||||
pub committed_strokes: Vec<Range<u32>>,
|
||||
committed: StrokeBuffers,
|
||||
|
||||
// Eingefügte Bilder der aktuellen Seite
|
||||
image_layer: crate::image_layer::ImageLayer,
|
||||
@@ -575,13 +684,6 @@ impl CanvasState {
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let committed_vertex_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Committed Strokes Vertex Buffer"),
|
||||
size: (Self::INITIAL_COMMITTED_CAPACITY * std::mem::size_of::<InkVertex>()) as u64,
|
||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let image_layer = crate::image_layer::ImageLayer::new(
|
||||
&device,
|
||||
&shader,
|
||||
@@ -641,10 +743,7 @@ impl CanvasState {
|
||||
max_radius: 3.75, // 0.375 mm bei vollem Druck
|
||||
samples_per_segment: 16,
|
||||
},
|
||||
committed_vertex_buffer,
|
||||
committed_vertex_capacity: Self::INITIAL_COMMITTED_CAPACITY,
|
||||
committed_vertex_count: 0,
|
||||
committed_strokes: Vec::with_capacity(128),
|
||||
committed: StrokeBuffers::default(),
|
||||
image_layer,
|
||||
neighbors: Vec::new(),
|
||||
camera_layout: bind_group_layout,
|
||||
@@ -1013,33 +1112,12 @@ impl CanvasState {
|
||||
let quads = self.page_image_quads(page, self.hidden_text);
|
||||
self.image_layer.set_quads(quads);
|
||||
|
||||
self.committed_vertex_count = page.vertex_cache.len() as u32;
|
||||
self.committed_strokes = page.stroke_ranges.clone();
|
||||
|
||||
if page.vertex_cache.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
if page.vertex_cache.len() > self.committed_vertex_capacity {
|
||||
let vertex_size = std::mem::size_of::<InkVertex>() as u64;
|
||||
let max_vertices = (self.device.limits().max_buffer_size / vertex_size) as usize;
|
||||
self.committed_vertex_capacity = grown_vertex_capacity(
|
||||
page.vertex_cache.len(),
|
||||
Self::INITIAL_COMMITTED_CAPACITY,
|
||||
max_vertices,
|
||||
);
|
||||
self.committed_vertex_buffer = self.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Committed Strokes Vertex Buffer (Reallocated)"),
|
||||
size: (self.committed_vertex_capacity * std::mem::size_of::<InkVertex>()) as u64,
|
||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
}
|
||||
|
||||
self.queue.write_buffer(
|
||||
&self.committed_vertex_buffer,
|
||||
0,
|
||||
bytemuck::cast_slice(&page.vertex_cache),
|
||||
self.committed.upload(
|
||||
&self.device,
|
||||
&self.queue,
|
||||
&page.vertex_cache,
|
||||
&page.stroke_ranges,
|
||||
Some(Self::INITIAL_COMMITTED_CAPACITY),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1084,19 +1162,14 @@ impl CanvasState {
|
||||
resource: camera_buffer.as_entire_binding(),
|
||||
}],
|
||||
});
|
||||
let vertex_buffer_with = |label: &str, vertices: &[InkVertex]| {
|
||||
(!vertices.is_empty()).then(|| {
|
||||
let buffer = self.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some(label),
|
||||
size: std::mem::size_of_val(vertices) as u64,
|
||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
self.queue
|
||||
.write_buffer(&buffer, 0, bytemuck::cast_slice(vertices));
|
||||
buffer
|
||||
})
|
||||
};
|
||||
let mut strokes = StrokeBuffers::default();
|
||||
strokes.upload(
|
||||
&self.device,
|
||||
&self.queue,
|
||||
&page.vertex_cache,
|
||||
&page.stroke_ranges,
|
||||
None,
|
||||
);
|
||||
// Eigenes Papier und Muster (Nachbarseiten können anders groß sein)
|
||||
let paper = generate_paper_quad(self.paper_theme.paper_color(), page.size);
|
||||
let pattern = generate_pattern_quad(
|
||||
@@ -1130,8 +1203,7 @@ impl CanvasState {
|
||||
camera_bind_group,
|
||||
paper_buffer,
|
||||
pattern_buffer,
|
||||
vertex_buffer: vertex_buffer_with("Neighbor Strokes Buffer", &page.vertex_cache),
|
||||
stroke_ranges: page.stroke_ranges.clone(),
|
||||
strokes,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1492,14 +1564,12 @@ impl CanvasState {
|
||||
render_pass.draw(0..6, 0..1);
|
||||
}
|
||||
self.image_layer.draw(&mut render_pass, i + 1);
|
||||
if let Some(buffer) = &neighbor.vertex_buffer {
|
||||
render_pass.set_pipeline(&self.strip_pipeline);
|
||||
render_pass.set_vertex_buffer(0, buffer.slice(..));
|
||||
for range in &neighbor.stroke_ranges {
|
||||
if range.end > range.start {
|
||||
self.next_stroke_stencil(&mut render_pass, &mut stencil_ref);
|
||||
render_pass.draw(range.clone(), 0..1);
|
||||
}
|
||||
render_pass.set_pipeline(&self.strip_pipeline);
|
||||
for chunk in neighbor.strokes.in_use() {
|
||||
render_pass.set_vertex_buffer(0, chunk.buffer.slice(..));
|
||||
for range in &chunk.strokes {
|
||||
self.next_stroke_stencil(&mut render_pass, &mut stencil_ref);
|
||||
render_pass.draw(range.clone(), 0..1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1525,13 +1595,11 @@ impl CanvasState {
|
||||
// 4. Abgeschlossene Striche der aktiven Seite rendern (TriangleStrip mit Vertex-Farben)
|
||||
render_pass.set_pipeline(&self.strip_pipeline);
|
||||
|
||||
if self.committed_vertex_count > 0 {
|
||||
render_pass.set_vertex_buffer(0, self.committed_vertex_buffer.slice(..));
|
||||
for range in &self.committed_strokes {
|
||||
if range.end > range.start {
|
||||
self.next_stroke_stencil(&mut render_pass, &mut stencil_ref);
|
||||
render_pass.draw(range.clone(), 0..1);
|
||||
}
|
||||
for chunk in self.committed.in_use() {
|
||||
render_pass.set_vertex_buffer(0, chunk.buffer.slice(..));
|
||||
for range in &chunk.strokes {
|
||||
self.next_stroke_stencil(&mut render_pass, &mut stencil_ref);
|
||||
render_pass.draw(range.clone(), 0..1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1741,9 +1809,7 @@ fn text_resolution(screen_px_per_unit: f32) -> f32 {
|
||||
}
|
||||
|
||||
/// Capacity for a vertex buffer that has to hold `needed` vertices: twice as much, so that
|
||||
/// it is not reallocated with every stroke, but no more than the device allows. Doubling
|
||||
/// alone asked for a buffer beyond the limit as soon as a very full page used half of it,
|
||||
/// which ends in a validation panic.
|
||||
/// it is not reallocated with every stroke, but no more than the device allows.
|
||||
fn grown_vertex_capacity(needed: usize, initial: usize, max_vertices: usize) -> usize {
|
||||
needed
|
||||
.saturating_mul(2)
|
||||
@@ -1756,6 +1822,193 @@ fn grown_vertex_capacity(needed: usize, initial: usize, max_vertices: usize) ->
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::single_range_in_vec_init)]
|
||||
fn test_strokes_are_split_into_buffers_within_the_limit() {
|
||||
// The usual case: one buffer, ranges as in the vertex cache
|
||||
let ranges = vec![0..10, 10..10, 10..25, 25..40];
|
||||
let plan = plan_stroke_chunks(&ranges, 1000);
|
||||
assert_eq!(
|
||||
plan,
|
||||
vec![ChunkPlan {
|
||||
vertices: 0..40,
|
||||
strokes: vec![0..10, 10..25, 25..40],
|
||||
}]
|
||||
);
|
||||
|
||||
// More than fits: several buffers, no stroke cut, ranges relative to their buffer
|
||||
let plan = plan_stroke_chunks(&ranges, 30);
|
||||
assert_eq!(
|
||||
plan,
|
||||
vec![
|
||||
ChunkPlan {
|
||||
vertices: 0..25,
|
||||
strokes: vec![0..10, 10..25],
|
||||
},
|
||||
ChunkPlan {
|
||||
vertices: 25..40,
|
||||
strokes: vec![0..15],
|
||||
},
|
||||
]
|
||||
);
|
||||
assert!(plan.iter().all(|c| c.vertices.len() <= 30));
|
||||
|
||||
// A stroke larger than a buffer is left out, the others are still drawn
|
||||
let plan = plan_stroke_chunks(&[0..10, 10..60, 60..70], 30);
|
||||
assert_eq!(
|
||||
plan,
|
||||
vec![
|
||||
ChunkPlan {
|
||||
vertices: 0..10,
|
||||
strokes: vec![0..10],
|
||||
},
|
||||
ChunkPlan {
|
||||
vertices: 60..70,
|
||||
strokes: vec![0..10],
|
||||
},
|
||||
]
|
||||
);
|
||||
assert!(plan_stroke_chunks(&[], 30).is_empty());
|
||||
}
|
||||
|
||||
/// Uploads and draws a page whose strokes exceed the buffer limit of a real device (the
|
||||
/// limit is set very low for the test). Skipped where no graphics adapter is available.
|
||||
#[test]
|
||||
fn test_page_beyond_the_buffer_limit_is_drawn_from_several_buffers() {
|
||||
let vertex_size = std::mem::size_of::<InkVertex>() as u64;
|
||||
// 40 vertices per buffer
|
||||
let limits = wgpu::Limits {
|
||||
max_buffer_size: 40 * vertex_size,
|
||||
..wgpu::Limits::default()
|
||||
};
|
||||
let instance = wgpu::Instance::default();
|
||||
let mut found = None;
|
||||
for force_fallback_adapter in [false, true] {
|
||||
let options = wgpu::RequestAdapterOptions {
|
||||
force_fallback_adapter,
|
||||
..Default::default()
|
||||
};
|
||||
if let Some(adapter) = pollster::block_on(instance.request_adapter(&options)) {
|
||||
let descriptor = wgpu::DeviceDescriptor {
|
||||
label: None,
|
||||
required_features: wgpu::Features::empty(),
|
||||
required_limits: limits.clone(),
|
||||
};
|
||||
if let Ok(pair) = pollster::block_on(adapter.request_device(&descriptor, None)) {
|
||||
found = Some(pair);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some((device, queue)) = found else {
|
||||
eprintln!("no graphics adapter, test skipped");
|
||||
return;
|
||||
};
|
||||
|
||||
// 10 strokes of 12 vertices: 120 vertices, three times the limit
|
||||
let vertices = vec![InkVertex::new(0.0, 0.0, [0.0, 0.0, 0.0, 1.0]); 120];
|
||||
let ranges: Vec<Range<u32>> = (0..10).map(|i| i * 12..(i + 1) * 12).collect();
|
||||
|
||||
// The limit is real: one buffer for everything is refused
|
||||
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
||||
let _ = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: None,
|
||||
size: vertices.len() as u64 * vertex_size,
|
||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
assert!(pollster::block_on(device.pop_error_scope()).is_some());
|
||||
|
||||
device.push_error_scope(wgpu::ErrorFilter::Validation);
|
||||
let mut strokes = StrokeBuffers::default();
|
||||
strokes.upload(&device, &queue, &vertices, &ranges, Some(16));
|
||||
assert_eq!(strokes.in_use().len(), 4);
|
||||
let drawn: usize = strokes.in_use().iter().map(|c| c.strokes.len()).sum();
|
||||
assert_eq!(drawn, 10);
|
||||
|
||||
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
|
||||
label: None,
|
||||
source: wgpu::ShaderSource::Wgsl(
|
||||
"@vertex fn vs(@location(0) p: vec2<f32>, @location(1) c: vec4<f32>)
|
||||
-> @builtin(position) vec4<f32> { return vec4<f32>(p, 0.0, 1.0) + c * 0.0; }
|
||||
@fragment fn fs() -> @location(0) vec4<f32> { return vec4<f32>(1.0); }"
|
||||
.into(),
|
||||
),
|
||||
});
|
||||
let format = wgpu::TextureFormat::Rgba8Unorm;
|
||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: None,
|
||||
layout: None,
|
||||
vertex: wgpu::VertexState {
|
||||
module: &shader,
|
||||
entry_point: "vs",
|
||||
buffers: &[InkVertex::desc()],
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
entry_point: "fs",
|
||||
targets: &[Some(format.into())],
|
||||
}),
|
||||
primitive: wgpu::PrimitiveState {
|
||||
topology: wgpu::PrimitiveTopology::TriangleStrip,
|
||||
..Default::default()
|
||||
},
|
||||
depth_stencil: None,
|
||||
multisample: wgpu::MultisampleState::default(),
|
||||
multiview: None,
|
||||
});
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: None,
|
||||
size: wgpu::Extent3d {
|
||||
width: 16,
|
||||
height: 16,
|
||||
depth_or_array_layers: 1,
|
||||
},
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format,
|
||||
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
view_formats: &[],
|
||||
});
|
||||
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
let mut encoder = device.create_command_encoder(&Default::default());
|
||||
{
|
||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: None,
|
||||
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
|
||||
view: &view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
|
||||
store: wgpu::StoreOp::Store,
|
||||
},
|
||||
})],
|
||||
depth_stencil_attachment: None,
|
||||
timestamp_writes: None,
|
||||
occlusion_query_set: None,
|
||||
});
|
||||
pass.set_pipeline(&pipeline);
|
||||
for chunk in strokes.in_use() {
|
||||
pass.set_vertex_buffer(0, chunk.buffer.slice(..));
|
||||
for range in &chunk.strokes {
|
||||
pass.draw(range.clone(), 0..1);
|
||||
}
|
||||
}
|
||||
}
|
||||
queue.submit(std::iter::once(encoder.finish()));
|
||||
device.poll(wgpu::Maintain::Wait);
|
||||
let error = pollster::block_on(device.pop_error_scope());
|
||||
assert!(error.is_none(), "{error:?}");
|
||||
|
||||
// A smaller page afterwards uses one buffer again and frees the others
|
||||
strokes.upload(&device, &queue, &vertices[..24], &ranges[..2], Some(16));
|
||||
assert_eq!(strokes.in_use().len(), 1);
|
||||
assert_eq!(strokes.chunks.len(), 1);
|
||||
strokes.upload(&device, &queue, &[], &[], Some(16));
|
||||
assert!(strokes.in_use().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vertex_capacity_doubles_up_to_the_device_limit() {
|
||||
assert_eq!(grown_vertex_capacity(10, 1000, 1_000_000), 1000);
|
||||
|
||||
+107
-2
@@ -166,12 +166,16 @@ impl DiskWatch {
|
||||
// Page order, titles, new and removed pages
|
||||
let mut fresh_pages: HashSet<u64> = HashSet::new();
|
||||
if changed("manifest.json") {
|
||||
match storage::load_manifest(&self.dir) {
|
||||
Ok(theirs) => match self.apply_manifest(notebook, manifest, theirs) {
|
||||
match storage::load_manifest_as_base(&self.dir) {
|
||||
Ok((theirs, base)) => match self.apply_manifest(notebook, manifest, theirs) {
|
||||
// Taken over: from now on our saves build on this manifest
|
||||
Ok(Some(new_ids)) => {
|
||||
base.adopt();
|
||||
fresh_pages = new_ids;
|
||||
outcome.structure_changed = true;
|
||||
}
|
||||
// Nothing to take over for the pages. Whatever else differs is merged
|
||||
// at the next save, so the base stays as it is.
|
||||
Ok(None) => {}
|
||||
Err(()) => {
|
||||
retry.insert("manifest.json".to_string());
|
||||
@@ -557,6 +561,107 @@ mod tests {
|
||||
assert_eq!(conflict_copies(dir.path()).len(), 1);
|
||||
}
|
||||
|
||||
/// Writes the manifest the way a sync client does: behind the back of `storage`.
|
||||
fn write_manifest_from_another_device(dir: &Path, manifest: &NotebookManifest) {
|
||||
fs::write(
|
||||
dir.join("manifest.json"),
|
||||
serde_json::to_vec(manifest).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn page_ids_on_disk(dir: &Path) -> Vec<u64> {
|
||||
let bytes = fs::read(dir.join("manifest.json")).unwrap();
|
||||
let manifest: NotebookManifest = serde_json::from_slice(&bytes).unwrap();
|
||||
manifest.pages.iter().map(|p| p.id).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_saving_the_manifest_keeps_a_page_added_on_another_device() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (mut notebook, mut manifest) = saved_notebook(dir.path());
|
||||
let now = Instant::now();
|
||||
let mut watch = DiskWatch::new(dir.path().to_path_buf(), now);
|
||||
|
||||
// The other device adds a second page
|
||||
let mut theirs = notebook.clone();
|
||||
let mut their_manifest = manifest.clone();
|
||||
let index = theirs.add_page(PageBackground::Lined);
|
||||
theirs.pages[index].add_stroke(stroke(6, 400.0));
|
||||
theirs.next_stroke_id = 7;
|
||||
their_manifest.sync_from_notebook(&theirs);
|
||||
write_from_another_device(dir.path(), &theirs.pages[index]);
|
||||
write_manifest_from_another_device(dir.path(), &their_manifest);
|
||||
let their_page = theirs.pages[index].id;
|
||||
|
||||
// Before the check ran, a stroke is drawn and saved here, twice
|
||||
for id in [2, 3] {
|
||||
notebook.current_page_mut().add_stroke(stroke(id, 200.0));
|
||||
notebook.next_stroke_id = id + 1;
|
||||
manifest.sync_from_notebook(¬ebook);
|
||||
storage::save_page(dir.path(), &PageData::from(notebook.current_page())).unwrap();
|
||||
storage::save_manifest(dir.path(), &manifest).unwrap();
|
||||
assert_eq!(page_ids_on_disk(dir.path()), vec![1, their_page]);
|
||||
}
|
||||
|
||||
// The check takes their page over, and saving stays an ordinary save afterwards
|
||||
let outcome = watch.check(&mut notebook, &mut manifest, now);
|
||||
assert!(outcome.structure_changed);
|
||||
assert_eq!(notebook.pages.len(), 2);
|
||||
assert_eq!(notebook.pages[0].strokes.len(), 3);
|
||||
assert!(notebook.next_stroke_id >= 7);
|
||||
manifest.sync_from_notebook(¬ebook);
|
||||
storage::save_manifest(dir.path(), &manifest).unwrap();
|
||||
assert_eq!(page_ids_on_disk(dir.path()), vec![1, their_page]);
|
||||
|
||||
// A page removed here afterwards is really gone
|
||||
notebook.pages.pop();
|
||||
notebook.current_page_index = 0;
|
||||
manifest.sync_from_notebook(¬ebook);
|
||||
storage::save_manifest(dir.path(), &manifest).unwrap();
|
||||
assert_eq!(page_ids_on_disk(dir.path()), vec![1]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_saving_an_unchanged_manifest_keeps_the_one_from_another_device() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (notebook, manifest) = saved_notebook(dir.path());
|
||||
|
||||
let mut their_manifest = manifest.clone();
|
||||
their_manifest.title = "Physik".to_string();
|
||||
write_manifest_from_another_device(dir.path(), &their_manifest);
|
||||
|
||||
storage::save_manifest(dir.path(), &manifest).unwrap();
|
||||
let bytes = fs::read(dir.path().join("manifest.json")).unwrap();
|
||||
let on_disk: NotebookManifest = serde_json::from_slice(&bytes).unwrap();
|
||||
assert_eq!(on_disk.title, "Physik");
|
||||
drop(notebook);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_manifest_changed_on_both_sides_is_merged() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let (mut notebook, mut manifest) = saved_notebook(dir.path());
|
||||
let ours_new = notebook.add_page(PageBackground::Blank);
|
||||
let ours_new = notebook.pages[ours_new].id;
|
||||
manifest.sync_from_notebook(¬ebook);
|
||||
storage::save_manifest(dir.path(), &manifest).unwrap();
|
||||
|
||||
// They rename the notebook; we remove our new page again
|
||||
let mut their_manifest = manifest.clone();
|
||||
their_manifest.title = "Physik".to_string();
|
||||
write_manifest_from_another_device(dir.path(), &their_manifest);
|
||||
notebook.pages.pop();
|
||||
notebook.current_page_index = 0;
|
||||
manifest.sync_from_notebook(¬ebook);
|
||||
storage::save_manifest(dir.path(), &manifest).unwrap();
|
||||
|
||||
let bytes = fs::read(dir.path().join("manifest.json")).unwrap();
|
||||
let on_disk: NotebookManifest = serde_json::from_slice(&bytes).unwrap();
|
||||
assert_eq!(on_disk.title, "Physik");
|
||||
assert!(!on_disk.pages.iter().any(|p| p.id == ours_new));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_page_still_being_synced_is_tried_again() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
+85
-13
@@ -590,16 +590,32 @@ pub fn atomic_write_json<T: Serialize>(path: &Path, value: &T) -> Result<(), Sto
|
||||
|
||||
/// Speichert das Manifest atomar in `manifest.json`.
|
||||
/// Sichert das bisherige Manifest als `manifest.json.bak` vor dem Überschreiben.
|
||||
///
|
||||
/// Like a page (see [`save_page`]), the manifest may have been changed behind our back by a
|
||||
/// sync before `disk_watch` took the change over, e.g. the other device added a page.
|
||||
/// Overwriting it would drop that page from the list. The manifest on disk is therefore
|
||||
/// merged with ours, with the manifest the notebook in memory is based on as common ancestor
|
||||
/// ([`ManifestBase`]); if we have nothing new ourselves, theirs simply stays.
|
||||
pub fn save_manifest(notebook_dir: &Path, manifest: &NotebookManifest) -> Result<(), StorageError> {
|
||||
let path = notebook_dir.join("manifest.json");
|
||||
if path.exists() {
|
||||
let ours = serde_json::to_vec(manifest)?;
|
||||
let key = seen_key(&path);
|
||||
let mut merged = None;
|
||||
if let Ok(theirs) = fs::read(&path) {
|
||||
let base = manifest_bases().get(&key).cloned();
|
||||
if base.as_ref() != Some(&theirs) && theirs != ours {
|
||||
if base.as_ref() == Some(&ours) {
|
||||
// Nothing changed here since the notebook was loaded or last saved
|
||||
return Ok(());
|
||||
}
|
||||
// Theirs unreadable (e.g. half written): ours replaces it
|
||||
merged = merge_manifests(base.as_deref(), &ours, &theirs);
|
||||
}
|
||||
let bak_path = notebook_dir.join("manifest.json.v0.bak");
|
||||
if !bak_path.exists() {
|
||||
if let Ok(content) = fs::read_to_string(&path) {
|
||||
if let Ok(old_m) = serde_json::from_str::<NotebookManifest>(&content) {
|
||||
if old_m.format_version == 0 {
|
||||
let _ = fs::copy(&path, &bak_path);
|
||||
}
|
||||
if let Ok(old_m) = serde_json::from_slice::<NotebookManifest>(&theirs) {
|
||||
if old_m.format_version == 0 {
|
||||
let _ = fs::copy(&path, &bak_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -607,10 +623,51 @@ pub fn save_manifest(notebook_dir: &Path, manifest: &NotebookManifest) -> Result
|
||||
let rolling_bak = notebook_dir.join("manifest.json.bak");
|
||||
let _ = fs::copy(&path, &rolling_bak);
|
||||
}
|
||||
atomic_write_json(&path, manifest)
|
||||
atomic_write_file(&path, merged.as_ref().unwrap_or(&ours))?;
|
||||
// Ours, not the merged file: the notebook in memory does not contain their part until
|
||||
// `disk_watch` has taken it over, so the next save has to merge it in again
|
||||
manifest_bases().insert(key, ours);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn load_manifest_from_file(path: &Path) -> Result<NotebookManifest, StorageError> {
|
||||
/// Three-way merge of manifests as JSON (page lists by page id, see
|
||||
/// `cloud_sync::merge_json`); `None` if one of them can't be read or the result is no
|
||||
/// valid manifest.
|
||||
fn merge_manifests(base: Option<&[u8]>, ours: &[u8], theirs: &[u8]) -> Option<Vec<u8>> {
|
||||
let ours: serde_json::Value = serde_json::from_slice(ours).ok()?;
|
||||
let theirs: serde_json::Value = serde_json::from_slice(theirs).ok()?;
|
||||
let base: Option<serde_json::Value> = base.and_then(|b| serde_json::from_slice(b).ok());
|
||||
let merged = crate::cloud_sync::merge_json(base.as_ref(), &ours, &theirs);
|
||||
serde_json::from_value::<NotebookManifest>(merged.clone()).ok()?;
|
||||
serde_json::to_vec(&merged).ok()
|
||||
}
|
||||
|
||||
/// Content of `manifest.json` that the notebooks in memory are based on, by file.
|
||||
fn manifest_bases() -> std::sync::MutexGuard<'static, std::collections::HashMap<PathBuf, Vec<u8>>> {
|
||||
static BASES: std::sync::OnceLock<
|
||||
std::sync::Mutex<std::collections::HashMap<PathBuf, Vec<u8>>>,
|
||||
> = std::sync::OnceLock::new();
|
||||
BASES
|
||||
.get_or_init(Default::default)
|
||||
.lock()
|
||||
.unwrap_or_else(|e| e.into_inner())
|
||||
}
|
||||
|
||||
/// A manifest as read from disk, to be declared the state the notebook in memory is based on
|
||||
/// once it has been taken over (see [`save_manifest`]). Reading a manifest alone, e.g. for
|
||||
/// the list of notebooks, must not do that.
|
||||
pub struct ManifestBase {
|
||||
key: PathBuf,
|
||||
bytes: Vec<u8>,
|
||||
}
|
||||
|
||||
impl ManifestBase {
|
||||
pub fn adopt(self) {
|
||||
manifest_bases().insert(self.key, self.bytes);
|
||||
}
|
||||
}
|
||||
|
||||
fn load_manifest_from_file(path: &Path) -> Result<(NotebookManifest, Vec<u8>), StorageError> {
|
||||
let mut file = File::open(path)?;
|
||||
let mut json_str = String::new();
|
||||
file.read_to_string(&mut json_str)?;
|
||||
@@ -630,7 +687,7 @@ fn load_manifest_from_file(path: &Path) -> Result<NotebookManifest, StorageError
|
||||
.map(|&id| PageMeta::new(id, None))
|
||||
.collect();
|
||||
}
|
||||
Ok(manifest)
|
||||
Ok((manifest, json_str.into_bytes()))
|
||||
}
|
||||
|
||||
/// Lädt das Manifest aus `manifest.json`.
|
||||
@@ -640,7 +697,15 @@ fn load_manifest_from_file(path: &Path) -> Result<NotebookManifest, StorageError
|
||||
/// `<base>/<id>`. A copied or renamed folder still carries the id of the original in its
|
||||
/// manifest, so the id is always taken from the folder.
|
||||
pub fn load_manifest(notebook_dir: &Path) -> Result<NotebookManifest, StorageError> {
|
||||
let mut manifest = load_manifest_or_backup(notebook_dir)?;
|
||||
load_manifest_as_base(notebook_dir).map(|(manifest, _)| manifest)
|
||||
}
|
||||
|
||||
/// Like [`load_manifest`], for a manifest that is taken over into the open notebook: call
|
||||
/// [`ManifestBase::adopt`] once that has happened.
|
||||
pub fn load_manifest_as_base(
|
||||
notebook_dir: &Path,
|
||||
) -> Result<(NotebookManifest, ManifestBase), StorageError> {
|
||||
let (mut manifest, bytes) = load_manifest_or_backup(notebook_dir)?;
|
||||
// Canonical, so that a path like `.` still yields the folder name
|
||||
let dir = notebook_dir.canonicalize();
|
||||
let name = dir
|
||||
@@ -653,10 +718,16 @@ pub fn load_manifest(notebook_dir: &Path) -> Result<NotebookManifest, StorageErr
|
||||
manifest.id = name.to_string();
|
||||
}
|
||||
}
|
||||
Ok(manifest)
|
||||
let base = ManifestBase {
|
||||
key: seen_key(¬ebook_dir.join("manifest.json")),
|
||||
bytes,
|
||||
};
|
||||
Ok((manifest, base))
|
||||
}
|
||||
|
||||
fn load_manifest_or_backup(notebook_dir: &Path) -> Result<NotebookManifest, StorageError> {
|
||||
fn load_manifest_or_backup(
|
||||
notebook_dir: &Path,
|
||||
) -> Result<(NotebookManifest, Vec<u8>), StorageError> {
|
||||
let path = notebook_dir.join("manifest.json");
|
||||
if !path.exists() {
|
||||
let bak_path = notebook_dir.join("manifest.json.bak");
|
||||
@@ -871,7 +942,8 @@ pub fn save_notebook(
|
||||
/// Lädt ein Notizbuch aus einem Ordner (erste Seite sofort, Folgeseiten als Platzhalter für Lazy Loading).
|
||||
pub fn load_notebook(notebook_dir: &Path) -> Result<(Notebook, NotebookManifest), StorageError> {
|
||||
let _ = cleanup_orphaned_temp_files(notebook_dir, std::time::Duration::from_secs(3600));
|
||||
let manifest = load_manifest(notebook_dir)?;
|
||||
let (manifest, base) = load_manifest_as_base(notebook_dir)?;
|
||||
base.adopt();
|
||||
let page_ids = manifest.page_ids();
|
||||
if page_ids.is_empty() {
|
||||
let nb = Notebook::new();
|
||||
|
||||
@@ -2667,16 +2667,18 @@ fn page_separators(ctx: &egui::Context, state: &UiState, notebook: &Notebook) {
|
||||
fn scrollbar_layout(
|
||||
screen: egui::Rect,
|
||||
side: SidebarSide,
|
||||
reserved: f32,
|
||||
(top, bottom): (f32, f32),
|
||||
center: f32,
|
||||
visible: f32,
|
||||
) -> (egui::Rect, egui::Rect) {
|
||||
const WIDTH: f32 = 28.0;
|
||||
const MARGIN: f32 = 12.0;
|
||||
// Gegenüber der Werkzeugleiste
|
||||
// Next to the toolbar, on its inner side: the writing hand rests on the opposite
|
||||
// half of the screen and no longer touches the bar by accident (issue #58)
|
||||
let x = match side {
|
||||
SidebarSide::Left => screen.right() - WIDTH,
|
||||
SidebarSide::Right => screen.left(),
|
||||
SidebarSide::Left => (screen.left() + reserved).min(screen.right() - WIDTH),
|
||||
SidebarSide::Right => (screen.right() - reserved - WIDTH).max(screen.left()),
|
||||
};
|
||||
let track = egui::Rect::from_min_size(
|
||||
egui::pos2(x, screen.top() + MARGIN),
|
||||
@@ -2696,7 +2698,7 @@ fn scrollbar_layout(
|
||||
(track, thumb)
|
||||
}
|
||||
|
||||
/// Durchgehende Ansicht: Bildlaufleiste am Fensterrand gegenüber der Werkzeugleiste. Den
|
||||
/// Durchgehende Ansicht: Bildlaufleiste neben der Werkzeugleiste (zur Seite hin). Den
|
||||
/// Griff ziehen (oder auf die Leiste tippen) springt schnell durch lange Notizbücher und
|
||||
/// PDFs (Issue #28); beim Ziehen steht die Seitenzahl daneben.
|
||||
fn page_scrollbar(
|
||||
@@ -2718,8 +2720,14 @@ fn page_scrollbar(
|
||||
let screen = ctx.screen_rect();
|
||||
let center = view.to_page(screen.center()).y;
|
||||
let visible = screen.height() / view.scale.max(1e-6);
|
||||
let (track, thumb) =
|
||||
scrollbar_layout(screen, state.sidebar_side, (min.y, max.y), center, visible);
|
||||
let (track, thumb) = scrollbar_layout(
|
||||
screen,
|
||||
state.sidebar_side,
|
||||
state.sidebar_reserved_width(),
|
||||
(min.y, max.y),
|
||||
center,
|
||||
visible,
|
||||
);
|
||||
|
||||
let dark = state.paper_theme.is_dark();
|
||||
let response = egui::Area::new(egui::Id::new("page_scrollbar"))
|
||||
@@ -2771,12 +2779,12 @@ fn page_scrollbar(
|
||||
}
|
||||
if let Some(page) = stack.page_at(target) {
|
||||
let label_x = match state.sidebar_side {
|
||||
SidebarSide::Left => track.left() - 8.0,
|
||||
SidebarSide::Right => track.right() + 8.0,
|
||||
SidebarSide::Left => track.right() + 8.0,
|
||||
SidebarSide::Right => track.left() - 8.0,
|
||||
};
|
||||
let anchor = match state.sidebar_side {
|
||||
SidebarSide::Left => egui::Align2::RIGHT_CENTER,
|
||||
SidebarSide::Right => egui::Align2::LEFT_CENTER,
|
||||
SidebarSide::Left => egui::Align2::LEFT_CENTER,
|
||||
SidebarSide::Right => egui::Align2::RIGHT_CENTER,
|
||||
};
|
||||
let painter = ctx.layer_painter(egui::LayerId::new(
|
||||
egui::Order::Foreground,
|
||||
@@ -5939,18 +5947,38 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_page_scrollbar_jumps_through_the_notebook() {
|
||||
// Layout: Griff oben am Anfang, unten am Ende, gegenüber der Werkzeugleiste
|
||||
// Layout: thumb at the top at the start, at the bottom at the end, beside the
|
||||
// toolbar and never on the opposite edge where the writing hand rests (issue #58)
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 850.0));
|
||||
let (track, top) =
|
||||
scrollbar_layout(screen, SidebarSide::Left, (0.0, 80_000.0), 0.0, 1000.0);
|
||||
assert_eq!(track.right(), screen.right());
|
||||
let (track, top) = scrollbar_layout(
|
||||
screen,
|
||||
SidebarSide::Left,
|
||||
64.0,
|
||||
(0.0, 80_000.0),
|
||||
0.0,
|
||||
1000.0,
|
||||
);
|
||||
assert_eq!(track.left(), 64.0);
|
||||
assert_eq!(top.top(), track.top());
|
||||
assert!(top.height() >= 48.0);
|
||||
let (_, end) =
|
||||
scrollbar_layout(screen, SidebarSide::Left, (0.0, 80_000.0), 80_000.0, 1000.0);
|
||||
let (_, end) = scrollbar_layout(
|
||||
screen,
|
||||
SidebarSide::Left,
|
||||
64.0,
|
||||
(0.0, 80_000.0),
|
||||
80_000.0,
|
||||
1000.0,
|
||||
);
|
||||
assert_eq!(end.bottom(), track.bottom());
|
||||
let (left, _) = scrollbar_layout(screen, SidebarSide::Right, (0.0, 1.0), 0.0, 1.0);
|
||||
assert_eq!(left.left(), screen.left());
|
||||
let (right, _) = scrollbar_layout(screen, SidebarSide::Right, 64.0, (0.0, 1.0), 0.0, 1.0);
|
||||
assert_eq!(right.right(), screen.right() - 64.0);
|
||||
assert!(right.left() > screen.center().x);
|
||||
// Without a toolbar the bar sits on the toolbar's edge; it stays on screen even
|
||||
// when the toolbar is wider than the window
|
||||
let (edge, _) = scrollbar_layout(screen, SidebarSide::Right, 0.0, (0.0, 1.0), 0.0, 1.0);
|
||||
assert_eq!(edge.right(), screen.right());
|
||||
let (narrow, _) = scrollbar_layout(screen, SidebarSide::Left, 5000.0, (0.0, 1.0), 0.0, 1.0);
|
||||
assert_eq!(narrow.right(), screen.right());
|
||||
|
||||
// Notizbuch mit 80 Seiten, durchgehend, Ansicht auf Seite 1
|
||||
let mut notebook = Notebook::new();
|
||||
@@ -5965,7 +5993,8 @@ mod tests {
|
||||
});
|
||||
let ctx = render_frames(&mut state, ¬ebook, 2);
|
||||
let updater = crate::updater::UpdaterController::new();
|
||||
let x = screen.right() - 14.0;
|
||||
let x = state.sidebar_reserved_width() + 14.0;
|
||||
assert!(x > 14.0, "the toolbar has been laid out");
|
||||
let mut actions = Vec::new();
|
||||
// Griff greifen und bis ans untere Ende ziehen
|
||||
for (pos, pressed) in [
|
||||
|
||||
Reference in new issue
Block a user