From 38d8447b7024112f54a4d2a4404840cae5e4d849 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 24 Mar 2019 00:47:11 +0100 Subject: Some fixes for CSS style objects. --- src/main/kotlin/pl/treksoft/kvision/core/Style.kt | 14 +++----- src/main/kotlin/pl/treksoft/kvision/panel/Root.kt | 39 ++++++++++++++--------- 2 files changed, 28 insertions(+), 25 deletions(-) (limited to 'src/main') diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt index c2858fa0..62154f77 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt @@ -40,7 +40,7 @@ import pl.treksoft.kvision.panel.Root open class Style(className: String? = null, parentStyle: Style? = null, init: (Style.() -> Unit)? = null) : StyledComponent() { - override var parent: Container? = null + override var parent: Container? = Root.getFirstRoot() private val newClassName: String = if (parentStyle == null) { className ?: "kv_styleclass_${counter++}" @@ -54,15 +54,7 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S var className: String by refreshOnUpdate(newClassName) init { - val root = Root.getLastRoot() - @Suppress("LeakingThis") - parent = root - if (root != null) { - @Suppress("LeakingThis") - root.addStyle(this) - } else { - println("At least one Root object is required to create a style object!") - } + styles.add(this) @Suppress("LeakingThis") init?.invoke(this) } @@ -141,10 +133,12 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S } override fun dispose() { + styles.remove(this) } companion object { internal var counter = 0 + internal var styles = mutableListOf