aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/Showcase.kt5
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Types.kt21
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Widget.kt31
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Button.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Image.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Tag.kt7
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt4
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt1
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt10
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt6
12 files changed, 61 insertions, 44 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
index 3bc6a348..aa97a026 100644
--- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
@@ -4,6 +4,7 @@ import pl.treksoft.kvision.basic.Label
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.Img
import pl.treksoft.kvision.core.Root
+import pl.treksoft.kvision.core.UNIT
import pl.treksoft.kvision.dropdown.DD.*
import pl.treksoft.kvision.dropdown.DropDown
import pl.treksoft.kvision.html.*
@@ -21,7 +22,7 @@ class Showcase : ApplicationBase() {
val root = Root("showcase")
val container = Container(setOf("abc", "def"))
- val h1 = Tag(H1, "To jest <i>test pisania</i> tekstu", false, ALIGN.NONE, classes = setOf("test", "test2"))
+ val h1 = Tag(H1, "To jest <i>test pisania</i> tekstu", false, null, classes = setOf("test", "test2"))
container.add(h1)
val label = Label("KVLabel1")
container.add(label)
@@ -167,7 +168,7 @@ class Showcase : ApplicationBase() {
pa.add(Label("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec fringilla turpis, vel molestie dolor. Vestibulum ut ex eget orci porta gravida eu sit amet tortor. Suspendisse vel fermentum purus, vel ornare tellus. Vivamus dictum, risus non viverra venenatis, magna mi pharetra purus, nec dignissim risus tortor a sem. Donec tincidunt dui ut eros laoreet consectetur. Nam dapibus vestibulum sem, eget accumsan ex vestibulum ac. Curabitur ac mi sit amet eros sodales dictum. Sed at felis at nunc aliquam finibus. Vestibulum lorem nulla, dictum ac libero non, mattis dictum nisl. Aenean semper lorem turpis. Praesent pellentesque ligula est, viverra molestie leo imperdiet ut. Nam vitae hendrerit justo. Nullam tincidunt et nibh ac volutpat. Aliquam vulputate mi aliquam fermentum rhoncus."),3)
pa.add(Image(Img("kotlin.png")),1)
pa.add(dock,2,alignSelf = FLEXALIGNITEMS.FLEXSTART)
- dock.width = 400
+ dock.width = 400 to UNIT.px
root.add(pa)
val modal = Modal("Test okienka")
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Types.kt b/src/main/kotlin/pl/treksoft/kvision/core/Types.kt
new file mode 100644
index 00000000..df0eb98b
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Types.kt
@@ -0,0 +1,21 @@
+package pl.treksoft.kvision.core
+
+@Suppress("EnumNaming", "EnumEntryName")
+enum class UNIT(val unit: String) {
+ px("px"),
+ pt("pt"),
+ em("em"),
+ cm("cm"),
+ mm("mm"),
+ `in`("in"),
+ pc("pc"),
+ ch("ch"),
+ rem("rem"),
+ vw("vw"),
+ vh("vh"),
+ vmin("vmin"),
+ vmax("vmax"),
+ perc("%")
+}
+
+typealias Length = Pair<Int, UNIT>
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
index e2a4f09f..ff34186b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt
@@ -47,17 +47,12 @@ open class Widget(classes: Set<String> = setOf()) : KVObject {
field = value
refresh()
}
- var width: Int? = null
+ var width: Length? = null
set(value) {
field = value
refresh()
}
- var widthPercent: Int? = null
- set(value) {
- field = value
- refresh()
- }
- var height: Int? = null
+ var height: Length? = null
set(value) {
field = value
refresh()
@@ -139,13 +134,11 @@ open class Widget(classes: Set<String> = setOf()) : KVObject {
protected open fun getSnStyle(): List<StringPair> {
val snstyle = mutableListOf<StringPair>()
- if (width != null) {
- snstyle.add("width" to width.toString() + "px")
- } else if (widthPercent != null) {
- snstyle.add("width" to widthPercent.toString() + "%")
+ width?.let {
+ snstyle.add("width" to it.first.toString() + it.second.unit)
}
- if (height != null) {
- snstyle.add("height" to height.toString() + "px")
+ height?.let {
+ snstyle.add("height" to it.first.toString() + it.second.unit)
}
return snstyle
}
@@ -157,14 +150,14 @@ open class Widget(classes: Set<String> = setOf()) : KVObject {
protected open fun getSnAttrs(): List<StringPair> {
val snattrs = mutableListOf<StringPair>()
- if (id != null) {
- snattrs.add("id" to id.orEmpty())
+ id?.let {
+ snattrs.add("id" to it)
}
- if (title != null) {
- snattrs.add("title" to title.orEmpty())
+ title?.let {
+ snattrs.add("title" to it)
}
- if (role != null) {
- snattrs.add("role" to role.orEmpty())
+ role?.let {
+ snattrs.add("role" to it)
}
return snattrs
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
index 74822401..d10cb8cd 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
@@ -70,8 +70,8 @@ open class Button(text: String, icon: String? = null, style: BUTTONSTYLE = BUTTO
val cl = super.getSnClass().toMutableList()
cl.add("btn" to true)
cl.add(style.className to true)
- if (size != null) {
- cl.add(size?.className.orEmpty() to true)
+ size?.let {
+ cl.add(it.className to true)
}
if (block) {
cl.add("btn-block" to true)
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt
index c9566531..50840f71 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Image.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Image.kt
@@ -47,7 +47,9 @@ open class Image(src: ResString, alt: String? = null, responsive: Boolean = fals
override fun getSnAttrs(): List<StringPair> {
val pr = super.getSnAttrs().toMutableList()
pr.add("src" to src)
- if (alt != null) pr.add("alt" to alt.orEmpty())
+ alt?.let {
+ pr.add("alt" to it)
+ }
return pr
}
@@ -59,8 +61,8 @@ open class Image(src: ResString, alt: String? = null, responsive: Boolean = fals
if (centered) {
cl.add("center-block" to true)
}
- if (shape != null) {
- cl.add(shape?.className.orEmpty() to true)
+ shape?.let {
+ cl.add(it.className to true)
}
return cl
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
index cb8330ac..da964f6e 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Tag.kt
@@ -41,7 +41,6 @@ enum class TAG(val tagName: String) {
}
enum class ALIGN(val className: String) {
- NONE(""),
LEFT("text-left"),
CENTER("text-center"),
RIGHT("text-right"),
@@ -49,7 +48,7 @@ enum class ALIGN(val className: String) {
NOWRAP("text-nowrap")
}
-open class Tag(type: TAG, text: String? = null, rich: Boolean = false, align: ALIGN = ALIGN.NONE,
+open class Tag(type: TAG, text: String? = null, rich: Boolean = false, align: ALIGN? = null,
classes: Set<String> = setOf()) : Container(classes) {
var type = type
set(value) {
@@ -86,8 +85,8 @@ open class Tag(type: TAG, text: String? = null, rich: Boolean = false, align: AL
override fun getSnClass(): List<StringBoolPair> {
val cl = super.getSnClass().toMutableList()
- if (align != ALIGN.NONE) {
- cl.add(align.className to true)
+ align?.let {
+ cl.add(it.className to true)
}
return cl
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt
index c04449c2..39268ffa 100644
--- a/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt
@@ -8,7 +8,7 @@ import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
open class Alert(caption: String? = null, text: String? = null, rich: Boolean = false,
- align: ALIGN = ALIGN.NONE, size: MODALSIZE? = null, animation: Boolean = true,
+ align: ALIGN? = null, size: MODALSIZE? = null, animation: Boolean = true,
private val callback: (() -> Unit)? = null) : Modal(caption, true, size, animation) {
var text
get() = content.text
@@ -48,7 +48,7 @@ open class Alert(caption: String? = null, text: String? = null, rich: Boolean =
companion object {
@Suppress("LongParameterList")
fun show(caption: String? = null, text: String? = null, rich: Boolean = false,
- align: ALIGN = ALIGN.NONE, size: MODALSIZE? = null, animation: Boolean = true,
+ align: ALIGN? = null, size: MODALSIZE? = null, animation: Boolean = true,
callback: (() -> Unit)? = null) {
Alert(caption, text, rich, align, size, animation, callback).show()
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt
index aa4e8b88..90766854 100644
--- a/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt
@@ -7,7 +7,7 @@ import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
open class Confirm(caption: String? = null, text: String? = null, rich: Boolean = false,
- align: ALIGN = ALIGN.NONE, size: MODALSIZE? = null, animation: Boolean = true,
+ align: ALIGN? = null, size: MODALSIZE? = null, animation: Boolean = true,
cancelVisible: Boolean = false,
private val noCallback: (() -> Unit)? = null,
private val yesCallback: (() -> Unit)? = null) : Modal(caption, false, size, animation, false) {
@@ -75,7 +75,7 @@ open class Confirm(caption: String? = null, text: String? = null, rich: Boolean
companion object {
@Suppress("LongParameterList")
fun show(caption: String? = null, text: String? = null, rich: Boolean = false,
- align: ALIGN = ALIGN.NONE, size: MODALSIZE? = null, animation: Boolean = true,
+ align: ALIGN? = null, size: MODALSIZE? = null, animation: Boolean = true,
cancelVisible: Boolean = false,
noCallback: (() -> Unit)? = null, yesCallback: (() -> Unit)? = null) {
Confirm(caption, text, rich, align, size, animation, cancelVisible, noCallback, yesCallback).show()
diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
index 69a83dfb..94796326 100644
--- a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt
@@ -180,8 +180,8 @@ open class ModalDialog(size: MODALSIZE?) : Container(setOf("modal-dialog")) {
override fun getSnClass(): List<StringBoolPair> {
val cl = super.getSnClass().toMutableList()
- if (size != null) {
- cl.add(size?.className.orEmpty() to true)
+ size?.let {
+ cl.add(it.className to true)
}
return cl
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
index 781f8dcd..10483a8d 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
@@ -124,7 +124,6 @@ open class FlexPanel(direction: FLEXDIR? = null, wrap: FLEXWRAP? = null, justify
alignContent?.let {
snstyle.add("align-content" to it.alignContent)
}
- println("abc")
return snstyle
}
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
index af4dd53f..17b3803f 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
@@ -19,7 +19,7 @@ const val MAX_COLUMNS = 12
internal data class WidgetParam(val widget: Widget, val size: Int, val offset: Int)
open class ResponsiveGridPanel(private val gridsize: GRIDSIZE = GRIDSIZE.MD,
- private var rows: Int = 0, private var cols: Int = 0, align: ALIGN = ALIGN.NONE,
+ private var rows: Int = 0, private var cols: Int = 0, align: ALIGN? = null,
classes: Set<String> = setOf()) : Container(classes) {
protected var align = align
set(value) {
@@ -87,8 +87,8 @@ open class ResponsiveGridPanel(private val gridsize: GRIDSIZE = GRIDSIZE.MD,
val widget = wp?.widget?.let {
WidgetWrapper(it, setOf("col-" + gridsize.size + "-" + num))
} ?: Tag(TAG.DIV, classes = setOf("col-" + gridsize.size + "-" + num))
- if (align != ALIGN.NONE) {
- widget.addCssClass(align.className)
+ align?.let {
+ widget.addCssClass(it.className)
}
rowContainer.add(widget)
} else {
@@ -98,8 +98,8 @@ open class ResponsiveGridPanel(private val gridsize: GRIDSIZE = GRIDSIZE.MD,
if (wp.offset > 0) {
widget.addCssClass("col-" + gridsize.size + "-offset-" + wp.offset)
}
- if (align != ALIGN.NONE) {
- widget.addCssClass(align.className)
+ align?.let {
+ widget.addCssClass(it.className)
}
rowContainer.add(widget)
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
index 569a5b85..06f9be59 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
@@ -4,6 +4,7 @@ import com.github.snabbdom.VNode
import pl.treksoft.jquery.JQuery
import pl.treksoft.jquery.JQueryEventObject
import pl.treksoft.kvision.core.Container
+import pl.treksoft.kvision.core.UNIT
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
import pl.treksoft.kvision.snabbdom.obj
@@ -23,6 +24,7 @@ open class SplitPanel(private val direction: DIRECTION = DIRECTION.VERTICAL,
internal fun afterInsertSplitter() {
if (children.size == 2) {
val horizontal = direction == DIRECTION.HORIZONTAL
+ val px = UNIT.px
val self = this
children[0].getElementJQueryD().resizable(obj {
handleSelector = "#" + splitter.id
@@ -36,9 +38,9 @@ open class SplitPanel(private val direction: DIRECTION = DIRECTION.VERTICAL,
}
onDragEnd = { e: JQueryEventObject, el: JQuery, _: dynamic ->
if (horizontal) {
- children[0].height = el.height().toInt()
+ children[0].height = el.height().toInt() to px
} else {
- children[0].width = el.width().toInt()
+ children[0].width = el.width().toInt() to px
}
self.dispatchEvent("dragEndSplitPanel", obj({ detail = e }))
}