Support for begin/update/end callbacks allowing state to be cached
and reused while dragging a number button or slider.
This is done using UI_block_interaction_set to set callbacks.
- Dragging multiple buttons at once is supported, passing multiple unique events into the update function.
- Update is only called once even when multiple buttons are edited.
- The update callback can detect the difference between click & drag actions so situations to support skipping cache creation and freeing for situations where it's not beneficial.
Motivation:
The initial motivation for this functionality was the speed up edit-mesh updates when dragging number buttons by caching information about the normals and face-triangulation that needs to be performed while dragging a button (as is currently done in transform code).
This can also be used to resolve T67442: Modifier re-evaluation makes editing dimensions unreliable, see reply noting that a persistent state during a drag action could resolve the problem.
Details:
Implementing this functionality ended up not being so straight-forward since multiple buttons can be edited at once and cancelling number buttons relies on uiAfterFunc, so supporting updating and freeing the cached data after the button it's self was freed needed to be supported.
Initializing the cache also needs to occur after multiple buttons have been selected (dragging vertically flags UI_BUT_DRAG_MULTI). So it's possible for the begin function to know which button events are being edited.
It's also important for this to run last, so there are checks to ensure this isn't added to uiAfterFunc multiple times.
Further Work:
There are larger refactors that I believe would be better handled as a separate patch.
- Merge uiBlockInteraction_CallbackData.update_fn into the existing uiBlock.handle_func callback.
This would involve the following changes.
Add custom_data and event array arguments to and handle_func.
Ensure handle_func is not called multiple times.
- Move block level updates into a separate list to UIAfterFuncs, so multiple buttons may be edited at once, running the block handle afterwards without the need for the logic this patch introduces that moves the handler to the last uiAfterFunc.