commonMain.io.nacular.doodle.theme.basic.date.BasicMonthPanelBehavior.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of themes Show documentation
Show all versions of themes Show documentation
A pure Kotlin, UI framework for the Web and Desktop
The newest version!
package io.nacular.doodle.theme.basic.date
import io.nacular.doodle.controls.ItemVisualizer
import io.nacular.doodle.controls.date.MonthPanel
import io.nacular.doodle.controls.date.MonthPanelBehavior
import io.nacular.doodle.controls.itemVisualizer
import io.nacular.doodle.controls.text.Label
import io.nacular.doodle.drawing.Canvas
import io.nacular.doodle.drawing.Paint
import kotlinx.datetime.LocalDate
/**
* Created by Nicholas Eddy on 2/21/22.
*/
public class BasicMonthPanelBehavior(
private val background: Paint,
private val defaultVisualizer: ItemVisualizer = itemVisualizer { day, previous, panel ->
val text = "${day.dayOfMonth}"
when (previous) {
is Label -> previous.apply { fitText = emptySet(); this.text = text }
else -> Label(text).apply { fitText = emptySet() }
}.also {
it.enabled = day.month == panel.startDate.month
}
}
): MonthPanelBehavior {
override fun itemVisualizer(of: MonthPanel): ItemVisualizer = of.itemVisualizer ?: defaultVisualizer
override fun render(view: MonthPanel, canvas: Canvas) {
canvas.rect(view.bounds.atOrigin, fill = background)
}
}