aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt91
1 files changed, 80 insertions, 11 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 -> {