Commit: a14005c070a1f3b7a1ed2013c61a359e816734fa
Author: Brecht Van Lommel
Date:   Fri Apr 27 19:30:25 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBa14005c070a1f3b7a1ed2013c61a359e816734fa

UI: fix popover menus not refreshing when changing settings.

===================================================================

M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface_handlers.c
M       source/blender/editors/interface/interface_intern.h
M       source/blender/editors/interface/interface_region_popover.c
M       source/blender/editors/interface/interface_region_popup.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index 968007f42f7..9f41f9175c4 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -422,10 +422,7 @@ void UI_popup_menu_but_set(uiPopupMenu *pup, struct 
ARegion *butregion, uiBut *b
 
 typedef struct uiPopover uiPopover;
 
-uiPopover *UI_popover_begin(
-        struct bContext *C) ATTR_NONNULL();
-uiPopover *UI_popover_begin_ex(
-        struct bContext *C, const char *block_name) ATTR_NONNULL();
+uiPopover *UI_popover_begin(struct bContext *C) ATTR_NONNULL();
 void UI_popover_end(struct bContext *C, struct uiPopover *head);
 struct uiLayout *UI_popover_layout(uiPopover *head);
 
diff --git a/source/blender/editors/interface/interface_handlers.c 
b/source/blender/editors/interface/interface_handlers.c
index 2c477b92885..9245fa2007d 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -635,11 +635,8 @@ PointerRNA 
*ui_handle_afterfunc_add_operator(wmOperatorType *ot, int opcontext,
 
 static void popup_check(bContext *C, wmOperator *op)
 {
-       if (op && op->type->check && op->type->check(C, op)) {
-               /* check for popup and re-layout buttons */
-               ARegion *ar_menu = CTX_wm_menu(C);
-               if (ar_menu)
-                       ED_region_tag_refresh_ui(ar_menu);
+       if (op && op->type->check) {
+               op->type->check(C, op);
        }
 }
 
@@ -779,7 +776,7 @@ static void ui_apply_but_funcs_after(bContext *C)
 
                if (after.popup_op)
                        popup_check(C, after.popup_op);
-               
+
                if (after.opptr) {
                        /* free in advance to avoid leak on exit */
                        opptr = *after.opptr;
@@ -7936,8 +7933,9 @@ static void button_activate_exit(
                WM_cursor_modal_restore(data->window);
        }
 
-       /* redraw (data is but->active!) */
+       /* redraw and refresh (for popups) */
        ED_region_tag_redraw(data->region);
+       ED_region_tag_refresh_ui(data->region);
 
        /* clean up button */
        if (but->active) {
@@ -8589,13 +8587,8 @@ static int ui_handle_list_event(bContext *C, const 
wmEvent *event, ARegion *ar,
        }
 
        if (redraw) {
-               if (listbox->block->flag & UI_BLOCK_POPUP) {
-                       /* popups need special refreshing */
-                       ED_region_tag_refresh_ui(ar);
-               }
-               else {
-                       ED_region_tag_redraw(ar);
-               }
+               ED_region_tag_redraw(ar);
+               ED_region_tag_refresh_ui(ar);
        }
 
        return retval;
diff --git a/source/blender/editors/interface/interface_intern.h 
b/source/blender/editors/interface/interface_intern.h
index 8353a17a359..6082b3ab7b0 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -519,16 +519,19 @@ struct uiKeyNavLock {
 };
 
 typedef uiBlock * (*uiBlockHandleCreateFunc)(struct bContext *C, struct 
uiPopupBlockHandle *handle, void *arg1);
+typedef void (*uiBlockHandleFreeFunc)(struct uiPopupBlockHandle *handle, void 
*arg1);
 
 struct uiPopupBlockCreate {
-       uiBlockCreateFunc              create_func;
+       uiBlockCreateFunc       create_func;
        uiBlockHandleCreateFunc handle_create_func;
+       uiBlockHandleFreeFunc   free_func;
        void *arg;
 
        int event_xy[2];
 
        /* when popup is initialized from a button */
        ARegion *butregion;
+       uiBut *but;
 };
 
 struct uiPopupBlockHandle {
diff --git a/source/blender/editors/interface/interface_region_popover.c 
b/source/blender/editors/interface/interface_region_popover.c
index bf75af524b7..ea8c4d9ddce 100644
--- a/source/blender/editors/interface/interface_region_popover.c
+++ b/source/blender/editors/interface/interface_region_popover.c
@@ -74,121 +74,115 @@ struct uiPopover {
        uiBlock *block;
        uiLayout *layout;
        uiBut *but;
-       ARegion *butregion;
-
-       int mx, my;
-       bool popover, slideout;
 
        uiMenuCreateFunc menu_func;
        void *menu_arg;
 };
 
-static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, 
void *arg_pup)
+static void ui_popover_create_block(bContext *C, uiPopover *pup, int opcontext)
 {
-       uiBlock *block;
-       uiPopover *pup = arg_pup;
-       int minwidth, width, height;
+       uiStyle *style = UI_style_get_dpi();
 
-       if (pup->menu_func) {
-               pup->block->handle = handle;
-               pup->menu_func(C, pup->layout, pup->menu_arg);
-               pup->block->handle = NULL;
-       }
+       pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS);
+       pup->layout = UI_block_layout(
+               pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0,
+               U.widget_unit * UI_POPOVER_WIDTH_UNITS, 0, MENU_PADDING, style);
+
+       uiLayoutSetOperatorContext(pup->layout, opcontext);
 
        if (pup->but) {
-               /* minimum width to enforece */
-               minwidth = BLI_rctf_size_x(&pup->but->rect);
+               if (pup->but->context) {
+                       uiLayoutContextCopy(pup->layout, pup->but->context);
+               }
        }
        else {
-               minwidth = UI_MENU_WIDTH_MIN;
+               /* Some enums reversing is strange, currently we have no good 
way to
+                * reverse some enum's but not others, so reverse all so the 
first menu
+                * items are always close to the mouse cursor. */
+               pup->block->flag |= UI_BLOCK_NO_FLIP;
        }
+}
 
-       block = pup->block;
+static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, 
void *arg_pup)
+{
+       uiPopover *pup = arg_pup;
 
-       /* in some cases we create the block before the region,
-        * so we set it delayed here if necessary */
-       if (BLI_findindex(&handle->region->uiblocks, block) == -1)
-               UI_block_region_set(block, handle->region);
+       /* Create UI block and layout now if it wasn't done between begin/end. 
*/
+       if (!pup->layout) {
+               ui_popover_create_block(C, pup, WM_OP_INVOKE_REGION_WIN);
 
-       UI_block_layout_resolve(block, &width, &height);
+               if (pup->menu_func) {
+                       pup->block->handle = handle;
+                       pup->menu_func(C, pup->layout, pup->menu_arg);
+                       pup->block->handle = NULL;
+               }
 
-       UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | 
UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER);
+               pup->layout = NULL;
+       }
+
+       /* Setup and resolve UI layout for block. */
+       uiBlock *block = pup->block;
+       int width, height;
 
+       UI_block_region_set(block, handle->region);
+       UI_block_layout_resolve(block, &width, &height);
+       UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | 
UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER);
        UI_block_direction_set(block, UI_DIR_DOWN | UI_DIR_CENTER_X);
 
        const int block_margin = U.widget_unit / 2;
 
-       if (pup->popover) {
+       if (pup->but) {
+               /* For a header menu we set the direction automatic. */
+               block->minbounds = BLI_rctf_size_x(&pup->but->rect);
+               UI_block_bounds_set_normal(block, block_margin);
+
+               /* If menu slides out of other menu, override direction. */
+               bool slideout = false; //ui_block_is_menu(pup->but->block);
+               if (slideout)
+                       UI_block_direction_set(block, UI_DIR_RIGHT);
+       }
+       else {
+               /* Not attached to a button. */
                int offset[2] = {0, 0};  /* Dummy. */
                UI_block_flag_enable(block, UI_BLOCK_LOOP);
                UI_block_direction_set(block, block->direction);
-               block->minbounds = minwidth;
+               block->minbounds = UI_MENU_WIDTH_MIN;
                UI_block_bounds_set_popup(block, block_margin, offset[0], 
offset[1]);
        }
-       else {
-               /* for a header menu we set the direction automatic */
-               block->minbounds = minwidth;
-               UI_block_bounds_set_normal(block, block_margin);
-       }
 
-       /* if menu slides out of other menu, override direction */
-       if (pup->slideout)
-               UI_block_direction_set(block, UI_DIR_RIGHT);
+       return block;
+}
 
-       return pup->block;
+static void ui_block_free_func_POPOVER(uiPopupBlockHandle *UNUSED(handle), 
void *arg_pup)
+{
+       uiPopover *pup = arg_pup;
+       MEM_freeN(pup);
 }
 
 uiPopupBlockHandle *ui_popover_panel_create(
         bContext *C, ARegion *butregion, uiBut *but,
         uiMenuCreateFunc menu_func, void *arg)
 {
-       wmWindow *window = CTX_wm_window(C);
-       uiStyle *style = UI_style_get_dpi();
-       uiPopupBlockHandle *handle;
-       uiPopover *pup;
-
-       pup = MEM_callocN(sizeof(uiPopover), __func__);
-       pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS);
-       UI_block_emboss_set(pup->block, UI_EMBOSS);
-       pup->layout = UI_block_layout(
-               pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0,
-               U.widget_unit * UI_POPOVER_WIDTH_UNITS, 0, MENU_PADDING, style);
-       pup->slideout = false; // but ? ui_block_is_menu(but->block) : false;
+       /* Create popover, buttons are created from callback. */
+       uiPopover *pup = MEM_callocN(sizeof(uiPopover), __func__);
        pup->but = but;
-       uiLayoutSetOperatorContext(pup->layout, WM_OP_INVOKE_REGION_WIN);
-
-       if (!but) {
-               /* no button to start from, means we are a popover */
-               pup->mx = window->eventstate->x;
-               pup->my = window->eventstate->y;
-               pup->popover = true;
-               pup->block->flag |= UI_BLOCK_NO_FLIP;
-       }
-       /* some enums reversing is strange, currently we have no good way to
-        * reverse some enum's but not others, so reverse all so the first menu
-        * items are always close to the mouse cursor */
-       else {
-               if (but->context) {
-                       uiLayoutContextCopy(pup->layout, but->context);
-               }
-       }
-
-       /* menu is created from a callback */
        pup->menu_func = menu_func;
        pup->menu_arg = arg;
 
+       /* Create popup block. */
+       uiPopupBlockHandle *handle;
        handle = ui_popup_block_create(C, butregion, but, NULL, 
ui_block_func_POPOVER, pup);
+       handle->popup_create_vars.free_func = ui_block_free_func_POPOVER;
 
+       /* Add handlers. If attached to a button, the button will already
+        * add a modal handler and pass on events. */
        if (!but) {
-               handle->popup = true;
-
+               wmWindow *window = CTX_wm_window(C);
                UI_popup_handlers_add(C, &window->modalhandlers, handle, 0);
                WM_event_add_mousemove(C);
+               handle->popup = true;
        }
 
-       handle->can_refresh = false;
-       MEM_freeN(pup);
-
        return handle;
 }
 
@@ -200,20 +194,13 @@ uiPopupBlockHandle *ui_popover_panel_create(
 
 /**
  * Only return handler, and set optional title.
- * \param block_name: Assigned to uiBlock.name (useful info for debugging).
  */
-uiPopover *UI_popover_begin_ex(bContext *C, const char *block_name)
+uiPopover *UI_popover_begin(bContext *C)
 {
-       uiStyle *style = UI_style_get_dpi();
        uiPopover *pup = MEM_callocN(sizeof(uiPopover), "popover menu");
 
-       pup->block = UI_block_begin(C, NULL, block_name, UI_EMBOSS);
-       pup->layout = UI_block_layout(
-               pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0,
-               U.widget_unit * UI_POPOVER_WIDTH_UNITS, 0, MENU_PADDING, style);
-
-       /* Copied 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to