diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-03-20 14:40:38 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-03-20 15:10:34 +0300 |
commit | a1addc5c633d4c35eeb491c698052ec9300271dc (patch) | |
tree | 2f8cf2086db19233c3e641662f8a3cd540a5fd1e /source/blender/editors/interface | |
parent | 69fb859909c8e99a8e5e9e06607992d5b9a41473 (diff) |
UI: support for popups starting with buttons activated
While this could already be done from C,
this is now exposed to Python
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface.c | 18 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 17 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.c | 10 |
3 files changed, 44 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 1e079835ec5..16c87b7a7d7 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -823,6 +823,24 @@ bool UI_but_active_only(const bContext *C, ARegion *ar, uiBlock *block, uiBut *b return true; } +bool UI_block_active_only_flagged_buttons(const bContext *C, ARegion *ar, uiBlock *block) +{ + bool done = false; + for (uiBut *but = block->buttons.first; but; but = but->next) { + if (!done && ui_but_is_editable(but)) { + if (but->flag & UI_BUT_ACTIVATE_ON_INIT) { + if (UI_but_active_only(C, ar, block, but)) { + done = true; + } + } + } + but->flag &= ~UI_BUT_ACTIVATE_ON_INIT; + } + return done; +} + + + /* simulate button click */ void UI_but_execute(const bContext *C, uiBut *but) { diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index a828c19be54..95791dc8811 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -160,6 +160,7 @@ struct uiLayout { short space; bool align; bool active; + bool activate_init; bool enabled; bool redalert; bool keepaspect; @@ -1818,6 +1819,9 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index if (layout->redalert) UI_but_flag_enable(but, UI_BUT_REDALERT); + + if (layout->activate_init) + UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); } /* single button */ else { @@ -1831,6 +1835,9 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index if (layout->redalert) UI_but_flag_enable(but, UI_BUT_REDALERT); + + if (layout->activate_init) + UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT); } /* Mark non-embossed textfields inside a listbox. */ @@ -3949,6 +3956,11 @@ void uiLayoutSetActive(uiLayout *layout, bool active) layout->active = active; } +void uiLayoutSetActivateInit(uiLayout *layout, bool activate_init) +{ + layout->activate_init = activate_init; +} + void uiLayoutSetEnabled(uiLayout *layout, bool enabled) { layout->enabled = enabled; @@ -4019,6 +4031,11 @@ bool uiLayoutGetActive(uiLayout *layout) return layout->active; } +bool uiLayoutGetActivateInit(uiLayout *layout) +{ + return layout->activate_init; +} + bool uiLayoutGetEnabled(uiLayout *layout) { return layout->enabled; diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index d15eb7a3246..3176c7a454a 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -302,16 +302,24 @@ int UI_popover_panel_invoke( return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } + uiBlock *block = NULL; if (keep_open) { - ui_popover_panel_create(C, NULL, NULL, ui_item_paneltype_func, pt); + uiPopupBlockHandle *handle = ui_popover_panel_create(C, NULL, NULL, ui_item_paneltype_func, pt); + uiPopover *pup = handle->popup_create_vars.arg; + block = pup->block; + } else { uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x); layout = UI_popover_layout(pup); UI_paneltype_draw(C, pt, layout); UI_popover_end(C, pup, NULL); + block = pup->block; } + if (block) { + UI_block_active_only_flagged_buttons(C, CTX_wm_region(C), block); + } return OPERATOR_INTERFACE; } |