aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-17 21:58:34 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-17 21:58:34 +0200
commit736b80835f67c9c34657074ebcfbe0752bef1c18 (patch)
tree82d1e18a9ec07692dfe5dd31f470b842a9950a89 /src/main/kotlin/pl/treksoft/kvision/panel
parent53b325d52208bfd44ba6a524ce3dda5379aed699 (diff)
downloadkvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.gz
kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.bz2
kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.zip
Move DSL builder functions out of the companion objects (#93)
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt22
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt30
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt40
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt36
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt47
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt22
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt28
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt26
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt28
9 files changed, 132 insertions, 147 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
index b871abfa..59c61637 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
@@ -197,17 +197,15 @@ open class DockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit
removeAt(Side.DOWN)
return this
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.dockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit)? = null): DockPanel {
- val dockPanel = DockPanel(classes, init)
- this.add(dockPanel)
- return dockPanel
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.dockPanel(classes: Set<String> = setOf(), init: (DockPanel.() -> Unit)? = null): DockPanel {
+ val dockPanel = DockPanel(classes, init)
+ this.add(dockPanel)
+ return dockPanel
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
index 010f7cba..436ade22 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
@@ -218,23 +218,21 @@ open class FlexPanel(
}
return snstyle
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.flexPanel(
- direction: FlexDir? = null, wrap: FlexWrap? = null, justify: FlexJustify? = null,
- alignItems: FlexAlignItems? = null, alignContent: FlexAlignContent? = null,
- spacing: Int? = null, classes: Set<String> = setOf(), init: (FlexPanel.() -> Unit)? = null
- ): FlexPanel {
- val flexPanel = FlexPanel(direction, wrap, justify, alignItems, alignContent, spacing, classes, init)
- this.add(flexPanel)
- return flexPanel
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.flexPanel(
+ direction: FlexDir? = null, wrap: FlexWrap? = null, justify: FlexJustify? = null,
+ alignItems: FlexAlignItems? = null, alignContent: FlexAlignContent? = null,
+ spacing: Int? = null, classes: Set<String> = setOf(), init: (FlexPanel.() -> Unit)? = null
+): FlexPanel {
+ val flexPanel = FlexPanel(direction, wrap, justify, alignItems, alignContent, spacing, classes, init)
+ this.add(flexPanel)
+ return flexPanel
}
/**
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
index 1f5efbb4..1598753b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
@@ -255,28 +255,26 @@ open class GridPanel(
}
return snstyle
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.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(), init: (GridPanel.() -> Unit)? = null
- ): GridPanel {
- val gridPanel = GridPanel(
- autoColumns, autoRows, autoFlow, templateColumns, templateRows, templateAreas,
- columnGap, rowGap, justifyItems, alignItems, justifyContent, alignContent, classes, init
- )
- this.add(gridPanel)
- return gridPanel
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.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(), init: (GridPanel.() -> Unit)? = null
+): GridPanel {
+ val gridPanel = GridPanel(
+ autoColumns, autoRows, autoFlow, templateColumns, templateRows, templateAreas,
+ columnGap, rowGap, justifyItems, alignItems, justifyContent, alignContent, classes, init
+ )
+ this.add(gridPanel)
+ return gridPanel
}
class GridWrapper(
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
index 0700e88a..ccc77b0f 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
@@ -47,24 +47,22 @@ open class HPanel(
@Suppress("LeakingThis")
init?.invoke(this)
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.hPanel(
- wrap: FlexWrap? = null,
- justify: FlexJustify? = null,
- alignItems: FlexAlignItems? = null,
- spacing: Int? = null,
- classes: Set<String> = setOf(),
- init: (HPanel.() -> Unit)? = null
- ): HPanel {
- val hpanel = HPanel(wrap, justify, alignItems, spacing, classes, init)
- this.add(hpanel)
- return hpanel
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.hPanel(
+ wrap: FlexWrap? = null,
+ justify: FlexJustify? = null,
+ alignItems: FlexAlignItems? = null,
+ spacing: Int? = null,
+ classes: Set<String> = setOf(),
+ init: (HPanel.() -> Unit)? = null
+): HPanel {
+ val hpanel = HPanel(wrap, justify, alignItems, spacing, classes, init)
+ this.add(hpanel)
+ return hpanel
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
index 7d06428a..111d4738 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
@@ -211,30 +211,29 @@ class Root : SimplePanel {
fun removeModal(modal: Widget) {
modals.remove(modal)
}
+ }
+}
- /**
- * Create new Root container based on ID
- * @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
- * @return the created Root container
- */
- fun Application.root(id: String, fixed: Boolean = false, init: Root.() -> Unit): Root {
- return Root(id, fixed, init)
- }
-
- /**
- * Create new Root container based on HTML element
- * @param element HTML element in the DOM tree
- * @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
- * @return the created Root container
- */
- fun Application.root(element: HTMLElement, fixed: Boolean = false, init: Root.() -> Unit): Root {
- return Root(element, fixed, init)
- }
+/**
+ * Create new Root container based on ID
+ * @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
+ * @return the created Root container
+ */
+fun Application.root(id: String, fixed: Boolean = false, init: Root.() -> Unit): Root {
+ return Root(id, fixed, init)
+}
- }
+/**
+ * Create new Root container based on HTML element
+ * @param element HTML element in the DOM tree
+ * @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
+ * @return the created Root container
+ */
+fun Application.root(element: HTMLElement, fixed: Boolean = false, init: Root.() -> Unit): Root {
+ return Root(element, fixed, init)
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
index 91eeda80..915fa6a7 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
@@ -101,17 +101,15 @@ open class SimplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() ->
children.forEach { it.dispose() }
removeAll()
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.simplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> Unit)? = null): SimplePanel {
- val simplePanel = SimplePanel(classes, init)
- this.add(simplePanel)
- return simplePanel
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.simplePanel(classes: Set<String> = setOf(), init: (SimplePanel.() -> Unit)? = null): SimplePanel {
+ val simplePanel = SimplePanel(classes, init)
+ this.add(simplePanel)
+ return simplePanel
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
index 8b46ae0b..c7f4b3ac 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
@@ -98,22 +98,20 @@ open class SplitPanel(
arrayOf()
}
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.splitPanel(
- direction: Direction = Direction.VERTICAL,
- classes: Set<String> = setOf(), init: (SplitPanel.() -> Unit)? = null
- ): SplitPanel {
- val splitPanel = SplitPanel(direction, classes, init)
- this.add(splitPanel)
- return splitPanel
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.splitPanel(
+ direction: Direction = Direction.VERTICAL,
+ classes: Set<String> = setOf(), init: (SplitPanel.() -> Unit)? = null
+): SplitPanel {
+ val splitPanel = SplitPanel(direction, classes, init)
+ this.add(splitPanel)
+ return splitPanel
}
internal class Splitter(private val splitPanel: SplitPanel, direction: Direction) : Tag(
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
index 37dd449b..26bfcb8c 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
@@ -118,18 +118,18 @@ open class StackPanel(
companion object {
internal var counter = 0
-
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.stackPanel(
- activateLast: Boolean = true, classes: Set<String> = setOf(), init: (StackPanel.() -> Unit)? = null
- ): StackPanel {
- val stackPanel = StackPanel(activateLast, classes, init)
- this.add(stackPanel)
- return stackPanel
- }
}
}
+
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.stackPanel(
+ activateLast: Boolean = true, classes: Set<String> = setOf(), init: (StackPanel.() -> Unit)? = null
+): StackPanel {
+ val stackPanel = StackPanel(activateLast, classes, init)
+ this.add(stackPanel)
+ return stackPanel
+}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
index eb9c138e..e5d275d4 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
@@ -46,20 +46,18 @@ open class VPanel(
@Suppress("LeakingThis")
init?.invoke(this)
}
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.vPanel(
- justify: FlexJustify? = null, alignItems: FlexAlignItems? = null, spacing: Int? = null,
- classes: Set<String> = setOf(), init: (VPanel.() -> Unit)? = null
- ): VPanel {
- val vpanel = VPanel(justify, alignItems, spacing, classes, init)
- this.add(vpanel)
- return vpanel
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Container.vPanel(
+ justify: FlexJustify? = null, alignItems: FlexAlignItems? = null, spacing: Int? = null,
+ classes: Set<String> = setOf(), init: (VPanel.() -> Unit)? = null
+): VPanel {
+ val vpanel = VPanel(justify, alignItems, spacing, classes, init)
+ this.add(vpanel)
+ return vpanel
}