hopefully true virtual list layout

This commit is contained in:
Agel committed 2026-10-28 23:44:54 +01:00
1 parent 905c61da52
commit 6c821c6a3c
10 files changed
+522 -37

No files matched your search

+5 -1
View File
@@ -159,6 +159,7 @@ public:
### 1. Text Mode (`ScrollPageView.qml`)
- `ReadingModel` manages a list of HTML chunks.
- `EpubReader` unwraps unstyled structural containers (`<div>`, `<section>`, `<article>`, etc.) that contain block-level children and partitions documents into fine-grained block/paragraph chunks (~512 chars max), propagating inherited CSS declarations. Paragraph `<div>`s containing inline markup (`<em>`, `<span>`, `<a>`, etc.) are preserved intact as atomic blocks without fragmenting text or punctuation.
- When viewport geometry or font preferences change, `ReadingModel::updateLayoutMetrics()` runs `ChunkLayoutEngine` off-thread:
- `HtmlBlockParser` extracts structured blocks (`Paragraph`, `ImageBlock`, `Rule`, `Container`).
- Block-level `background` sets `BoxStyle::background` (emitted as `PositionedDecoration`), while inline spans apply to `TextStyle::background` (individual word runs).
@@ -167,7 +168,10 @@ public:
- `KnuthPlass` computes optimal justified/aligned line breaks.
- `BookImageResolver` resolves embedded image dimensions and URLs.
- Off-thread calculation stores `ChunkLayout` and pixel heights.
- Rendered in a virtualized `ListView` (`cacheBuffer: 600`, high flick velocity) using `KnuthPlassItem`.
- **Two-Phase Visible-First Layout**: On book open and font changes, `ReadingModel::startLayoutMeasurement()` computes layout for the visible window around the anchor chunk synchronously (<1ms) and emits `restoreReady(chunkIndex, intraOffset)` immediately so the visible screen renders on the first frame, while the background thread computes remaining off-screen chunks and updates only non-visible model ranges. On-demand layout guards ensure any chunk scrolled to before background completion is measured instantly.
- Rendered in a strictly virtualized `ListView` (`cacheBuffer: 0`, `reuseItems: true`, high flick velocity) using `KnuthPlassItem` as the direct delegate, preserving smooth scrolling without allocating off-screen delegate textures.
- **Debug Chunk Index**: In debug builds (`isDebugBuild`), displays the chunk index at the top-left of each list item (`x: 4, y: 2`), ignoring `horizontalMargin`.
- **Clip-Rect Culling in `KnuthPlassItem`**: `paint()` inspects `painter->clipBoundingRect()`, skips decorations/rules outside the clip, uses $O(\log N)$ binary search (`std::lower_bound`) to draw only lines intersecting the clip, and skips off-screen image decoding/resolution completely.
- **Publisher Colours vs Theme**: Controlled by per-book `useBookColours` setting (default `false`).
- When off: paints with theme palette (`readingText`, `dimText`, `buttonAccent`), omitting publisher backgrounds and border boxes (semantic blockquote bars with only `borderLeft` and no explicit border colour are drawn in `dimText`).
- When on: paints publisher backgrounds and border colours, using WCAG contrast calculation (`contrastRatio < 3.0`) to automatically select high-contrast black or white text when publisher or theme text colours would be unreadable on the effective background.