aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-02-09 01:23:34 +0100
committerRobert Jaros <rjaros@finn.pl>2018-02-09 01:23:34 +0100
commitd8779ac38742fe86d2489e47f5c8c4479ab74ba6 (patch)
treef0895c0dfc9d5452cd67facc42bffc1554b17d16 /src/main/kotlin/pl/treksoft/kvision/panel
parent70d2f14d4a34f841a3161482eec5d355cbd755f6 (diff)
downloadkvision-d8779ac38742fe86d2489e47f5c8c4479ab74ba6.tar.gz
kvision-d8779ac38742fe86d2489e47f5c8c4479ab74ba6.tar.bz2
kvision-d8779ac38742fe86d2489e47f5c8c4479ab74ba6.zip
Refactoring. API documentation.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt91
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt96
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt118
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt33
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt63
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt37
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt38
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt40
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt40
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt47
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt32
11 files changed, 597 insertions, 38 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
index e9670c1a..7f32a61c 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
@@ -1,7 +1,31 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import pl.treksoft.kvision.core.Component
+/**
+ * Dock layout directions.
+ */
enum class SIDE {
LEFT,
RIGHT,
@@ -10,17 +34,51 @@ enum class SIDE {
DOWN
}
+/**
+ * The container with dock layout (up, down, left, right and center positions).
+ *
+ * @constructor
+ * @param classes a set of CSS class names
+ */
open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = classes) {
+ /**
+ * @suppress
+ * Internal property.
+ */
protected var left: Component? = null
+ /**
+ * @suppress
+ * Internal property.
+ */
protected var center: Component? = null
+ /**
+ * @suppress
+ * Internal property.
+ */
protected var right: Component? = null
+ /**
+ * @suppress
+ * Internal property.
+ */
protected var up: Component? = null
+ /**
+ * @suppress
+ * Internal property.
+ */
protected var down: Component? = null
+ /**
+ * @suppress
+ * Internal property.
+ */
protected val mainContainer = FlexPanel(
direction = FLEXDIR.COLUMN, justify = FLEXJUSTIFY.SPACEBETWEEN,
alignItems = FLEXALIGNITEMS.STRETCH
)
+ /**
+ * @suppress
+ * Internal property.
+ */
protected val subContainer = FlexPanel(justify = FLEXJUSTIFY.SPACEBETWEEN, alignItems = FLEXALIGNITEMS.CENTER)
init {
@@ -28,33 +86,39 @@ open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = cla
mainContainer.add(subContainer, 2)
}
+ /**
+ * Adds a component to the dock container.
+ * @param child child component
+ * @param position position in the dock
+ * @return current container
+ */
@Suppress("MagicNumber")
- open fun add(widget: Component, position: SIDE): DockPanel {
+ open fun add(child: Component, position: SIDE): DockPanel {
when (position) {
SIDE.UP -> {
up?.let { mainContainer.remove(it) }
- up = widget
- mainContainer.add(widget, 1, alignSelf = FLEXALIGNITEMS.CENTER)
+ up = child
+ mainContainer.add(child, 1, alignSelf = FLEXALIGNITEMS.CENTER)
}
SIDE.CENTER -> {
center?.let { subContainer.remove(it) }
- center = widget
- subContainer.add(widget, 2)
+ center = child
+ subContainer.add(child, 2)
}
SIDE.LEFT -> {
left?.let { subContainer.remove(it) }
- left = widget
- subContainer.add(widget, 1)
+ left = child
+ subContainer.add(child, 1)
}
SIDE.RIGHT -> {
right?.let { subContainer.remove(it) }
- right = widget
- subContainer.add(widget, 3)
+ right = child
+ subContainer.add(child, 3)
}
SIDE.DOWN -> {
down?.let { mainContainer.remove(it) }
- down = widget
- mainContainer.add(widget, 3, alignSelf = FLEXALIGNITEMS.CENTER)
+ down = child
+ mainContainer.add(child, 3, alignSelf = FLEXALIGNITEMS.CENTER)
}
}
return this
@@ -78,6 +142,11 @@ open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = cla
return this
}
+ /**
+ * Removes child from given position in the dock.
+ * @param position position in the dock
+ * @return current container
+ */
open fun removeAt(position: SIDE): DockPanel {
when (position) {
SIDE.UP -> {
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
index ad3522ea..266612fe 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
@@ -1,25 +1,55 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import pl.treksoft.kvision.core.Component
+import pl.treksoft.kvision.core.StringPair
import pl.treksoft.kvision.core.StyledComponent
import pl.treksoft.kvision.core.WidgetWrapper
-import pl.treksoft.kvision.core.StringPair
import pl.treksoft.kvision.utils.px
-enum class FLEXDIR(val dir: String) {
+/**
+ * CSS flexbox directions.
+ */
+enum class FLEXDIR(internal val dir: String) {
ROW("row"),
ROWREV("row-reverse"),
COLUMN("column"),
COLUMNREV("column-reverse")
}
-enum class FLEXWRAP(val wrap: String) {
+/**
+ * CSS flexbox wrap modes.
+ */
+enum class FLEXWRAP(internal val wrap: String) {
NOWRAP("nowrap"),
WRAP("wrap"),
WRAPREV("wrap-reverse")
}
-enum class FLEXJUSTIFY(val justify: String) {
+/**
+ * CSS flexbox justification options.
+ */
+enum class FLEXJUSTIFY(internal val justify: String) {
FLEXSTART("flex-start"),
FLEXEND("flex-end"),
CENTER("center"),
@@ -28,7 +58,10 @@ enum class FLEXJUSTIFY(val justify: String) {
SPACEEVENLY("space-evenly")
}
-enum class FLEXALIGNITEMS(val alignItems: String) {
+/**
+ * CSS flexbox alignments options.
+ */
+enum class FLEXALIGNITEMS(internal val alignItems: String) {
FLEXSTART("flex-start"),
FLEXEND("flex-end"),
CENTER("center"),
@@ -36,7 +69,10 @@ enum class FLEXALIGNITEMS(val alignItems: String) {
STRETCH("stretch")
}
-enum class FLEXALIGNCONTENT(val alignContent: String) {
+/**
+ * CSS flexbox content alignment options.
+ */
+enum class FLEXALIGNCONTENT(internal val alignContent: String) {
FLEXSTART("flex-start"),
FLEXEND("flex-end"),
CENTER("center"),
@@ -45,37 +81,68 @@ enum class FLEXALIGNCONTENT(val alignContent: String) {
STRETCH("stretch")
}
+/**
+ * The container with CSS flexbox layout support.
+ *
+ * @constructor
+ * @param direction flexbox direction
+ * @param wrap flexbox wrap
+ * @param justify flexbox content justification
+ * @param alignItems flexbox items alignment
+ * @param alignContent flexbox content alignment
+ * @param spacing spacing between columns/rows
+ * @param classes a set of CSS class names
+ */
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()
) : SimplePanel(classes) {
+
+ /**
+ * CSS flexbox direction.
+ */
var direction = direction
set(value) {
field = value
refreshSpacing()
refresh()
}
+ /**
+ * CSS flexbox wrap mode.
+ */
var wrap = wrap
set(value) {
field = value
refresh()
}
+ /**
+ * CSS flexbox content justification.
+ */
var justify = justify
set(value) {
field = value
refresh()
}
+ /**
+ * CSS flexbox items alignment.
+ */
var alignItems = alignItems
set(value) {
field = value
refresh()
}
+ /**
+ * CSS flexbox content alignment.
+ */
var alignContent = alignContent
set(value) {
field = value
refresh()
}
+ /**
+ * The spacing between columns/rows.
+ */
var spacing = spacing
set(value) {
field = value
@@ -83,6 +150,16 @@ open class FlexPanel(
refresh()
}
+ /**
+ * Adds a component to the flexbox container.
+ * @param child child component
+ * @param order child flexbox ordering
+ * @param grow child flexbox grow
+ * @param shrink child flexbox shrink
+ * @param basis child flexbox basis
+ * @param alignSelf child self alignment
+ * @param classes a set of CSS class names
+ */
@Suppress("LongParameterList")
fun add(
child: Component, order: Int? = null, grow: Int? = null, shrink: Int? = null,
@@ -123,7 +200,7 @@ open class FlexPanel(
}
override fun remove(child: Component): FlexPanel {
- children.find { (it as FlexWrapper).delegate == child }?.let {
+ children.find { (it as FlexWrapper).wrapped == child }?.let {
super.remove(it)
it.dispose()
}
@@ -162,7 +239,10 @@ open class FlexPanel(
}
}
-class FlexWrapper(
+/**
+ * Helper class form CSS flexbox layout.
+ */
+internal class FlexWrapper(
delegate: Component, private val order: Int? = null, private val grow: Int? = null,
private val shrink: Int? = null, private val basis: Int? = null,
private val alignSelf: FLEXALIGNITEMS? = null,
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
index 549f7631..b6f1d3a5 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
@@ -1,24 +1,54 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import pl.treksoft.kvision.core.Component
-import pl.treksoft.kvision.core.WidgetWrapper
import pl.treksoft.kvision.core.StringPair
+import pl.treksoft.kvision.core.WidgetWrapper
-enum class GRIDJUSTIFY(val justify: String) {
+/**
+ * CSS grid justification options.
+ */
+enum class GRIDJUSTIFY(internal val justify: String) {
START("start"),
END("end"),
CENTER("center"),
STRETCH("stretch")
}
-enum class GRIDALIGN(val align: String) {
+/**
+ * CSS grid alignment options.
+ */
+enum class GRIDALIGN(internal val align: String) {
START("start"),
END("end"),
CENTER("center"),
STRETCH("stretch")
}
-enum class GRIDJUSTIFYCONTENT(val justifyContent: String) {
+/**
+ * CSS grid content justification options.
+ */
+enum class GRIDJUSTIFYCONTENT(internal val justifyContent: String) {
START("start"),
END("end"),
CENTER("center"),
@@ -28,7 +58,10 @@ enum class GRIDJUSTIFYCONTENT(val justifyContent: String) {
SPACEEVENLY("space-evenly")
}
-enum class GRIDALIGNCONTENT(val alignContent: String) {
+/**
+ * CSS grid content alignment options.
+ */
+enum class GRIDALIGNCONTENT(internal val alignContent: String) {
START("start"),
END("end"),
CENTER("center"),
@@ -38,13 +71,34 @@ enum class GRIDALIGNCONTENT(val alignContent: String) {
SPACEEVENLY("space-evenly")
}
-enum class GRIDFLOW(val flow: String) {
+/**
+ * CSS grid flow options.
+ */
+enum class GRIDFLOW(internal val flow: String) {
ROW("row"),
COLUMN("column"),
ROWDENSE("row dense"),
COLUMNDENSE("column dense")
}
+/**
+ * The container with CSS grid layout support.
+ *
+ * @constructor
+ * @param autoColumns grid auto columns
+ * @param autoRows grid auto rows
+ * @param autoFlow grid auto flow
+ * @param templateColumns grid columns template
+ * @param templateRows grid rows template
+ * @param templateAreas grid areas template
+ * @param columnGap grid column gap
+ * @param rowGap grid row gap
+ * @param justifyItems grid items justification
+ * @param alignItems grid items alignment
+ * @param justifyContent flexbox content justification
+ * @param alignContent flexbox content alignment
+ * @param classes a set of CSS class names
+ */
open class GridPanel(
autoColumns: String? = null, autoRows: String? = null, autoFlow: GRIDFLOW? = null,
templateColumns: String? = null, templateRows: String? = null, templateAreas: List<String>? = null,
@@ -52,67 +106,117 @@ open class GridPanel(
alignItems: GRIDALIGN? = null, justifyContent: GRIDJUSTIFYCONTENT? = null,
alignContent: GRIDALIGNCONTENT? = null, classes: Set<String> = setOf()
) : SimplePanel(classes) {
+
+ /**
+ * CSS grid auto columns.
+ */
var autoColumns = autoColumns
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid auto rows.
+ */
var autoRows = autoRows
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid auto flow.
+ */
var autoFlow = autoFlow
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid columns template.
+ */
var templateColumns = templateColumns
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid rows template.
+ */
var templateRows = templateRows
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid areas template.
+ */
var templateAreas = templateAreas
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid column gap.
+ */
var columnGap = columnGap
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid row gap.
+ */
var rowGap = rowGap
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid items justification.
+ */
var justifyItems = justifyItems
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid items alignment.
+ */
var alignItems = alignItems
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid content justification.
+ */
var justifyContent = justifyContent
set(value) {
field = value
refresh()
}
+ /**
+ * CSS grid content alignment.
+ */
var alignContent = alignContent
set(value) {
field = value
refresh()
}
+ /**
+ * Adds a component to the grid container.
+ * @param child child component
+ * @param columnStart number of starting column
+ * @param rowStart number of starting row
+ * @param columnEnd number of ending column
+ * @param rowEnd number of ending row
+ * @param area grid area
+ * @param justifySelf child self justification
+ * @param alignSelf child self alignment
+ * @param classes a set of CSS class names
+ * @return current container
+ */
@Suppress("LongParameterList")
fun add(
child: Component, columnStart: Int? = null, rowStart: Int? = null,
@@ -133,7 +237,7 @@ open class GridPanel(
}
override fun remove(child: Component): GridPanel {
- children.find { (it as GridWrapper).delegate == child }?.let {
+ children.find { (it as GridWrapper).wrapped == child }?.let {
super.remove(it)
it.dispose()
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
index 841985ba..7639ca3b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
@@ -1,5 +1,38 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
+/**
+ * The container with horizontal layout.
+ *
+ * This is a special case of the flexbox layout.
+ *
+ * @constructor
+ * @param wrap flexbox wrap
+ * @param justify flexbox content justification
+ * @param alignItems flexbox items alignment
+ * @param spacing spacing between columns/rows
+ * @param classes a set of CSS class names
+ */
open class HPanel(
wrap: FLEXWRAP? = null, justify: FLEXJUSTIFY? = null, alignItems: FLEXALIGNITEMS? = null, spacing: Int? = null,
classes: Set<String> = setOf()
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
index f4630298..93588617 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import pl.treksoft.kvision.core.Component
@@ -6,31 +27,57 @@ import pl.treksoft.kvision.html.ALIGN
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
-enum class GRIDSIZE(val size: String) {
+/**
+ * Bootstrap grid sizes.
+ */
+enum class GRIDSIZE(internal val size: String) {
XS("xs"),
SM("sm"),
MD("md"),
LG("lg")
}
-const val MAX_COLUMNS = 12
+internal const val MAX_COLUMNS = 12
internal data class WidgetParam(val widget: Component, val size: Int, val offset: Int)
+/**
+ * The container with support for Bootstrap responsive grid layout.
+ *
+ * @constructor
+ * @param gridsize grid size
+ * @param rows number of rows
+ * @param cols number of columns
+ * @param align text align of grid cells
+ * @param classes a set of CSS class names
+ */
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()
) : SimplePanel(classes) {
- protected var align = align
+
+ /**
+ * Text align of grid cells.
+ */
+ var align = align
set(value) {
field = value
- refresh()
+ refreshRowContainers()
}
internal val map = mutableMapOf<Int, MutableMap<Int, WidgetParam>>()
private var auto: Boolean = true
+ /**
+ * Adds child component to the grid.
+ * @param child child component
+ * @param col column number
+ * @param row row number
+ * @param size cell size (colspan)
+ * @param offset cell offset
+ * @return this container
+ */
open fun add(child: Component, col: Int, row: Int, size: Int = 0, offset: Int = 0): ResponsiveGridPanel {
val cRow = if (row < 0) 0 else row
val cCol = if (col < 0) 0 else col
@@ -68,6 +115,12 @@ open class ResponsiveGridPanel(
return this
}
+ /**
+ * Removes child component at given location (column, row).
+ * @param col column number
+ * @param row row number
+ * @return this container
+ */
open fun removeAt(col: Int, row: Int): ResponsiveGridPanel {
map[row]?.remove(col)
refreshRowContainers()
@@ -75,7 +128,7 @@ open class ResponsiveGridPanel(
}
@Suppress("ComplexMethod", "NestedBlockDepth")
- protected open fun refreshRowContainers() {
+ private fun refreshRowContainers() {
singleRender {
clearRowContainers()
val num = MAX_COLUMNS / cols
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
index 88634bea..e10fdc86 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
@@ -1,10 +1,43 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
import pl.treksoft.kvision.KVManager
-import pl.treksoft.kvision.modal.Modal
import pl.treksoft.kvision.core.StringBoolPair
+import pl.treksoft.kvision.modal.Modal
+/**
+ * Root container.
+ *
+ * This container is bound to the specific element in the main HTML file of the project.
+ * It is always the root of components tree and it is responsible for rendering and updating
+ * Snabbdom virtual DOM.
+ *
+ * @constructor
+ * @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)
+ */
class Root(id: String, private val fixed: Boolean = false) : SimplePanel() {
private val modals: MutableList<Modal> = mutableListOf()
private var rootVnode: VNode = renderVNode()
@@ -18,7 +51,7 @@ class Root(id: String, private val fixed: Boolean = false) : SimplePanel() {
}
override fun render(): VNode {
- return kvh("div#" + id, childrenVNodes() + modalsVNodes())
+ return render("div#" + id, childrenVNodes() + modalsVNodes())
}
internal fun addModal(modal: Modal) {
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
index 51c42a06..b210f2cb 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
@@ -5,17 +26,32 @@ import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.Widget
+/**
+ * Basic container class, rendered as a DIV element with all children directly within.
+ *
+ * @constructor
+ * @param classes a set of CSS class names
+ */
open class SimplePanel(classes: Set<String> = setOf()) : Widget(classes), Container {
internal val children: MutableList<Component> = mutableListOf()
override fun render(): VNode {
- return kvh("div", childrenVNodes())
+ return render("div", childrenVNodes())
}
+ /**
+ * Returns the array of the children Snabbdom vnodes.
+ * @return array of children vnodes
+ */
protected open fun childrenVNodes(): Array<VNode> {
return children.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
}
+ /**
+ * Protected and final method to add given component to the current container.
+ * @param child child component
+ * @return current container
+ */
protected fun addInternal(child: Component): SimplePanel {
children.add(child)
child.parent = this
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
index 10595a37..cfeadd58 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
@@ -9,11 +30,24 @@ import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
import pl.treksoft.kvision.utils.obj
-enum class DIRECTION(val dir: String) {
+/**
+ * Split panel direction.
+ */
+enum class DIRECTION(internal val dir: String) {
HORIZONTAL("horizontal"),
VERTICAL("vertical")
}
+/**
+ * The container with draggable splitter.
+ *
+ * It is required to have exactly two children, for both sides of the splitter. Otherwise it will be
+ * rendered as empty.
+ *
+ * @constructor
+ * @param direction direction of the splitter
+ * @param classes a set of CSS class names
+ */
open class SplitPanel(
private val direction: DIRECTION = DIRECTION.VERTICAL,
classes: Set<String> = setOf()
@@ -59,7 +93,7 @@ open class SplitPanel(
}
}
-class Splitter(private val splitPanel: SplitPanel, direction: DIRECTION) : Tag(
+internal class Splitter(private val splitPanel: SplitPanel, direction: DIRECTION) : Tag(
TAG.DIV,
classes = setOf("splitter-" + direction.dir)
) {
@@ -75,6 +109,6 @@ class Splitter(private val splitPanel: SplitPanel, direction: DIRECTION) : Tag(
}
companion object {
- var counter = 0
+ internal var counter = 0
}
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
index e69cc416..672c8690 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
@@ -1,13 +1,47 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.routing.routing
+/**
+ * The container with only one active (visible) child at any moment.
+ *
+ * It supports activating children by a JavaScript route.
+ *
+ * @constructor
+ * @param activateLast determines if added component is automatically activated (default true)
+ * @param classes a set of CSS class names
+ */
open class StackPanel(
private val activateLast: Boolean = true,
classes: Set<String> = setOf()
) : SimplePanel(classes) {
+
+ /**
+ * The index of active (visible) child.
+ */
var activeIndex = -1
set(value) {
field = value
@@ -22,6 +56,12 @@ open class StackPanel(
}
}
+ /**
+ * Adds given component and bounds it's activation to a given route.
+ * @param panel child component
+ * @param route JavaScript route to activate given child
+ * @return current container
+ */
open fun add(panel: Component, route: String): StackPanel {
add(panel)
val currentIndex = children.size - 1
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
index 411c4a57..9072d261 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
@@ -1,3 +1,24 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
import pl.treksoft.kvision.core.Component
@@ -7,7 +28,19 @@ import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
import pl.treksoft.kvision.routing.routing
-open class TabPanel : SimplePanel(setOf()) {
+/**
+ * The container rendering it's children as tabs.
+ *
+ * It supports activating children by a JavaScript route.
+ *
+ * @constructor
+ * @param classes a set of CSS class names
+ */
+open class TabPanel(classes: Set<String> = setOf()) : SimplePanel(classes) {
+
+ /**
+ * The index of active (visible) tab.
+ */
var activeIndex
get() = content.activeIndex
set(value) {
@@ -30,6 +63,15 @@ open class TabPanel : SimplePanel(setOf()) {
this.addInternal(content)
}
+ /**
+ * Adds new tab and optionally bounds it's activation to a given route.
+ * @param title title of the tab
+ * @param panel child component
+ * @param icon icon of the tab
+ * @param image image of the tab
+ * @param route JavaScript route to activate given child
+ * @return current container
+ */
open fun addTab(
title: String, panel: Component, icon: String? = null,
image: ResString? = null, route: String? = null
@@ -59,6 +101,9 @@ open class TabPanel : SimplePanel(setOf()) {
return this
}
+ /**
+ * Removes tab at given index.
+ */
open fun removeTab(index: Int): TabPanel {
nav.remove(nav.children[index])
content.remove(content.children[index])
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
index 7870b67a..91ee4a6a 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/VPanel.kt
@@ -1,5 +1,37 @@
+/*
+ * Copyright (c) 2017-present Robert Jaros
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
package pl.treksoft.kvision.panel
+/**
+ * The container with vertical layout.
+ *
+ * This is a special case of the flexbox layout.
+ *
+ * @constructor
+ * @param justify flexbox content justification
+ * @param alignItems flexbox items alignment
+ * @param spacing spacing between columns/rows
+ * @param classes a set of CSS class names
+ */
open class VPanel(
justify: FLEXJUSTIFY? = null, alignItems: FLEXALIGNITEMS? = null, spacing: Int? = null,
classes: Set<String> = setOf()