diff --git a/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/Static.kt b/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/Static.kt index c6eef567..812b54b1 100644 --- a/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/Static.kt +++ b/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/Static.kt @@ -16,30 +16,30 @@ public fun Static( items: Flow, content: @Composable (T) -> Unit, ) { - class Item(val value: T, var rendered: Boolean) + class Item(val value: T, var drawn: Boolean) - // Keep list of items which have not yet been rendered. + // Keep list of items which have not yet been drawn. val pending = remember { mutableStateListOf() } LaunchedEffect(items) { items.collect { - pending.add(Item(it, rendered = false)) + pending.add(Item(it, drawn = false)) } } ComposeNode( factory = { StaticNode { - pending.removeAll { it.rendered } + pending.removeAll { it.drawn } } }, update = {}, content = { for (item in pending) { Row { - // Render item and mark it as having been included in render. + // Draw item and mark it as such. content(item.value) - item.rendered = true + item.drawn = true } } }, @@ -47,7 +47,7 @@ public fun Static( } internal class StaticNode( - private val postRender: () -> Unit, + private val onPostDraw: () -> Unit, ) : ContainerNode() { // Delegate container column for static content. private val box = LinearNode(isRow = false) @@ -63,25 +63,25 @@ internal class StaticNode( // Not visible. } - override fun renderTo(canvas: TextCanvas) { + override fun drawTo(canvas: TextCanvas) { // No content. } - override fun renderStatics(): List { + override fun drawStatics(): List { val statics = mutableListOf() - // Render contents of static node to a separate display. - val static = box.render() + // Draw contents of static node to a separate node hierarchy. + val static = box.draw() // Add display canvas to static canvases if it is not empty. if (static.width > 0 && static.height > 0) { statics.add(static) } - // Propagate any static content of the display. - statics.addAll(box.renderStatics()) + // Propagate any static content of this static node. + statics.addAll(box.drawStatics()) - postRender() + onPostDraw() return statics } diff --git a/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/mosaic.kt b/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/mosaic.kt index b807a11e..bddc9e1e 100644 --- a/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/mosaic.kt +++ b/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/mosaic.kt @@ -51,8 +51,8 @@ public suspend fun runMosaic(body: suspend MosaicScope.() -> Unit): Unit = corou hasFrameWaiters = false clock.sendFrame(0L) // Frame time value is not used by Compose runtime. - val canvas = rootNode.render() - val statics = rootNode.renderStatics() + val canvas = rootNode.draw() + val statics = rootNode.drawStatics() output.display(canvas, statics) displaySignal?.complete(Unit) diff --git a/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/nodes.kt b/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/nodes.kt index 92fc38cf..e1c0aff1 100644 --- a/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/nodes.kt +++ b/mosaic-runtime/src/commonMain/kotlin/com/jakewharton/mosaic/nodes.kt @@ -9,26 +9,26 @@ internal sealed class MosaicNode { var height = 0 // These two values are set by a call to `layout` on the parent node. - /** Pixels right relative to parent at which this node will render. */ + /** Pixels right relative to parent at which this node will draw. */ var x = 0 - /** Pixels down relative to parent at which this node will render. */ + /** Pixels down relative to parent at which this node will draw. */ var y = 0 /** Measure this node (and any children) and update [width] and [height]. */ abstract fun measure() /** Layout any children nodes and update their [x] and [y] relative to this node. */ abstract fun layout() - abstract fun renderTo(canvas: TextCanvas) + abstract fun drawTo(canvas: TextCanvas) - fun render(): TextCanvas { + fun draw(): TextCanvas { measure() layout() val canvas = TextSurface(width, height) - renderTo(canvas) + drawTo(canvas) return canvas } - abstract fun renderStatics(): List + abstract fun drawStatics(): List } internal class TextNode(initialValue: String = "") : MosaicNode() { @@ -56,13 +56,13 @@ internal class TextNode(initialValue: String = "") : MosaicNode() { // No children. } - override fun renderTo(canvas: TextCanvas) { + override fun drawTo(canvas: TextCanvas) { value.split('\n').forEachIndexed { index, line -> canvas.write(index, 0, line, foreground, background, style) } } - override fun renderStatics() = emptyList() + override fun drawStatics() = emptyList() override fun toString() = "Text(\"$value\", x=$x, y=$y, width=$width, height=$height)" } @@ -134,22 +134,22 @@ internal class LinearNode(var isRow: Boolean = true) : ContainerNode() { } } - override fun renderTo(canvas: TextCanvas) { + override fun drawTo(canvas: TextCanvas) { for (child in children) { if (child.width != 0 && child.height != 0) { val left = child.x val top = child.y val right = left + child.width - 1 val bottom = top + child.height - 1 - child.renderTo(canvas[top..bottom, left..right]) + child.drawTo(canvas[top..bottom, left..right]) } else { - child.renderTo(canvas.empty()) + child.drawTo(canvas.empty()) } } } - override fun renderStatics(): List { - return children.flatMap(MosaicNode::renderStatics) + override fun drawStatics(): List { + return children.flatMap(MosaicNode::drawStatics) } override fun toString() = children.joinToString(prefix = "Box(", postfix = ")")