aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt6
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt10
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt5
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt9
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt6
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt11
11 files changed, 74 insertions, 13 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
index 7f32a61c..82d1c117 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
@@ -39,8 +39,10 @@ enum class SIDE {
*
* @constructor
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
-open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = classes) {
+open class DockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit)? = null) :
+ SimplePanel(classes = classes) {
/**
* @suppress
* Internal property.
@@ -84,6 +86,8 @@ open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = cla
init {
this.addInternal(mainContainer)
mainContainer.add(subContainer, 2)
+ @Suppress("LeakingThis")
+ init?.invoke(this)
}
/**
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
index 266612fe..5aebe1c6 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
@@ -92,11 +92,12 @@ enum class FLEXALIGNCONTENT(internal val alignContent: String) {
* @param alignContent flexbox content alignment
* @param spacing spacing between columns/rows
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class FlexPanel(
direction: FLEXDIR? = null, wrap: FLEXWRAP? = null, justify: FLEXJUSTIFY? = null,
alignItems: FLEXALIGNITEMS? = null, alignContent: FLEXALIGNCONTENT? = null,
- spacing: Int? = null, classes: Set<String> = setOf()
+ spacing: Int? = null, classes: Set<String> = setOf(), init: (FlexPanel.() -> Unit)? = null
) : SimplePanel(classes) {
/**
@@ -150,6 +151,11 @@ open class FlexPanel(
refresh()
}
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
/**
* Adds a component to the flexbox container.
* @param child child component
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
index b6f1d3a5..ba72535a 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
@@ -98,13 +98,14 @@ enum class GRIDFLOW(internal val flow: String) {
* @param justifyContent flexbox content justification
* @param alignContent flexbox content alignment
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class GridPanel(
autoColumns: String? = null, autoRows: String? = null, autoFlow: GRIDFLOW? = null,
templateColumns: String? = null, templateRows: String? = null, templateAreas: List<String>? = null,
columnGap: Int? = null, rowGap: Int? = null, justifyItems: GRIDJUSTIFY? = null,
alignItems: GRIDALIGN? = null, justifyContent: GRIDJUSTIFYCONTENT? = null,
- alignContent: GRIDALIGNCONTENT? = null, classes: Set<String> = setOf()
+ alignContent: GRIDALIGNCONTENT? = null, classes: Set<String> = setOf(), init: (GridPanel.() -> Unit)? = null
) : SimplePanel(classes) {
/**
@@ -204,6 +205,11 @@ open class GridPanel(
refresh()
}
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
/**
* Adds a component to the grid container.
* @param child child component
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
index 7639ca3b..755c675b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
@@ -32,11 +32,17 @@ package pl.treksoft.kvision.panel
* @param alignItems flexbox items alignment
* @param spacing spacing between columns/rows
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class HPanel(
wrap: FLEXWRAP? = null, justify: FLEXJUSTIFY? = null, alignItems: FLEXALIGNITEMS? = null, spacing: Int? = null,
- classes: Set<String> = setOf()
+ classes: Set<String> = setOf(), init: (HPanel.() -> Unit)? = null
) : FlexPanel(
null,
wrap, justify, alignItems, null, spacing, classes
-)
+) {
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
index 93588617..8831e905 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
@@ -50,11 +50,12 @@ internal data class WidgetParam(val widget: Component, val size: Int, val offset
* @param cols number of columns
* @param align text align of grid cells
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class ResponsiveGridPanel(
private val gridsize: GRIDSIZE = GRIDSIZE.MD,
private var rows: Int = 0, private var cols: Int = 0, align: ALIGN? = null,
- classes: Set<String> = setOf()
+ classes: Set<String> = setOf(), init: (ResponsiveGridPanel.() -> Unit)? = null
) : SimplePanel(classes) {
/**
@@ -69,6 +70,11 @@ open class ResponsiveGridPanel(
internal val map = mutableMapOf<Int, MutableMap<Int, WidgetParam>>()
private var auto: Boolean = true
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
/**
* Adds child component to the grid.
* @param child child component
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
index e10fdc86..d81b103d 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
@@ -37,8 +37,9 @@ import pl.treksoft.kvision.modal.Modal
* @param id ID attribute of element in the main HTML file
* @param fixed if false, the container is rendered with Bootstrap "container-fluid" class,
* otherwise it's rendered with "container" class (default is false)
+ * @param init an initializer extension function
*/
-class Root(id: String, private val fixed: Boolean = false) : SimplePanel() {
+class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Unit)? = null) : SimplePanel() {
private val modals: MutableList<Modal> = mutableListOf()
private var rootVnode: VNode = renderVNode()
@@ -48,6 +49,8 @@ class Root(id: String, private val fixed: Boolean = false) : SimplePanel() {
rootVnode = KVManager.patch(id, this.renderVNode())
this.id = id
roots.add(this)
+ @Suppress("LeakingThis")
+ init?.invoke(this)
}
override fun render(): VNode {
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
index b210f2cb..aad57023 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
@@ -31,10 +31,17 @@ import pl.treksoft.kvision.core.Widget
*
* @constructor
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
-open class SimplePanel(classes: Set<String> = setOf()) : Widget(classes), Container {
+open class SimplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> Unit)? = null) : Widget(classes),
+ Container {
internal val children: MutableList<Component> = mutableListOf()
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
override fun render(): VNode {
return render("div", childrenVNodes())
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
index cfeadd58..677d0704 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
@@ -47,15 +47,21 @@ enum class DIRECTION(internal val dir: String) {
* @constructor
* @param direction direction of the splitter
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class SplitPanel(
private val direction: DIRECTION = DIRECTION.VERTICAL,
- classes: Set<String> = setOf()
+ classes: Set<String> = setOf(), init: (SplitPanel.() -> Unit)? = null
) : SimplePanel(classes + ("splitpanel-" + direction.dir)) {
@Suppress("LeakingThis")
internal val splitter = Splitter(this, direction)
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
@Suppress("UnsafeCastFromDynamic")
internal fun afterInsertSplitter() {
if (children.size == 2) {
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
index 672c8690..cf765928 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
@@ -33,10 +33,11 @@ import pl.treksoft.kvision.routing.routing
* @constructor
* @param activateLast determines if added component is automatically activated (default true)
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class StackPanel(
private val activateLast: Boolean = true,
- classes: Set<String> = setOf()
+ classes: Set<String> = setOf(), init: (StackPanel.() -> Unit)? = null
) : SimplePanel(classes) {
/**
@@ -48,6 +49,11 @@ open class StackPanel(
refresh()
}
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+
override fun childrenVNodes(): Array<VNode> {
return if (activeIndex >= 0 && activeIndex < children.size) {
arrayOf(children[activeIndex].renderVNode())
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
index 9072d261..067a8146 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
@@ -35,8 +35,9 @@ import pl.treksoft.kvision.routing.routing
*
* @constructor
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
-open class TabPanel(classes: Set<String> = setOf()) : SimplePanel(classes) {
+open class TabPanel(classes: Set<String> = setOf(), init: (TabPanel.() -> Unit)? = null) : SimplePanel(classes) {
/**
* The index of active (visible) tab.
@@ -61,6 +62,9 @@ open class TabPanel(classes: Set<String> = setOf()) : SimplePanel(classes) {
init {
this.addInternal(nav)
this.addInternal(content)
+
+ @Suppress("LeakingThis")
+ init?.invoke(this)
}
/**
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
index 91ee4a6a..823ab66f 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
@@ -31,11 +31,18 @@ package pl.treksoft.kvision.panel
* @param alignItems flexbox items alignment
* @param spacing spacing between columns/rows
* @param classes a set of CSS class names
+ * @param init an initializer extension function
*/
open class VPanel(
justify: FLEXJUSTIFY? = null, alignItems: FLEXALIGNITEMS? = null, spacing: Int? = null,
- classes: Set<String> = setOf()
+ classes: Set<String> = setOf(), init: (VPanel.() -> Unit)? = null
) : FlexPanel(
FLEXDIR.COLUMN,
null, justify, alignItems, null, spacing, classes
-)
+) {
+ init {
+ @Suppress("LeakingThis")
+ init?.invoke(this)
+ }
+}
+