commonMain.CircleElement.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.Kanvas
import com.juul.krayon.kanvas.Paint
import com.juul.krayon.kanvas.Path
public class CircleElement : InteractableElement() {
override val tag: String get() = "circle"
public var centerX: Float by attributes.withDefault { 0f }
public var centerY: Float by attributes.withDefault { 0f }
public var radius: Float by attributes.withDefault { 0f }
public var paint: Paint by attributes.withDefault { DEFAULT_FILL }
override fun draw(kanvas: Kanvas) {
kanvas.drawCircle(centerX, centerY, radius, paint)
}
override fun getInteractionPath(): Path = Path {
val left = centerX - radius
val top = centerY - radius
val right = centerX + radius
val bottom = centerY + radius
arcTo(left, top, right, bottom, 0f, 180f, forceMoveTo = false)
arcTo(left, top, right, bottom, 180f, 180f, forceMoveTo = false)
}
public companion object : ElementBuilder, ElementSelector {
override fun build(): CircleElement = CircleElement()
override fun trySelect(element: Element): CircleElement? = element as? CircleElement
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy