All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.openrndr.events.Event.kt Maven / Gradle / Ivy

The newest version!
package org.openrndr.events

expect class Event(name: String = "", postpone: Boolean = false) {
    val listeners: MutableList<(T) -> Unit>

    fun trigger(message: T)
    fun deliver()

    /**
     * add an event message listener
     * @param listener a function to be invoked when an event message is received
     * @return the [listener] that was passed in
     */
    fun listen(listener: (T) -> Unit): (T) -> Unit
    fun listen(listener: Event): (T) -> Unit

    /**
     * cancel a listener
     */
    fun cancel(listener: (T) -> Unit)
    fun listenOnce(listener: (T) -> Unit)
    fun listenOnce(listener: Event)
}

/**
 * add listener to [Iterable] of [Event] entries
 */
fun  Iterable>.listen(listener: (T) -> Unit): (T) -> Unit {
    for (e in this) {
        e.listen(listener)
    }
    return listener
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy