Skip to content

Instantly share code, notes, and snippets.

@AndyG
Created February 28, 2018 23:50
Show Gist options
  • Save AndyG/12455f2d30a28897b87c33a9d0e08e12 to your computer and use it in GitHub Desktop.
Save AndyG/12455f2d30a28897b87c33a9d0e08e12 to your computer and use it in GitHub Desktop.
SimpleAST StyleNode
class StyleNode(val styles: List<CharacterStyle>) : SpannableRenderableNode() {
override fun render(builder: SpannableStringBuilder, context: Context?) {
// No matter what happens in this world, never forget where you came from.
val startIndex = builder.length
// First render all child nodes, as these are the nodes we want to apply the styles to.
getChildren()?.forEach { (it as SpannableRenderableNode).render(builder, context) }
styles.forEach { builder.setSpan(it, startIndex, builder.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment