Refactor using Fable

This commit is contained in:
Agel committed 2026-07-31 17:31:02 +02:00
1 parent 1a60a6b93c
commit 83968646c6
90 files changed
+2080 -2267

No files matched your search

+20 -27
View File
@@ -29,28 +29,26 @@ Rectangle {
function handleScrollUp() { previousPair() }
function nextPair() {
if (currentPair < readingModel.totalPagePairs - 1) {
currentPair++
onPairChanged()
}
if (currentPair < readingModel.totalPagePairs - 1)
showPair(currentPair + 1)
}
function previousPair() {
if (currentPair > 0) {
currentPair--
onPairChanged()
}
if (currentPair > 0)
showPair(currentPair - 1)
}
function onPairChanged() {
const pair = readingModel.pagePair(currentPair)
// Single entry point for displaying a pair: sets the index, refreshes the
// displayed pair contents, and syncs scroll/position state.
function showPair(pairIndex) {
currentPair = pairIndex
pageArea.pair = contentReady ? readingModel.pagePair(pairIndex) : []
const pair = pageArea.pair
if (pair.length === 0) return
const firstChunk = pair[0]
// Keep scroll model in sync so Footer page counter and chapter tracking work.
readingModel.setScrollInfo(firstChunk, currentPair / Math.max(1, readingModel.totalPagePairs - 1))
readingModel.setScrollInfo(firstChunk, pairIndex / Math.max(1, readingModel.totalPagePairs - 1))
book.saveCurrentPosition(firstChunk, 0, readingModel.pageShift)
// Sync currentPage for footer display.
// totalPages is already set to totalPagePairs by the model in manga mode.
}
// Notify model when orientation changes (triggers pair rebuild).
@@ -72,8 +70,9 @@ Rectangle {
anchors.fill: parent
anchors.margins: readingPreferences.verticalMargin
// Build display pair: for RTL mode pages are reversed (higher index on the left).
property var pair: contentReady ? readingModel.pagePair(currentPair) : []
// Display pair, updated by showPair(). For RTL mode pages are reversed
// (higher index on the left) via leftChunk/rightChunk below.
property var pair: []
property int leftChunk: {
if (pair.length === 0) return -1
@@ -189,7 +188,7 @@ Rectangle {
} else {
// Middle — toggle bars.
window.barsVisible = !window.barsVisible
window.sidebarOpen = !window.sidebarOpen
uiState.sidebarOpen = !uiState.sidebarOpen
}
}
}
@@ -199,23 +198,17 @@ Rectangle {
target: readingModel
function onRestoreReady(chunkIndex, intraOffset) {
contentReady = true
const pair = readingModel.pairIndexForChunk(chunkIndex)
currentPair = pair
restoreReady = true
onPairChanged()
showPair(readingModel.pairIndexForChunk(chunkIndex))
}
function onTotalPagePairsChanged() {
// Re-clamp after pair rebuild (resize / orientation flip).
currentPair = Math.min(currentPair, Math.max(0, readingModel.totalPagePairs - 1))
showPair(Math.min(currentPair, Math.max(0, readingModel.totalPagePairs - 1)))
}
function onPagePairsRebuilt(newPairIndex) {
// setPageShift rebuilt the pairs — the pair-content binding needs to re-evaluate
// even when newPairIndex equals the existing currentPair (toggling shift can leave
// the index unchanged while pair contents change). Two writes force two change
// notifications; the binding is read once after the function returns with the
// final value, so the -1 intermediate is never displayed.
currentPair = -1
currentPair = newPairIndex
// setPageShift rebuilt the pairs; refresh even when the index is
// unchanged since the pair contents may differ.
showPair(newPairIndex)
}
}