All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.ClipElement.kt Maven / Gradle / Ivy

There is a newer version: 0.19.1
Show newest version
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