diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-15 17:07:19 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-15 17:07:19 +0200 |
commit | d270d087dab24175949a819b2ab2037d31c28b6b (patch) | |
tree | 813f1cccf863f6f7a5ceb304cd638ebad03397ad /src/main/kotlin | |
parent | 73f1022ac23ae282a236bff5c9b68029428352e7 (diff) | |
download | kvision-d270d087dab24175949a819b2ab2037d31c28b6b.tar.gz kvision-d270d087dab24175949a819b2ab2037d31c28b6b.tar.bz2 kvision-d270d087dab24175949a819b2ab2037d31c28b6b.zip |
Add new generic onClick handler extension function.
Diffstat (limited to 'src/main/kotlin')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/core/Widget.kt | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index d077415e..c0e684ba 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -27,6 +27,7 @@ import com.github.snabbdom.h import org.w3c.dom.CustomEventInit import org.w3c.dom.DragEvent import org.w3c.dom.Node +import org.w3c.dom.events.MouseEvent import pl.treksoft.jquery.JQuery import pl.treksoft.jquery.jQuery import pl.treksoft.kvision.KVManager @@ -868,6 +869,20 @@ fun Container.widget( return widget } +/** + * An extension function for defining event handlers. + */ inline fun <reified T : Widget> T.onEvent(noinline block: SnOn<T>.() -> Unit): Int { return this.setEventListener(block) } + +/** + * An extension function for defining on click event handlers. + */ +inline fun <reified T : Widget> T.onClick(noinline handler: T.(MouseEvent) -> Unit): Int { + return this.setEventListener<T> { + click = { e -> + self.handler(e) + } + } +} |