-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/org.jetbrains.dokka-1.x
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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<ClipElement>, ElementSelector<ClipElement> { | ||
override fun build(): ClipElement = ClipElement() | ||
override fun trySelect(element: Element): ClipElement? = element as? ClipElement | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters