From 398cfa0a80bc10c6580557e9688ba4390b89917b Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 3 Nov 2017 15:52:47 +0100 Subject: Select form component --- src/main/kotlin/pl/treksoft/kvision/Showcase.kt | 6 ++++++ .../pl/treksoft/kvision/data/DataContainer.kt | 16 +++++++++------ .../pl/treksoft/kvision/dropdown/DropDown.kt | 15 ++++++++++++++ src/main/kotlin/pl/treksoft/kvision/form/Select.kt | 24 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt index b4abad0c..a0ea6881 100644 --- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt +++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt @@ -110,6 +110,12 @@ class Showcase : ApplicationBase() { val select5 = Select(listOf("a" to "Pierwsza", "b" to "Druga"), "a", label = "Lista wyboru") root.add(select5) + val select6 = Select(label = "Lista wyboru 2") + select6.add(SelectOption("a", "Opcja 1")) + select6.add(SelectOption("b", "Opcja 2")) + select6.add(SelectOption("c", "Opcja 3")) + root.add(select6) + val container = SimplePanel(setOf("abc", "def")) val h1 = Tag(H1, "To jest test pisania tekstu", false, null, classes = setOf("test", "test2")) container.add(h1) diff --git a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt index 3b6d3aa8..5af2eb66 100644 --- a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt +++ b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt @@ -7,8 +7,8 @@ import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.panel.VPanel class DataContainer(val model: ObservableList, - private val binding: (M, Int) -> C, - private val child: Container = VPanel()) : + private val binding: (M, Int) -> C, + private val child: Container = VPanel()) : Widget(setOf()), Container, DataUpdatable { override var visible @@ -26,19 +26,23 @@ class DataContainer(val model: ObservableList, } override fun add(child: Widget): Container { - return this.child.add(child) + this.child.add(child) + return this } override fun addAll(children: List): Container { - return this.child.addAll(children) + this.child.addAll(children) + return this } override fun remove(child: Widget): Container { - return this.child.remove(child) + this.child.remove(child) + return this } override fun removeAll(): Container { - return this.child.removeAll() + this.child.removeAll() + return this } override fun getChildren(): List { diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index eabed092..ade2937b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -97,6 +97,21 @@ open class DropDown(text: String, elements: List? = null, icon: Stri return this } + override fun remove(child: Widget): SimplePanel { + list.remove(child) + return this + } + + override fun removeAll(): SimplePanel { + list.removeAll() + return this + } + + override fun getChildren(): List { + return list.getChildren() + } + + private fun setChildrenFromElements() { list.removeAll() elements?.let { elems -> diff --git a/src/main/kotlin/pl/treksoft/kvision/form/Select.kt b/src/main/kotlin/pl/treksoft/kvision/form/Select.kt index 413178d2..a8759208 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/Select.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/Select.kt @@ -119,4 +119,28 @@ open class Select(options: List? = null, value: String? = null, input.removeEventListeners() return this } + + override fun add(child: Widget): SimplePanel { + input.add(child) + return this + } + + override fun addAll(children: List): SimplePanel { + input.addAll(children) + return this + } + + override fun remove(child: Widget): SimplePanel { + input.remove(child) + return this + } + + override fun removeAll(): SimplePanel { + input.removeAll() + return this + } + + override fun getChildren(): List { + return input.getChildren() + } } -- cgit