mirror of
https://github.com/JakeWharton/mosaic.git
synced 2025-11-02 04:36:19 +08:00
Remove some indirection within Static
This commit is contained in:
@ -27,56 +27,34 @@ public fun <T> Static(
|
||||
}
|
||||
}
|
||||
|
||||
Static(
|
||||
postRender = {
|
||||
// Remove any items which have been rendered.
|
||||
pending.removeAll { it.rendered }
|
||||
}
|
||||
) {
|
||||
for (item in pending) {
|
||||
Row {
|
||||
// Render item and mark it as having been included in render.
|
||||
content(item.value)
|
||||
item.rendered = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders [content] permanently above the normal canvas. When content has
|
||||
* actually been written to a [TextCanvas], the [postRender] callback will be
|
||||
* invoked to allow clearing of content.
|
||||
*
|
||||
* @param postRender Callback after rendering to a [TextCanvas] is complete.
|
||||
* @param content Content which should be rendered permanently above normal
|
||||
* canvas.
|
||||
*/
|
||||
@Composable
|
||||
internal fun Static(
|
||||
postRender: () -> Unit = {},
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
ComposeNode<StaticNode, MosaicNodeApplier>(
|
||||
factory = ::StaticNode,
|
||||
update = {
|
||||
set(postRender) {
|
||||
this.postRender = postRender
|
||||
factory = {
|
||||
StaticNode {
|
||||
pending.removeAll { it.rendered }
|
||||
}
|
||||
},
|
||||
update = {},
|
||||
content = {
|
||||
for (item in pending) {
|
||||
Row {
|
||||
// Render item and mark it as having been included in render.
|
||||
content(item.value)
|
||||
item.rendered = true
|
||||
}
|
||||
}
|
||||
},
|
||||
content = content,
|
||||
)
|
||||
}
|
||||
|
||||
internal class StaticNode : ContainerNode() {
|
||||
internal class StaticNode(
|
||||
private val postRender: () -> Unit,
|
||||
) : ContainerNode() {
|
||||
// Delegate container column for static content.
|
||||
private val box = LinearNode(isRow = false)
|
||||
|
||||
override val children: MutableList<MosaicNode>
|
||||
get() = box.children
|
||||
|
||||
var postRender: () -> Unit = {}
|
||||
|
||||
override fun measure() {
|
||||
// Not visible.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user