Events of View
When interacting with the application, various events arise: clicks, resizing, changing input data, etc.
Event listeners are designed to respond to events. A listener is a function that is called every time an event occurs.Each event can have multiple listeners. Let's analyze the listeners using the example of the "edit-text-changed"text change event in the "EditView" editor.
The event listener is a function of the form
func([, ])
where the first argument is the View in which the event occurred. Further there are additional parameters of the event.
For "edit-text-changed", the main listener will look like this:
func(EditView, string)
where the second argument is the new text value
If you do not plan to use the first argument, you can omit it. This will be an additional listener
func(string)
In order to assign a listener, you must assign it to a property with the event name
view.Set(rui.EditTextChanged, func(edit EditView, newText string) { // do something })
or
view.Set(rui.EditTextChanged, func(newText string) { // do something })
Each event can have multiple listeners. In this regard, five data types can be used as listeners:
- func(< View >[, < parameters >])
- func([< parameters>])
- []func(< View >[, < parameters >])
- []func([< parameters >])
- []any which only contains func(< View >[, < parameters >]) and func([< parameters >])
After being assigned to a property, all these types are converted to an array of []func(< View >, [< parameters >]).Accordingly, the Get function always returns an array of []func(< View >, [< parameters >]).If there are no listeners, this array will be empty.
For the "edit-text-changed" event, this
- func(editor EditView, newText string)
- func(newText string)
- []func(editor EditView, newText string)
- []func(newText string)
- []any содержащий только func(editor EditView, newText string) и func(newText string)
And the "edit-text-changed" property always stores and returns []func(EditView, string).
In what follows, when describing specific events, only the format of the main listener will be presented.