Event Builder
Event Builder is used to attach external event handlers to views. It's suitable for application-side code: you don't need to write a new view type, nor implement View, just chain bind events when creating views.
Complete method list, handler types and dispatch status see Handler API. This page only explains how to use.
Basic Writing
After importing EventBuilder, all values implementing ViewIdentity can chain bind events. Normal views, ViewBox, and values returned as impl IntoView all satisfy this condition.
Complete event callback parameters are not all the same. For example, the complete mouse click parameters are ViewId, KeyState, and MousePosition; mouse enter/leave use ViewId; keyboard events use ViewId, KeyCode, and modifier key state. Most handlers now also support omitting unused parameters. Specific signatures are listed in EventBuilder API and handler wrapper types.
When examples show different parameter counts, read them as different conversion forms for the same handler. Event Builder converts the closure, function, or method item you pass into the corresponding handler. Handlers with extra event parameters usually support four forms: full arguments, no arguments, ViewId only, and without ViewId. Mechanism details are in External Events: Mechanism Explanation and IntoEventHandler API.
Not Only Can Pass Closure
Event Builder's parameter is not "only can pass closure". Source code's method parameter is impl IntoEventHandler<On...Handler, Args>. Handler types keep the full-signature From<F> conversion, and additionally support common forms such as no arguments, ViewId only, or without ViewId. So you can pass a closure, a normal function, an associated function, or a method item.
Associated function can also be directly passed:
Generic functions or generic associated functions can also be passed, but Rust must see a function item whose type has already been determined:
Methods with instance state are usually called through a closure that captures the instance; the value passed to the builder is still an Fn matching the target signature.
Closures are suitable for writing a small amount of logic in place. Functions, method items, and generic functions are useful for reusing logic or splitting page code more clearly. As long as the final signature matches, all of these forms are valid.
Understanding the Args Generic
An event method looks like this:
Args is not a runtime event parameter, and users do not need to write it when calling the method. It is only a marker for Rust trait inference: full arguments, no arguments, ViewId only, and without ViewId match different IntoEventHandler implementations.
You only need to write this generic parameter when you accept an event handler in your own function and forward it:
Omitting Unused Parameters
If you only do not use some parameters, you can still use _ or _name to ignore them:
Now you can also reduce the parameter count directly. Common supported forms include:
The full-argument form is still available. Reduced parameters are useful when business logic does not care about the view ID, mouse position, or button state.
Mouse Events
Mouse events are usually used for click, press, release, move, enter and leave.
Regular mouse hit events' MousePosition is target view's local coordinates. Complete mouse event list see Handler API's current dispatch status.
Keyboard Events
Keyboard events are dispatched to current focus view. To let view receive view-level on_key_down / on_key_up, first let it enter focus table; focus mechanism see Focus Mechanism.
Keyboard handler returns HandleResult. Returning Handled means this key is already handled; returning Default means using default handling. Keyboard handlers can use the full arguments or omit ViewId; the complete signature is in Keyboard Events API.
Focus and Lifecycle Events
on_focus / on_blur are triggered by focus manager, second parameter is virtual focus number.
on_create is suitable for doing one-time runtime initialization after view tree creation, for example pushing focus scope for popup layer:
Lifecycle-type handler's aliases and parameters see View and Lifecycle Events API.
Feature-gated Events
Drag-drop and theme change — these kinds of events are controlled by feature. After enabling the corresponding feature, related builder methods are available. Complete explanation see Handler API.
If you're unsure whether an event is already connected to dispatch path, first see Current Dispatch Status. Tutorial page won't repeatedly maintain each method's complete status table.

