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

commonMain.TextElement.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.Kanvas
import com.juul.krayon.kanvas.Paint

public class TextElement : Element() {

    override val tag: String get() = "text"

    public var text: String by attributes.withDefault { "" }
    public var x: Float by attributes.withDefault { 0f }
    public var y: Float by attributes.withDefault { 0f }
    public var paint: Paint.Text by attributes.withDefault { DEFAULT_TEXT }

    /** Vertical alignment, as a ratio of [Paint.Text.size]. */
    public var verticalAlign: Float by attributes.withDefault { 0f }

    override fun draw(kanvas: Kanvas) {
        kanvas.drawText(text, x, y + (paint.size * verticalAlign), paint)
    }

    public companion object : ElementBuilder, ElementSelector {
        override fun build(): TextElement = TextElement()

        override fun trySelect(element: Element): TextElement? = element as? TextElement
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy