commonMain.ClipElement.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of element Show documentation
Show all versions of element Show documentation
A collection of drawing/charting utilities
package com.juul.krayon.element
import com.juul.krayon.kanvas.Clip
import com.juul.krayon.kanvas.Kanvas
import com.juul.krayon.kanvas.withClip
/**
* An element that clips rendering of child elements.
*
* Note that this does not prevent clipped children from being hit-tested for interactions.
*/
public class ClipElement : Element() {
override val tag: String get() = "clip"
public var clip: Clip? by attributes.withDefault { null }
override fun draw(kanvas: Kanvas) {
when (val clip = this.clip) {
null -> children.forEach { it.draw(kanvas) }
else -> kanvas.withClip(clip) {
children.forEach { it.draw(kanvas) }
}
}
}
public companion object : ElementBuilder, ElementSelector {
override fun build(): ClipElement = ClipElement()
override fun trySelect(element: Element): ClipElement? = element as? ClipElement
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy