Skip to content

Commit

Permalink
Do page centering
Browse files Browse the repository at this point in the history
  • Loading branch information
max-kammerer committed May 29, 2024
1 parent 8c61f11 commit 6ed04cf
Showing 1 changed file with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import android.graphics.RectF
import androidx.core.math.MathUtils
import kotlinx.coroutines.CompletableJob
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import universe.constellation.orion.viewer.BuildConfig
import universe.constellation.orion.viewer.Controller
import universe.constellation.orion.viewer.LastPageInfo
import universe.constellation.orion.viewer.PageInfo
import universe.constellation.orion.viewer.bitmap.BitmapManager
import universe.constellation.orion.viewer.errorInDebug
import universe.constellation.orion.viewer.errorInDebugOr
import universe.constellation.orion.viewer.layout.LayoutPosition
import universe.constellation.orion.viewer.layout.calcPageLayout
import universe.constellation.orion.viewer.log
Expand Down Expand Up @@ -416,8 +414,8 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {
layoutStrategy.reset(pos, info, next)
val oldPosition = page.layoutData.position
val x = -pos.x.offset
//val y = getCenteredYInSinglePageMode(-pos.y.offset, page.height)
val y = -pos.y.offset
val y = getCenteredYInSinglePageMode(-pos.y.offset.toFloat(), page.height)
//val y = -pos.y.offset

doScrollAndDoRendering(
oldPosition.x,
Expand All @@ -436,8 +434,8 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {
layoutStrategy.reset(pos, info, next)
val oldPosition = page.layoutData.position
val x = -pos.x.offset
//val y = getCenteredYInSinglePageMode(-pos.y.offset, page.height)
val y = -pos.y.offset
val y = getCenteredYInSinglePageMode(-pos.y.offset.toFloat(), page.height)
//val y = -pos.y.offset
doScrollAndDoRendering(
oldPosition.x,
oldPosition.y,
Expand All @@ -454,13 +452,13 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {
return null
}

private fun getCenteredYInSinglePageMode(y: Int, pageHeight: Int): Float {
private fun getCenteredYInSinglePageMode(y: Float, pageHeight: Int): Float {
if (isSinglePageMode) {
if (pageHeight < sceneHeight) {
if (pageHeight <= sceneHeight) {
return (sceneHeight - pageHeight) / 2.0f
}
}
return y.toFloat()
return y
}

fun renderPageAt(
Expand All @@ -469,12 +467,13 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {
y: Int,
isTapNavigation: Boolean = false,
doScroll: (PageView, PageInfo) -> Unit = { page, _ ->
val newPosition = page.layoutData.position
val oldPosition = page.layoutData.position
val newY = getCenteredYInSinglePageMode(y.toFloat(), page.height)
doScrollAndDoRendering(
newPosition.x,
newPosition.y,
x - newPosition.x,
y - newPosition.y,
oldPosition.x,
oldPosition.y,
x - oldPosition.x,
newY - oldPosition.y,
isTapNavigation
)
}
Expand Down Expand Up @@ -519,7 +518,7 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {

onPageSizeCalculatedCallback?.job?.cancel()
if (page.state == PageState.SIZE_AND_BITMAP_CREATED) {
println("onPageSizeCalculatedCallback: inplace")
log("onPageSizeCalculatedCallback: inplace")
onPageSizeCalculatedCallback = null
val completed = page.pageInfo!!
doScroll(page, completed) //TODO process errors
Expand All @@ -528,17 +527,16 @@ class PageLayoutManager(val controller: Controller, val scene: OrionDrawScene) {
dump()
errorInDebug("Unexpected state ${page.pageNum} + ${page.pageInfoJob.isCompleted}")
}
println("onPageSizeCalculatedCallback: lazy")
onPageSizeCalculatedCallback = Callback(pageNum, Job(controller.rootJob)) {
println("onPageSizeCalculatedCallback: call")
log("onPageSizeCalculatedCallback: call")
doScroll(page, it)
}
}
return page
}

private fun destroyPages() {
log("Descroying pages")
log("Destroying pages")
val iterator = activePages.iterator()
for (page in iterator) {
//TODO optimize
Expand Down

0 comments on commit 6ed04cf

Please sign in to comment.