Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
commonMain.io.nacular.doodle.theme.basic.BasicTheme.kt Maven / Gradle / Ivy
@file:Suppress("unused")
package io.nacular.doodle.theme.basic
import io.nacular.doodle.controls.DynamicListModel
import io.nacular.doodle.controls.ItemVisualizer
import io.nacular.doodle.controls.MutableListModel
import io.nacular.doodle.controls.ProgressBar
import io.nacular.doodle.controls.ProgressIndicator
import io.nacular.doodle.controls.buttons.Button
import io.nacular.doodle.controls.buttons.CheckBox
import io.nacular.doodle.controls.buttons.RadioButton
import io.nacular.doodle.controls.buttons.Switch
import io.nacular.doodle.controls.date.DaysOfTheWeekPanel
import io.nacular.doodle.controls.date.MonthPanel
import io.nacular.doodle.controls.dropdown.MutableSelectBox
import io.nacular.doodle.controls.dropdown.SelectBox
import io.nacular.doodle.controls.list.HorizontalDynamicList
import io.nacular.doodle.controls.list.HorizontalList
import io.nacular.doodle.controls.list.HorizontalMutableList
import io.nacular.doodle.controls.list.List
import io.nacular.doodle.controls.list.MutableList
import io.nacular.doodle.controls.list.VerticalDynamicList
import io.nacular.doodle.controls.list.VerticalList
import io.nacular.doodle.controls.list.VerticalMutableList
import io.nacular.doodle.controls.panels.GridPanel
import io.nacular.doodle.controls.panels.SplitPanel
import io.nacular.doodle.controls.panels.TabbedPanel
import io.nacular.doodle.controls.popupmenu.Menu
import io.nacular.doodle.controls.range.CircularRangeSlider
import io.nacular.doodle.controls.range.CircularSlider
import io.nacular.doodle.controls.range.RangeSlider
import io.nacular.doodle.controls.range.Slider
import io.nacular.doodle.controls.spinner.MutableSpinButton
import io.nacular.doodle.controls.spinner.MutableSpinButtonModel
import io.nacular.doodle.controls.spinner.SpinButton
import io.nacular.doodle.controls.spinner.SpinButtonModel
import io.nacular.doodle.controls.table.MutableTable
import io.nacular.doodle.controls.table.Table
import io.nacular.doodle.controls.table.TreeTable
import io.nacular.doodle.controls.text.Label
import io.nacular.doodle.controls.theme.CommonLabelBehavior
import io.nacular.doodle.controls.tree.MutableTree
import io.nacular.doodle.controls.tree.Tree
import io.nacular.doodle.controls.tree.TreeModel
import io.nacular.doodle.controls.treecolumns.TreeColumns
import io.nacular.doodle.core.Behavior
import io.nacular.doodle.drawing.Canvas
import io.nacular.doodle.drawing.Color
import io.nacular.doodle.drawing.Color.Companion.Black
import io.nacular.doodle.drawing.Color.Companion.Blue
import io.nacular.doodle.drawing.Color.Companion.White
import io.nacular.doodle.drawing.ColorPaint
import io.nacular.doodle.drawing.GradientPaint
import io.nacular.doodle.drawing.ImagePaint
import io.nacular.doodle.drawing.LinearGradientPaint
import io.nacular.doodle.drawing.Paint
import io.nacular.doodle.drawing.PatternPaint
import io.nacular.doodle.drawing.RadialGradientPaint
import io.nacular.doodle.drawing.Stroke
import io.nacular.doodle.drawing.darker
import io.nacular.doodle.drawing.grayScale
import io.nacular.doodle.drawing.lighter
import io.nacular.doodle.drawing.paint
import io.nacular.doodle.geometry.Path
import io.nacular.doodle.geometry.SegmentBuilder
import io.nacular.doodle.geometry.Size
import io.nacular.doodle.theme.Modules
import io.nacular.doodle.theme.Modules.Companion.ThemeModule
import io.nacular.doodle.theme.Modules.Companion.bindBehavior
import io.nacular.doodle.theme.PaintMapper
import io.nacular.doodle.theme.PathProgressIndicatorBehavior
import io.nacular.doodle.theme.PathProgressIndicatorBehavior.Direction
import io.nacular.doodle.theme.Scene
import io.nacular.doodle.theme.adhoc.DynamicTheme
import io.nacular.doodle.theme.basic.BasicMenuBehavior.Config
import io.nacular.doodle.theme.basic.date.BasicDaysOfTheWeekPanelBehavior
import io.nacular.doodle.theme.basic.date.BasicMonthPanelBehavior
import io.nacular.doodle.theme.basic.dropdown.BasicMutableSelectBoxBehavior
import io.nacular.doodle.theme.basic.dropdown.BasicSelectBoxBehavior
import io.nacular.doodle.theme.basic.list.basicHorizontalListBehavior
import io.nacular.doodle.theme.basic.list.basicHorizontalMutableListBehavior
import io.nacular.doodle.theme.basic.list.basicVerticalListBehavior
import io.nacular.doodle.theme.basic.list.basicVerticalMutableListBehavior
import io.nacular.doodle.theme.basic.range.BasicCircularRangeSliderBehavior
import io.nacular.doodle.theme.basic.range.BasicCircularSliderBehavior
import io.nacular.doodle.theme.basic.range.BasicRangeSliderBehavior
import io.nacular.doodle.theme.basic.range.BasicSliderBehavior
import io.nacular.doodle.theme.basic.range.TickPresentation
import io.nacular.doodle.theme.basic.spinner.BasicMutableSpinButtonBehavior
import io.nacular.doodle.theme.basic.spinner.BasicSpinButtonBehavior
import io.nacular.doodle.theme.basic.tabbedpanel.BasicTabProducer
import io.nacular.doodle.theme.basic.tabbedpanel.BasicTabbedPanelBehavior
import io.nacular.doodle.theme.basic.tabbedpanel.SimpleTabContainer
import io.nacular.doodle.theme.basic.tabbedpanel.TabContainer
import io.nacular.doodle.theme.basic.tabbedpanel.TabProducer
import io.nacular.doodle.theme.basic.table.BasicMutableTableBehavior
import io.nacular.doodle.theme.basic.table.BasicTableBehavior
import io.nacular.doodle.theme.basic.table.BasicTreeTableBehavior
import io.nacular.doodle.theme.basic.tree.BasicMutableTreeBehavior
import io.nacular.doodle.theme.basic.tree.BasicTreeBehavior
import io.nacular.doodle.theme.basic.treecolumns.BasicTreeColumnsBehavior
import io.nacular.doodle.theme.basic.treecolumns.SimpleTreeColumnRowIcon
import io.nacular.doodle.theme.basic.treecolumns.TreeColumnRowIcon
import io.nacular.doodle.utils.RotationDirection
import io.nacular.doodle.utils.RotationDirection.Clockwise
import io.nacular.measured.units.Angle
import io.nacular.measured.units.Angle.Companion.degrees
import io.nacular.measured.units.Measure
import io.nacular.measured.units.times
import kotlinx.datetime.DayOfWeek
import org.kodein.di.DI
import org.kodein.di.DI.Module
import org.kodein.di.DirectDI
import org.kodein.di.bind
import org.kodein.di.bindings.NoArgBindingDI
import org.kodein.di.erasedSet
import org.kodein.di.instance
import org.kodein.di.instanceOrNull
import org.kodein.di.provider
import org.kodein.di.singleton
private typealias BTheme = BasicTheme
private typealias ListModel = io.nacular.doodle.controls.ListModel
private typealias MutableTreeModel = io.nacular.doodle.controls.tree.MutableTreeModel
private typealias TabContainerFactory = DirectDI.(TabbedPanel, TabProducer) -> TabContainer
@Suppress("UNCHECKED_CAST")
public open class BasicTheme(private val configProvider: ConfigProvider, behaviors: Iterable): DynamicTheme(behaviors.filter { it.theme == BTheme::class }) {
override fun install(scene: Scene) {
configProvider.config = config
super.install(scene)
}
public open val config: BasicThemeConfig = object: BasicThemeConfig {}
override fun toString(): String = this::class.simpleName ?: ""
public interface BasicThemeConfig {
public val borderColor : Color get() = Color(0x888888u)
public val oddItemColor : Color get() = foregroundColor.inverted
public val evenItemColor : Color get() = lightBackgroundColor
public val selectionColor : Color get() = Color(0x0063e1u)
public val foregroundColor : Color get() = Black
public val backgroundColor : Color get() = Color(0xccccccu)
public val darkBackgroundColor : Color get() = Color(0xaaaaaau)
public val lightBackgroundColor : Color get() = Color(0xf3f4f5u)
public val defaultBackgroundColor: Color get() = backgroundColor
public val cornerRadius : Double get() = 6.0
public val checkBoxCornerRadius : Double get() = 4.0
public val hoverColorMapper : ColorMapper get() = { it.darker(0.1f) }
public val disabledColorMapper : ColorMapper get() = { it.lighter() }
public val disabledPaintMapper : PaintMapper get() = defaultDisabledPaintMapper
}
public interface ConfigProvider {
public var config: BasicThemeConfig
}
private class ConfigProviderImpl: ConfigProvider {
override var config = object: BasicThemeConfig {}
}
@Suppress("MemberVisibilityCanBePrivate")
public companion object {
private val Config = Module(name = "BasicThemeConfig") {
bind () with singleton { ConfigProviderImpl() }
bind() with provider { instance().config }
}
public fun basicThemeModule(name: String, init: DI.Builder.() -> Unit): Module = Module(name = name) {
importOnce(Config, allowOverride = true)
init()
}
public val BasicTheme: Module = basicThemeModule(name = "BasicTheme") {
importOnce(ThemeModule, allowOverride = true)
bind() with singleton { BasicTheme(instance(), Instance(erasedSet())) }
}
public fun basicListBehavior(
itemHeight : Double? = null,
evenItemColor : Color? = null,
oddItemColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null
): Module = basicThemeModule(name = "BasicListBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
basicVerticalListBehavior(
focusManager = instanceOrNull(),
evenItemColor = evenItemColor ?: this.evenItemColor,
oddItemColor = oddItemColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
itemHeight = itemHeight ?: 20.0,
numColumns = when (it) {
is VerticalList -> it.numColumns
is VerticalDynamicList -> it.numColumns
is VerticalMutableList -> it.numColumns
else -> 1
}
)
}
}
}
public fun basicHorizontalListBehavior(
itemWidth : Double? = null,
evenItemColor : Color? = null,
oddItemColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null
): Module = basicThemeModule(name = "BasicHorizontalListBehavior") {
val a: NoArgBindingDI<*>.(List) -> Unit = {
it.behavior = instance().run {
basicHorizontalListBehavior(
focusManager = instanceOrNull(),
evenItemColor = evenItemColor ?: this.evenItemColor,
oddItemColor = oddItemColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
itemWidth = itemWidth ?: 20.0,
numRows = when (it) {
is HorizontalList -> it.numRows
is HorizontalDynamicList -> it.numRows
is HorizontalMutableList -> it.numRows
else -> 1
}
)
}
}
bindBehavior>>(BTheme::class, a)
bindBehavior>>(BTheme::class, a)
bindBehavior>>(BTheme::class, a)
}
public fun basicMutableListBehavior(
itemHeight : Double? = null,
evenItemColor : Color? = null,
oddItemColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null
): Module = basicThemeModule(name = "BasicMutableListBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
basicVerticalMutableListBehavior(
focusManager = instanceOrNull(),
evenItemColor = evenItemColor ?: this.evenItemColor,
oddItemColor = oddItemColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
itemHeight = itemHeight ?: 20.0,
numColumns = if (it is VerticalMutableList) it.numColumns else 1
) }
}
}
public fun basicHorizontalMutableListBehavior(
itemWidth : Double? = null,
evenItemColor : Color? = null,
oddItemColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null
): Module = basicThemeModule(name = "BasicHorizontalMutableListBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
basicHorizontalMutableListBehavior(
focusManager = instanceOrNull(),
evenItemColor = evenItemColor ?: this.evenItemColor,
oddItemColor = oddItemColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
itemWidth = itemWidth ?: 20.0,
numRows = it.numRows
)
}
}
}
public fun basicTreeBehavior(
rowHeight : Double? = null,
evenRowColor : Color? = null,
oddRowColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null,
iconFactory : (() -> TreeRowIcon)? = null): Module = basicThemeModule(name = "BasicTreeBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
BasicTreeBehavior(
focusManager = instanceOrNull(),
rowHeight = rowHeight ?: 20.0,
evenRowColor = evenRowColor ?: this.evenItemColor,
oddRowColor = oddRowColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
iconFactory = iconFactory ?: { SimpleTreeRowIcon(foregroundColor, foregroundColor.inverted) }
)
}
}
}
public fun basicMutableTreeBehavior(
rowHeight : Double? = null,
evenRowColor : Color? = null,
oddRowColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null,
iconFactory : (() -> TreeRowIcon)? = null): Module = basicThemeModule(name = "BasicMutableTreeBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
BasicMutableTreeBehavior(
focusManager = instanceOrNull(),
rowHeight = rowHeight ?: 20.0,
evenRowColor = evenRowColor ?: this.evenItemColor,
oddRowColor = oddRowColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
iconFactory = iconFactory ?: { SimpleTreeRowIcon(foregroundColor, foregroundColor.inverted) }
) }
}
}
public fun basicTreeTableBehavior(
rowHeight : Double? = null,
evenRowColor : Color? = null,
oddRowColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null,
iconFactory : (() -> TreeRowIcon)? = null
): Module = basicThemeModule(name = "BasicTreeTableBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
BasicTreeTableBehavior(
focusManager = instanceOrNull(),
rowHeight = rowHeight ?: 20.0,
evenRowColor = evenRowColor ?: this.evenItemColor,
oddRowColor = oddRowColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
iconFactory = iconFactory ?: { SimpleTreeRowIcon(foregroundColor, foregroundColor.inverted) }
) }
}
}
public fun basicLabelBehavior(foregroundColor: Color? = null): Module = basicThemeModule(name = "BasicLabelBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
CommonLabelBehavior(instance(), foregroundColor ?: this.foregroundColor).apply {
disabledColorMapper = [email protected]
}
}
}
}
public fun basicTableBehavior(
rowHeight : Double? = null,
headerColor : Color? = null,
footerColor : Color? = null,
evenRowColor : Color? = null,
oddRowColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null): Module = basicThemeModule(name = "BasicTableBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run { BasicTableBehavior(
focusManager = instanceOrNull(),
rowHeight = rowHeight ?: 20.0,
headerColor = headerColor ?: this.backgroundColor,
footerColor = footerColor ?: this.backgroundColor,
evenRowColor = evenRowColor ?: this.evenItemColor,
oddRowColor = oddRowColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter()
) }
}
}
public fun basicMutableTableBehavior(
rowHeight : Double? = null,
headerColor : Color? = null,
footerColor : Color? = null,
evenRowColor : Color? = null,
oddRowColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null): Module = basicThemeModule(name = "BasicMutableTableBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run { BasicMutableTableBehavior(
focusManager = instanceOrNull(),
rowHeight = rowHeight ?: 20.0,
headerColor = headerColor ?: this.backgroundColor,
footerColor = footerColor ?: this.backgroundColor,
evenRowColor = evenRowColor ?: this.evenItemColor,
oddRowColor = oddRowColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter()
) }
}
}
public fun basicTreeColumnsBehavior(
rowHeight : Double? = null,
columnSeparatorColor : Color? = null,
selectionColor : Color? = null,
selectionBlurredColor: Color? = null,
backgroundColor : Color? = null,
iconFactory : (() -> TreeColumnRowIcon)? = null): Module = basicThemeModule(name = "BasicTreeColumnsBehavior") {
bindBehavior>(BTheme::class) {
it.behavior = instance().run { BasicTreeColumnsBehavior (
focusManager = instanceOrNull(),
rowHeight = rowHeight ?: 20.0,
columnSeparatorColor = columnSeparatorColor ?: this.backgroundColor,
backgroundColor = backgroundColor ?: this.oddItemColor,
selectionColor = selectionColor ?: this.selectionColor,
selectionBlurredColor = selectionBlurredColor ?: this.selectionColor.grayScale().lighter(),
iconFactory = iconFactory ?: { SimpleTreeColumnRowIcon(foregroundColor, foregroundColor.inverted) }
) }
}
}
public fun basicButtonBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
borderColor : Color? = null,
borderWidth : Double? = null,
cornerRadius : Double? = null,
insets : Double? = null): Module = basicThemeModule(name = "BasicButtonBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicButtonBehavior(
instance(),
backgroundColor = backgroundColor ?: this.backgroundColor,
darkBackgroundColor = darkBackgroundColor ?: this.darkBackgroundColor,
foregroundColor = foregroundColor ?: this.foregroundColor,
borderColor = borderColor ?: this.borderColor,
borderWidth = borderWidth ?: 0.0,
cornerRadius = cornerRadius ?: this.cornerRadius,
insets = insets ?: 8.0,
focusManager = instanceOrNull()
).apply {
hoverColorMapper = [email protected]
disabledColorMapper = [email protected]
}
}
}
}
public fun basicSliderBehavior(
barFill : Paint? = null,
knobFill : Paint? = null,
rangeFill : Paint? = null,
grooveThicknessRatio: Float? = null,
showTicks : TickPresentation? = null): Module = basicThemeModule(name = "BasicSliderBehavior") {
bindBehavior>(BTheme::class) {
it.behavior = instance().run {
BasicSliderBehavior(
barFill = barFill ?: defaultBackgroundColor.paint,
knobFill = knobFill ?: darkBackgroundColor.paint,
rangeFill = rangeFill,
grooveThicknessRatio = grooveThicknessRatio ?: 0.5f,
showTicks = showTicks,
focusManager = instanceOrNull()
).apply {
disabledPaintMapper = [email protected]
}
}
}
}
public fun basicRangeSliderBehavior(
barFill : Paint? = null,
startKnobFill : Paint? = null,
endKnobFill : Paint? = startKnobFill,
rangeFill : Paint? = endKnobFill,
grooveThicknessRatio: Float? = null,
showTicks : TickPresentation? = null
): Module = basicThemeModule(name = "BasicRangeSliderBehavior") {
bindBehavior>(BTheme::class) {
it.behavior = instance().run {
BasicRangeSliderBehavior(
barFill = barFill ?: defaultBackgroundColor.paint,
startKnobFill = startKnobFill ?: darkBackgroundColor.paint,
endKnobFill = endKnobFill ?: startKnobFill ?: darkBackgroundColor.paint,
rangeFill = rangeFill ?: darkBackgroundColor.paint,
grooveThicknessRatio = grooveThicknessRatio ?: 0.5f,
showTicks = showTicks,
focusManager = instanceOrNull()
).apply {
disabledPaintMapper = [email protected]
}
}
}
}
public fun basicRangeSliderBehavior(
barFill : Paint? = null,
knobFill : Paint? = null,
rangeFill : Paint? = knobFill,
grooveThicknessRatio: Float? = null,
showTicks : TickPresentation? = null): Module = basicRangeSliderBehavior(
barFill = barFill,
startKnobFill = knobFill,
rangeFill = rangeFill,
grooveThicknessRatio = grooveThicknessRatio,
showTicks = showTicks
)
@Deprecated("Use basicSpinButtonBehavior", ReplaceWith("basicSpinButtonBehavior(backgroundColor, darkBackgroundColor, foregroundColor, cornerRadius, buttonWidth, incrementA11yLabel, decrementA11yLabel)"))
public fun basicSpinnerBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
incrementA11yLabel : String? = null,
decrementA11yLabel : String? = null,
): Module = basicSpinButtonBehavior(
backgroundColor = backgroundColor,
darkBackgroundColor = darkBackgroundColor,
foregroundColor = foregroundColor,
cornerRadius = cornerRadius,
buttonWidth = buttonWidth,
incrementA11yLabel = incrementA11yLabel,
decrementA11yLabel = decrementA11yLabel
)
public fun basicSpinButtonBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
incrementA11yLabel : String? = null,
decrementA11yLabel : String? = null,
): Module = basicThemeModule(name = "BasicSpinButtonBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
BasicSpinButtonBehavior>(
instance(),
buttonWidth = buttonWidth ?: 20.0,
focusManager = instanceOrNull(),
cornerRadius = cornerRadius ?: this.cornerRadius,
backgroundColor = backgroundColor ?: this.backgroundColor,
foregroundColor = foregroundColor ?: this.foregroundColor,
incrementA11yLabel = incrementA11yLabel,
decrementA11yLabel = decrementA11yLabel,
darkBackgroundColor = darkBackgroundColor ?: this.darkBackgroundColor,
).apply {
hoverColorMapper = [email protected]
disabledColorMapper = [email protected]
}
}
}
}
@Deprecated("Use basicMutableSpinButtonBehavior", ReplaceWith("basicMutableSpinButtonBehavior(backgroundColor, darkBackgroundColor, foregroundColor, cornerRadius, buttonWidth, incrementA11yLabel, decrementA11yLabel)"))
public fun basicMutableSpinnerBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
incrementA11yLabel : String? = null,
decrementA11yLabel : String? = null,
): Module = basicMutableSpinButtonBehavior(
backgroundColor = backgroundColor,
darkBackgroundColor = darkBackgroundColor,
foregroundColor = foregroundColor,
cornerRadius = cornerRadius,
buttonWidth = buttonWidth,
incrementA11yLabel = incrementA11yLabel,
decrementA11yLabel = decrementA11yLabel
)
public fun basicMutableSpinButtonBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
incrementA11yLabel : String? = null,
decrementA11yLabel : String? = null,
): Module = basicThemeModule(name = "BasicMutableSpinButtonBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
BasicMutableSpinButtonBehavior>(
instance(),
buttonWidth = buttonWidth ?: 20.0,
cornerRadius = cornerRadius ?: this.cornerRadius,
focusManager = instanceOrNull(),
incrementLabel = incrementA11yLabel,
decrementLabel = decrementA11yLabel,
backgroundColor = backgroundColor ?: this.backgroundColor,
foregroundColor = foregroundColor ?: this.foregroundColor,
darkBackgroundColor = darkBackgroundColor ?: this.darkBackgroundColor,
).apply {
hoverColorMapper = [email protected]
disabledColorMapper = [email protected]
}
}
}
}
public fun basicCheckBoxBehavior(
foregroundColor : Color? = null,
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
cornerRadius : Double? = null,
iconTextSpacing : Double? = null,
iconInset : Double? = null,
checkInset : ((CheckBox) -> Float)? = null,
iconSize : ((CheckBox) -> Size)? = null
): Module = basicThemeModule(name = "BasicCheckBoxBehavior") {
bindBehavior(BTheme::class) { checkBox ->
val iconInsets = iconInset ?: 1.0
checkBox.behavior = instance().run { BasicCheckBoxBehavior(
instance(),
iconSize = iconSize ?: { Size(maxOf(0.0, minOf(16.0, it.height - 2 * iconInsets, it.width - 2 * iconInsets))) },
checkInset = checkInset ?: { 0.5f },
iconTextSpacing = iconTextSpacing ?: 8.0,
iconInset = iconInsets,
cornerRadius = cornerRadius ?: this.checkBoxCornerRadius,
backgroundColor = backgroundColor ?: this.backgroundColor,
foregroundColor = foregroundColor ?: this.foregroundColor,
darkBackgroundColor = darkBackgroundColor ?: this.darkBackgroundColor,
hoverColorMapper = [email protected] ,
disabledColorMapper = [email protected] ,
focusManager = instanceOrNull()
) as Behavior }
}
}
public fun basicRadioButtonBehavior(
foregroundColor : Color? = null,
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
iconSpacing : Double? = null,
iconInset : Double? = null,
innerCircleInset : ((RadioButton) -> Double)? = null,
iconSize : ((RadioButton) -> Size )? = null,
): Module = basicThemeModule(name = "BasicRadioButtonBehavior") {
bindBehavior(BTheme::class) {radioButton ->
val iconInsets = iconInset ?: 1.0
radioButton.behavior = instance().run { BasicRadioBehavior(
instance(),
iconTextSpacing = iconSpacing ?: 8.0,
iconSize = iconSize ?: { Size(maxOf(0.0, minOf(16.0, it.height - 2 * iconInsets, it.width - 2 * iconInsets))) },
backgroundColor = backgroundColor ?: this.backgroundColor,
foregroundColor = foregroundColor ?: this.foregroundColor,
iconInset = iconInsets,
innerCircleInset = innerCircleInset ?: { 4.0 },
darkBackgroundColor = darkBackgroundColor ?: this.darkBackgroundColor,
hoverColorMapper = [email protected] ,
disabledColorMapper = [email protected] ,
focusManager = instanceOrNull(),
) as Behavior }
}
}
public fun basicSwitchBehavior(
onBackground : Color? = null,
onForeground : Color? = null,
offBackground: Color? = null,
offForeground: Color? = null
): Module = basicThemeModule(name = "BasicSwitchBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicSwitchBehavior(
onBackground ?: Blue,
onForeground ?: White,
offBackground?: backgroundColor,
offForeground?: onForeground ?: White,
focusManager = instanceOrNull()).apply {
hoverColorMapper = [email protected]
disabledColorMapper = [email protected]
} as Behavior
}
}
}
public fun basicSplitPanelBehavior(
showDivider : Boolean = false,
background : Paint? = null,
dividerBackground: Paint? = null
): Module = basicThemeModule(name = "BasicSplitPanelBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicSplitPanelBehavior(
background = background ?: this.backgroundColor.paint,
dividerBackground = dividerBackground ?: if (showDivider) this.backgroundColor.paint else null,
)
}
}
}
public fun basicProgressBarBehavior(
background : Paint? = null,
foreground : Paint? = null,
outlineColor : Color? = null,
backgroundRadius: Double? = null,
foregroundRadius: Double? = backgroundRadius): Module = basicThemeModule(name = "BasicProgressBarBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicProgressBarBehavior(
background = background ?: defaultBackgroundColor.paint,
foreground = foreground ?: darkBackgroundColor.paint,
outlineColor = outlineColor,
backgroundRadius = backgroundRadius ?: cornerRadius,
foregroundRadius = foregroundRadius ?: 0.0).apply {
disabledPaintMapper = [email protected]
} as Behavior
}
}
}
public fun basicCircularProgressIndicatorBehavior(
foreground : Paint? = null,
background : Paint? = null,
thickness : Double = 15.0,
outline : Stroke? = null,
startAngle : Measure = -90 * degrees,
direction : RotationDirection = Clockwise,
startCap : SegmentBuilder = { _,_ -> },
endCap : SegmentBuilder = { _,it -> lineTo(it) }): Module = basicThemeModule(name = "BasicCircularProgressBarBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicCircularProgressIndicatorBehavior(
foreground ?: darkBackgroundColor.paint,
background ?: defaultBackgroundColor.paint,
thickness,
outline,
startAngle,
direction,
startCap,
endCap
).apply {
disabledPaintMapper = [email protected]
}
}
}
}
public fun basicPathProgressIndicatorBehavior(
path : Path,
foreground : Paint? = null,
background : Paint? = null,
foregroundThickness: Double = 1.0,
backgroundThickness: Double = foregroundThickness,
direction : Direction = Direction.Forward
): Module = basicThemeModule(name = "BasicPathProgressIndicatorBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
PathProgressIndicatorBehavior(
pathMetrics = instance(),
path = path,
foreground = foreground ?: darkBackgroundColor.paint,
background = background ?: defaultBackgroundColor.paint,
foregroundThickness = foregroundThickness,
backgroundThickness = backgroundThickness,
direction = direction).apply {
disabledPaintMapper = [email protected]
}
}
}
}
public fun basicCircularSliderBehavior(
barFill : Paint? = null,
knobFill : Paint? = null,
rangeFill: Paint? = null,
thickness: Double = 20.0
): Module = basicThemeModule(name = "BasicCircularSliderBehavior") {
bindBehavior>(BTheme::class) {
it.behavior = instance().run {
BasicCircularSliderBehavior(
barFill = barFill ?: defaultBackgroundColor.paint,
knobFill = knobFill ?: darkBackgroundColor.paint,
rangeFill = rangeFill,
thickness = thickness,
focusManager = instanceOrNull()
).apply {
disabledPaintMapper = [email protected]
}
}
}
}
/**
* Creates a basic behavior for rendering [CircularRangeSlider]s.
*
* @param barFill for the slider's background
* @param startKnobFill for the knob at the start of the slider's range
* @param endKnobFill for the knob at the end of the slider's range
* @param rangeFill for the slider's range region
* @param thickness of the slider
*/
public fun basicCircularRangeSliderBehavior(
barFill : Paint? = null,
startKnobFill : Paint? = null,
endKnobFill : Paint? = startKnobFill,
rangeFill : Paint? = endKnobFill,
thickness : Double = 20.0
): Module = basicThemeModule(name = "BasicCircularRangeSliderBehavior") {
bindBehavior>(BTheme::class) {
it.behavior = instance().run {
BasicCircularRangeSliderBehavior(
barFill = barFill ?: defaultBackgroundColor.paint,
startKnobFill = startKnobFill ?: darkBackgroundColor.paint,
endKnobFill = endKnobFill ?: startKnobFill ?: darkBackgroundColor.paint,
rangeFill = rangeFill ?: darkBackgroundColor.paint,
thickness = thickness,
focusManager = instanceOrNull()
).apply {
disabledPaintMapper = [email protected]
}
}
}
}
/**
* Creates a basic behavior for rendering [CircularRangeSlider]s.
*
* @param barFill for the slider's background
* @param knobFill for the knob at the start of the slider's range
* @param rangeFill for the slider's range region
* @param thickness of the slider
*/
public fun basicCircularRangeSliderBehavior(
barFill : Paint? = null,
knobFill : Paint? = null,
rangeFill: Paint? = knobFill,
thickness: Double = 20.0): Module = basicCircularRangeSliderBehavior(
barFill = barFill,
startKnobFill = knobFill,
rangeFill = rangeFill,
thickness = thickness
)
public fun basicTabbedPanelBehavior(
tabProducer : TabProducer? = null,
backgroundColor: Color? = null,
tabContainer : TabContainerFactory? = null): Module = basicThemeModule(name = "BasicTabbedPanelBehavior") {
bindBehavior>(BTheme::class) {
it.behavior = instance().run {
BasicTabbedPanelBehavior(
tabProducer ?: BasicTabProducer(
tabColor = backgroundColor ?: this.backgroundColor,
hoverColorMapper = [email protected] ,
selectedColorMapper = { foregroundColor.inverted }
),
backgroundColor ?: this.backgroundColor,
tabContainer?.let {
{ panel: TabbedPanel, tabProducer: TabProducer ->
it(this@bindBehavior, panel, tabProducer)
}
} ?: { panel, tabProducer -> SimpleTabContainer(panel, tabProducer) }
)
}
}
}
@Deprecated("Use basicSelectBoxBehavior", ReplaceWith("basicSelectBoxBehavior(backgroundColor, darkBackgroundColor, foregroundColor, cornerRadius, buttonWidth, buttonA11yLabel, inset)"))
public fun basicDropdownBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
buttonA11yLabel : String? = null,
inset : Double? = null,
): Module = basicSelectBoxBehavior(
backgroundColor = backgroundColor,
darkBackgroundColor = darkBackgroundColor,
foregroundColor = foregroundColor,
cornerRadius = cornerRadius,
buttonWidth = buttonWidth,
buttonA11yLabel = buttonA11yLabel,
inset = inset
)
public fun basicSelectBoxBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
buttonA11yLabel : String? = null,
inset : Double? = null,
): Module = basicThemeModule(name = "BasicSelectBoxBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
BasicSelectBoxBehavior>(
display = instance(),
textMetrics = instance(),
buttonWidth = buttonWidth ?: 20.0,
focusManager = instanceOrNull(),
popupManager = instanceOrNull(),
cornerRadius = cornerRadius ?: this.cornerRadius,
backgroundColor = backgroundColor ?: this.backgroundColor,
foregroundColor = foregroundColor ?: this.foregroundColor,
buttonA11yLabel = buttonA11yLabel,
darkBackgroundColor = darkBackgroundColor ?: this.darkBackgroundColor,
inset = inset ?: 4.0,
).apply {
hoverColorMapper = [email protected]
disabledColorMapper = [email protected]
}
}
}
}
@Deprecated("Use basicMutableSelectBoxBehavior", ReplaceWith("basicMutableSelectBoxBehavior(backgroundColor, darkBackgroundColor, foregroundColor, cornerRadius, buttonWidth, buttonA11yLabel, inset)"))
public fun basicMutableDropdownBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
buttonA11yLabel : String? = null,
inset : Double? = null,
): Module = basicMutableSelectBoxBehavior(
backgroundColor = backgroundColor,
darkBackgroundColor = darkBackgroundColor,
foregroundColor = foregroundColor,
cornerRadius = cornerRadius,
buttonWidth = buttonWidth,
buttonA11yLabel = buttonA11yLabel,
inset = inset
)
public fun basicMutableSelectBoxBehavior(
backgroundColor : Color? = null,
darkBackgroundColor: Color? = null,
foregroundColor : Color? = null,
cornerRadius : Double? = null,
buttonWidth : Double? = null,
buttonA11yLabel : String? = null,
inset : Double? = null,
): Module = basicThemeModule(name = "BasicMutableSelectBoxBehavior") {
bindBehavior>>(BTheme::class) {
it.behavior = instance().run {
BasicMutableSelectBoxBehavior>(
display = instance(),
textMetrics = instance(),
buttonWidth = buttonWidth ?: 20.0,
focusManager = instanceOrNull(),
popupManager = instanceOrNull(),
cornerRadius = cornerRadius ?: this.cornerRadius,
backgroundColor = backgroundColor ?: this.backgroundColor,
foregroundColor = foregroundColor ?: this.foregroundColor,
darkBackgroundColor = darkBackgroundColor ?: this.darkBackgroundColor,
buttonA11yLabel = buttonA11yLabel,
inset = inset ?: 4.0,
).apply {
hoverColorMapper = [email protected]
disabledColorMapper = [email protected]
}
}
}
}
public fun basicMonthPanelBehavior(background: Paint? = null): Module = basicThemeModule(name = "BasicMonthPanelBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicMonthPanelBehavior(background ?: [email protected] )
}
}
}
public fun basicDaysOfTheWeekPanelBehavior(
background : Paint? = null,
defaultVisualizer: ItemVisualizer? = null
): Module = basicThemeModule(name = "BasicDaysOfTheWeekPanelBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicDaysOfTheWeekPanelBehavior(background ?: [email protected] , defaultVisualizer)
}
}
}
public fun basicGridPanelBehavior(background: Paint? = null): Module = basicThemeModule(name = "BasicGridPanelBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
object: Behavior {
override fun render(view: GridPanel, canvas: Canvas) {
canvas.rect(view.bounds.atOrigin, fill = (background ?: [email protected] ))
}
}
}
}
}
public fun basicMenuBehavior(
menuFillPaint : Paint? = null,
itemTextPaint : Paint? = null,
itemDisabledTextPaint : Paint? = null,
subMenuIconPaint : Paint? = null,
itemHighlightPaint : Paint? = null,
itemTextSelectedPaint : Paint? = null,
subMenuIconSelectedPaint : Paint? = null,
separatorPaint : Paint? = null,
): Module = basicThemeModule(name = "BasicMenuBehavior") {
bindBehavior(BTheme::class) {
it.behavior = instance().run {
BasicMenuBehavior(instance(), instance(), config = Config(
menuFillPaint = menuFillPaint ?: this.backgroundColor.paint,
itemTextPaint = itemTextPaint ?: this.foregroundColor.paint,
itemDisabledTextPaint = itemDisabledTextPaint ?: this.disabledPaintMapper(this.foregroundColor.paint),
subMenuIconPaint = subMenuIconPaint ?: this.foregroundColor.paint,
itemHighlightPaint = itemHighlightPaint ?: this.selectionColor.paint,
itemTextSelectedPaint = itemTextSelectedPaint ?: White.paint,
subMenuIconSelectedPaint = subMenuIconSelectedPaint ?: White.paint,
separatorPaint = separatorPaint ?: this.darkBackgroundColor.paint,
))
}
}
}
public fun basicThemeBehaviors(): kotlin.collections.List = listOf(
basicListBehavior(),
basicTreeBehavior(),
basicLabelBehavior(),
basicTableBehavior(),
basicButtonBehavior(),
basicSwitchBehavior(),
basicSliderBehavior(),
basicRangeSliderBehavior(),
basicCircularSliderBehavior(),
basicCircularRangeSliderBehavior(),
basicSpinButtonBehavior(),
basicCheckBoxBehavior(),
basicSelectBoxBehavior(),
basicSplitPanelBehavior(),
basicRadioButtonBehavior(),
basicMutableListBehavior(),
basicProgressBarBehavior(foregroundRadius = null),
basicMutableTreeBehavior(),
basicTreeColumnsBehavior(),
basicTabbedPanelBehavior(),
basicMutableTableBehavior(),
basicMutableSpinButtonBehavior(),
basicMutableSelectBoxBehavior(),
basicMonthPanelBehavior(),
basicDaysOfTheWeekPanelBehavior(),
basicGridPanelBehavior(),
basicMenuBehavior(),
)
}
}
public class DarkBasicTheme(configProvider: ConfigProvider, behaviors: Iterable): BasicTheme(configProvider, behaviors) {
public class DarkBasicThemeConfig: BasicThemeConfig {
override val borderColor : Color = super.borderColor.inverted
override val foregroundColor : Color = super.foregroundColor.inverted
override val backgroundColor : Color = super.backgroundColor.inverted
override val darkBackgroundColor : Color = super.darkBackgroundColor.inverted
override val lightBackgroundColor : Color = Color(0x282928u)
override val defaultBackgroundColor: Color = super.defaultBackgroundColor.inverted
override val hoverColorMapper : ColorMapper = { it.lighter(0.3f) }
override val disabledColorMapper : ColorMapper = { it.darker() }
override val disabledPaintMapper : PaintMapper = { paint ->
when (paint) {
is ColorPaint -> paint.color.darker().paint
is LinearGradientPaint -> LinearGradientPaint(paint.colors.map { GradientPaint.Stop(it.color.darker(), it.offset) }, start = paint.start, end = paint.end)
is RadialGradientPaint -> RadialGradientPaint(paint.colors.map { GradientPaint.Stop(it.color.darker(), it.offset) }, start = paint.start, end = paint.end)
is ImagePaint -> ImagePaint(image = paint.image, size = paint.size, opacity = paint.opacity * 0.5f)
is PatternPaint -> PatternPaint(paint.bounds, paint.transform, paint.opacity * 0.5f, paint.paint)
else -> paint
}
}
}
override val config: BasicThemeConfig = DarkBasicThemeConfig()
public companion object {
public val DarkBasicTheme: Module = basicThemeModule(name = "DarkBasicTheme") {
bind() with singleton { DarkBasicTheme(instance(), Instance(erasedSet())) }
}
}
}