diff options
author | Robbie Cronin <robert.cronin@uqconnect.edu.au> | 2019-06-26 12:42:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-26 12:42:55 +0800 |
commit | d20bc8739b1ad58c1222d63258f01ef9e9d34064 (patch) | |
tree | 078b87746de4a305452224de39272529def43679 /src/main/kotlin/pl | |
parent | 97d136f14f086cf457453f1c94da1ecdae835234 (diff) | |
parent | 1f5742bebbafbe20a9d7527794798db7ebe5ab98 (diff) | |
download | kvision-d20bc8739b1ad58c1222d63258f01ef9e9d34064.tar.gz kvision-d20bc8739b1ad58c1222d63258f01ef9e9d34064.tar.bz2 kvision-d20bc8739b1ad58c1222d63258f01ef9e9d34064.zip |
Merge pull request #2 from rjaros/master
pull version 0.0.37
Diffstat (limited to 'src/main/kotlin/pl')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt | 22 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index fbcd89da..414356ce 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -86,6 +86,10 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component * Determines if the current widget is draggable. */ var draggable: Boolean? by refreshOnUpdate() + /** + * Determines if the current widget is strictly bound to the DOM. + */ + var strictDOM: Boolean by refreshOnUpdate(false) protected var surroundingSpan by refreshOnUpdate(false) @@ -184,7 +188,11 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component */ private fun getSnOpt(): VNodeData { return snOpt { - if (vnkey != null) key = vnkey + if (vnkey != null) { + key = vnkey + } else if (strictDOM) { + key = hashCode().toString() + } attrs = snAttrs(getSnAttrsInternal()) style = snStyle(getSnStyleInternal()) `class` = snClasses(getSnClassInternal()) diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt index f376de5a..5fac0494 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt @@ -33,9 +33,13 @@ import pl.treksoft.kvision.utils.px * Context menu component. * * @constructor + * @param element an element to bind + * @param fixedPosition use fixed positioning * @param classes a set of CSS class names */ open class ContextMenu( + element: Widget? = null, + protected val fixedPosition: Boolean = false, classes: Set<String> = setOf(), init: (ContextMenu.() -> Unit)? = null ) : ListTag(ListType.UL, classes = classes + "dropdown-menu") { @@ -44,7 +48,7 @@ open class ContextMenu( hide() @Suppress("LeakingThis") display = Display.BLOCK - val root = Root.getLastRoot() + val root = element?.getRoot() ?: Root.getLastRoot() if (root != null) { @Suppress("LeakingThis") root.addContextMenu(this) @@ -61,22 +65,32 @@ open class ContextMenu( * @return current context menu */ open fun positionMenu(mouseEvent: MouseEvent): ContextMenu { - this.top = mouseEvent.pageY.toInt().px - this.left = mouseEvent.pageX.toInt().px + if (fixedPosition) { + this.top = DEFAULT_FIXED_POS_Y.px + this.left = DEFAULT_FIXED_POS_X.px + } else { + this.top = mouseEvent.pageY.toInt().px + this.left = mouseEvent.pageX.toInt().px + } this.show() return this } companion object { + + const val DEFAULT_FIXED_POS_X = 5 + const val DEFAULT_FIXED_POS_Y = 5 + /** * DSL builder extension function. * * It takes the same parameters as the constructor of the built component. */ fun Widget.contextMenu( + fixedPosition: Boolean = false, classes: Set<String> = setOf(), init: (ContextMenu.() -> Unit)? = null ): ContextMenu { - val contextMenu = ContextMenu(classes).apply { init?.invoke(this) } + val contextMenu = ContextMenu(this, fixedPosition, classes).apply { init?.invoke(this) } this.setContextMenu(contextMenu) return contextMenu } |