Motivation
Currently theres the buttons in a popup are fixed, once the popup is made, theres no way to modify the buttons based on changed state.
This is ok for menu's, but for Operator-redo popup (or similar popups for the operator UI), this can be quite annoying.
For example, some buttons may show, depending on other options. Options may become inactive.
This works in the toolbar for operators, but not in popups.
This patch adds the ability for popups to re-initialize so the UI can be dynamic.
note:
(The color picker works around this by hiding buttons, so it doesn't need to redraw the UI)
note:
This patch changes editmesh_tools.c, only so you can easily test the change.
Testing
To test the patch:
- Add 2 shape keys to the default cube.
- enter editmode
- Spacebar "Blend from shape"
- Press F6 (to open popup)
- Press Add,
Notice the Blend button toggles on and off This serves no purpose, its just an example
Implementation details
- RGN_DRAW_REFRESH_UI is added to tag regions to refresh their buttons.
- Each regions draw functions is responsible for handling & clearing this flag.
- ED_region_tag_refresh_ui sets RGN_DRAW_REFRESH_UI
- Currently this flag only makes sense for popups, but it could be used elsewhere later.
- Some low level functions had to be split-out, because the old-new button comparisons must be delayed until after the popups buttons have been relocated.
- uiBlockUpdateFromOld has been split from uiEndBlock into its own function.
- callbacks to ui_popup_block_create can't run uiEndBlock because any old-buttons aren't relocated to the popup's position.
Concerns
- RGN_DRAW_REFRESH_UI may not be the best way to tag the UI for updating, I did attempt to do this as a callback (but this ended up being more complicated since each popup handler then needed some way to flag the UI to redraw). Nevertheless this could be done differently.
- Up until now we rely on ED_region_do_draw to call uiFreeInactiveBlocks, but I couldn't find a way to enforce updating the UI, without a manual call here. This also involves clearing block->oldblock, and running uiBlockUpdateFromOld explicitly, am not so happy about this.
- The mouse location when first opening the popup needs to be stored and used when refreshing, because popup layout functions use. This isnt great either, to avoid we'd need to pass mouse xy coords to uiEndBlock