scoop:scoop.ui:0.1.0
src/view/scene_cache.scoop
Selected production source · src/view/scene_cache.scoop
1
package scoop.ui3
import scoop.graphics.Point5
private val sceneRevisionComparison = InputComparison<Long> { before, after -> before == after }7
/** Explicitly reuses stable scene operations; revision covers external, unobserved inputs. */8
public fun cachedScene(content: View, revision: Long = 0L, key: ViewKey = ViewKey.Position): View =9
element(revision, ::SceneCacheElement, [content], key, Some(sceneRevisionComparison))11
private class SceneCacheElement(private val props: Props<Long>, scope: ComponentScope): Element<12
Unit13
>(scope) {14
private var revision = props.value15
private var epoch = SceneEpoch()16
public override fun update(): UiInvalidation {17
if (revision == props.value)18
return UiInvalidation.None19
revision = props.value20
epoch = SceneEpoch()21
return UiInvalidation.Scene22
}23
public override fun measure(context: MeasureContext, constraints: Constraints): LayoutResult<24
Unit25
> {26
val child = context.measureChild(0L, constraints)27
context.placeChild(0L, Point(0.0, 0.0))28
return LayoutResult(child, Unit)29
}30
public override fun scene(context: SceneContext, layout: Unit) {31
context.presentChildren(None, Some(epoch))32
}33
}