Binding0
A utility class for bi-directionally binding a property of type T to an Element, where changes in one are synchronized with the other. The binding operates on the provided Program instance's coroutine scope and listens for events of type E, which are used to update the property value.
Parameters
The type of the input event used for updating the property.
The data type of the property being bound.
The program instance managing the coroutine lifecycle for this binding.
The UI element associated with this binding.
The event to listen to for changes triggering property updates.
A mutable property reference to bind to the element value.
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:
currentValuemaintains the current state of the bound property.closedindicates whether the binding has been closed.
Closing the binding stops its coroutine, removes event listeners, and marks it as inactive.