aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Css.kt24
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt33
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt3
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt9
5 files changed, 37 insertions, 34 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Css.kt b/src/main/kotlin/pl/treksoft/kvision/core/Css.kt
index 1e6fdbeb..a5a85531 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Css.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Css.kt
@@ -1,5 +1,6 @@
package pl.treksoft.kvision.core
+import pl.treksoft.kvision.utils.asString
import pl.treksoft.kvision.utils.toHexString
typealias ResString = String
@@ -19,7 +20,8 @@ enum class UNIT(val unit: String) {
vh("vh"),
vmin("vmin"),
vmax("vmax"),
- perc("%")
+ perc("%"),
+ auto("auto")
}
typealias CssSize = Pair<Int, UNIT>
@@ -226,9 +228,7 @@ class Border private constructor(
constructor(width: CssSize? = null, style: BORDERSTYLE? = null, color: COLOR) : this(width, style, color.color)
fun asString(): String {
- val w = width?.let {
- it.first.toString() + it.second.unit
- }
+ val w = width?.asString()
return w.orEmpty() + " " + (style?.borderStyle).orEmpty() + " " + color.orEmpty()
}
}
@@ -286,18 +286,10 @@ class Background private constructor(
val img = image?.let {
"url($image)"
}
- val posX = positionX?.let {
- it.first.toString() + it.second.unit
- }
- val posY = positionY?.let {
- it.first.toString() + it.second.unit
- }
- val sX = sizeX?.let {
- it.first.toString() + it.second.unit
- }
- val sY = sizeY?.let {
- it.first.toString() + it.second.unit
- }
+ val posX = positionX?.asString()
+ val posY = positionY?.asString()
+ val sX = sizeX?.asString()
+ val sY = sizeY?.asString()
return color.orEmpty() + " " + img.orEmpty() + " " + posX.orEmpty() + " " + posY.orEmpty() +
if (sX != null || sY != null || size != null) {
(if (posX != null || posY != null) " / " else " 0px 0px / ") +
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt b/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt
index 12ed797e..f4bf6e09 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/StyledComponent.kt
@@ -1,6 +1,7 @@
package pl.treksoft.kvision.core
import pl.treksoft.kvision.snabbdom.StringPair
+import pl.treksoft.kvision.utils.asString
abstract class StyledComponent : Component {
@@ -155,22 +156,22 @@ abstract class StyledComponent : Component {
protected open fun getSnStyle(): List<StringPair> {
val snstyle = mutableListOf<StringPair>()
width?.let {
- snstyle.add("width" to it.first.toString() + it.second.unit)
+ snstyle.add("width" to it.asString())
}
minWidth?.let {
- snstyle.add("min-width" to it.first.toString() + it.second.unit)
+ snstyle.add("min-width" to it.asString())
}
maxWidth?.let {
- snstyle.add("max-width" to it.first.toString() + it.second.unit)
+ snstyle.add("max-width" to it.asString())
}
height?.let {
- snstyle.add("height" to it.first.toString() + it.second.unit)
+ snstyle.add("height" to it.asString())
}
minHeight?.let {
- snstyle.add("min-height" to it.first.toString() + it.second.unit)
+ snstyle.add("min-height" to it.asString())
}
maxHeight?.let {
- snstyle.add("max-height" to it.first.toString() + it.second.unit)
+ snstyle.add("max-height" to it.asString())
}
border?.let {
snstyle.add("border" to it.asString())
@@ -188,34 +189,34 @@ abstract class StyledComponent : Component {
snstyle.add("border-left" to it.asString())
}
margin?.let {
- snstyle.add("margin" to it.first.toString() + it.second.unit)
+ snstyle.add("margin" to it.asString())
}
marginTop?.let {
- snstyle.add("margin-top" to it.first.toString() + it.second.unit)
+ snstyle.add("margin-top" to it.asString())
}
marginRight?.let {
- snstyle.add("margin-right" to it.first.toString() + it.second.unit)
+ snstyle.add("margin-right" to it.asString())
}
marginBottom?.let {
- snstyle.add("margin-bottom" to it.first.toString() + it.second.unit)
+ snstyle.add("margin-bottom" to it.asString())
}
marginLeft?.let {
- snstyle.add("margin-left" to it.first.toString() + it.second.unit)
+ snstyle.add("margin-left" to it.asString())
}
padding?.let {
- snstyle.add("padding" to it.first.toString() + it.second.unit)
+ snstyle.add("padding" to it.asString())
}
paddingTop?.let {
- snstyle.add("padding-top" to it.first.toString() + it.second.unit)
+ snstyle.add("padding-top" to it.asString())
}
paddingRight?.let {
- snstyle.add("padding-right" to it.first.toString() + it.second.unit)
+ snstyle.add("padding-right" to it.asString())
}
paddingBottom?.let {
- snstyle.add("padding-bottom" to it.first.toString() + it.second.unit)
+ snstyle.add("padding-bottom" to it.asString())
}
paddingLeft?.let {
- snstyle.add("padding-left" to it.first.toString() + it.second.unit)
+ snstyle.add("padding-left" to it.asString())
}
color?.let {
snstyle.add("color" to it.asString())
diff --git a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
index 32546bd5..2c87daea 100644
--- a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt
@@ -56,7 +56,7 @@ class DataContainer<M : DataComponent, C : Widget>(
return this.child.renderVNode()
}
- open fun get(index: Int) = model[index]
+ fun get(index: Int) = model[index]
override fun update() {
model.forEach { it.container = this }
diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt
index f38429e3..6830823d 100644
--- a/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/form/select/SelectInput.kt
@@ -10,6 +10,7 @@ import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.snabbdom.StringBoolPair
import pl.treksoft.kvision.snabbdom.StringPair
import pl.treksoft.kvision.snabbdom.obj
+import pl.treksoft.kvision.utils.asString
enum class SELECTWIDTHTYPE(val value: String) {
AUTO("auto"),
@@ -254,7 +255,7 @@ open class SelectInput(
selectWidthType?.let {
sn.add("data-width" to it.value)
} ?: selectWidth?.let {
- sn.add("data-width" to it.first.toString() + it.second.unit)
+ sn.add("data-width" to it.asString())
}
return sn
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt
index b426e432..80a7c482 100644
--- a/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/utils/Utils.kt
@@ -23,6 +23,15 @@ fun Int.vh(): CssSize = Pair(this, UNIT.vh)
fun Int.vw(): CssSize = Pair(this, UNIT.vw)
fun Int.vmin(): CssSize = Pair(this, UNIT.vmin)
fun Int.vmax(): CssSize = Pair(this, UNIT.vmax)
+fun auto(): CssSize = Pair(0, UNIT.auto)
+
+fun CssSize.asString(): String {
+ return if (this.second != UNIT.auto) {
+ this.first.toString() + this.second.unit
+ } else {
+ "auto"
+ }
+}
private val hex = arrayOf("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f")