diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-06-23 02:18:06 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-06-23 02:18:06 +0200 |
commit | 1fb687a051d37d6d13bfdcc8f84e6cf1165cadc7 (patch) | |
tree | 7dfb8964926f37654f26ce2d6b0f98673365fb67 /src/main/kotlin/pl/treksoft/kvision/dropdown | |
parent | 0c647a465b708829166010218fe0ae61f01de934 (diff) | |
download | kvision-1fb687a051d37d6d13bfdcc8f84e6cf1165cadc7.tar.gz kvision-1fb687a051d37d6d13bfdcc8f84e6cf1165cadc7.tar.bz2 kvision-1fb687a051d37d6d13bfdcc8f84e6cf1165cadc7.zip |
Fixed positioning of the context menu for use inside a Tabulator component.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/dropdown')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt index f376de5a..c09737f2 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,8 +65,13 @@ 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 = 5.px + this.left = 5.px + } else { + this.top = mouseEvent.pageY.toInt().px + this.left = mouseEvent.pageX.toInt().px + } this.show() return this } @@ -74,9 +83,10 @@ open class ContextMenu( * 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 } |