Binding0

constructor(program: Program, element: Element, event: Event<E>, property: KMutableProperty0<T>, newValueFromEvent: (E) -> T, setElementValue: (T) -> Unit)(source)

Parameters

E

The type of the input event used for updating the property.

T

The data type of the property being bound.

program

The program instance managing the coroutine lifecycle for this binding.

element

The UI element associated with this binding.

event

The event to listen to for changes triggering property updates.

property

A mutable property reference to bind to the element value.

newValueFromEvent

A lambda function that converts the event of type E into a new property value of type T.

setElementValue

A lambda function that updates the element with the current property value.

This class continuously monitors changes to the bound property and the associated element:

  • When an E event is captured, it invokes newValueFromEvent to compute a new property value. If the value has changed, the property is updated, and the change is propagated to the element.

  • Concurrently, it checks for any modifications in the property value, ensuring the changes reflect back onto the UI element using setElementValue.

The binding operates until closed explicitly using the close method, or if the parent element is disposed.

Implements AutoCloseable to ensure proper cleanup of resources like coroutines and event listeners.

Properties:

  • currentValue maintains the current state of the bound property.

  • closed indicates whether the binding has been closed.

Closing the binding stops its coroutine, removes event listeners, and marks it as inactive.