[Bf-blender-cvs] [cb6234fccf7] master: Property Search: Set panel expansion when tab changes

Hans Goudey noreply at git.blender.org
Sat Oct 3 18:25:58 CEST 2020


Commit: cb6234fccf7dfd3e09555cac18357427d802be1d
Author: Hans Goudey
Date:   Sat Oct 3 11:25:13 2020 -0500
Branches: master
https://developer.blender.org/rBcb6234fccf7dfd3e09555cac18357427d802be1d

Property Search: Set panel expansion when tab changes

This commit makes the panel expansion set based on the search results
when the active tab in the properties editor changes. The multi-tab
search patch (D8859) actually doesn't handle this because it uses a
different code path.

This feature uncovered a subtle but fairly significant issue with the
implementation of property search (More details in T81113). Basically,
the search needed multiple redraws to properly display the expansion of
panels based on the search results. Because there is no animation of
panel expansion when switching tabs, the problem was exposed only now.

With this commit, hiding of "search only" buttons and panel size
calculation happens in a single final step of the panel layout pass.
The "search only" layout root flag is removed. Instead every button
inside a panel header is in a single "uiButtonGroup" marked with a
specific "in header" flag, an idea which could be generalized in the
future.

Differential Revision: https://developer.blender.org/D9006

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_button_group.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/screen/area.c
M	source/blender/makesdna/DNA_screen_types.h

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 972c741f061..cac18d81f56 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1683,14 +1683,15 @@ struct Panel *UI_panel_begin(struct ARegion *region,
                              struct PanelType *pt,
                              struct Panel *panel,
                              bool *r_open);
-void UI_panel_end(const struct ARegion *region, uiBlock *block, int width, int height, bool open);
+void UI_panel_header_buttons_begin(struct Panel *panel);
+void UI_panel_header_buttons_end(struct Panel *panel);
+void UI_panel_end(struct Panel *panel, int width, int height);
 
 bool UI_panel_is_active(const struct Panel *panel);
 void UI_panel_label_offset(struct uiBlock *block, int *r_x, int *r_y);
 int UI_panel_size_y(const struct Panel *panel);
 bool UI_panel_is_dragging(const struct Panel *panel);
 bool UI_panel_matches_search_filter(const struct Panel *panel);
-void UI_panels_set_expansion_from_seach_filter(const struct bContext *C, struct ARegion *region);
 
 bool UI_panel_category_is_visible(const struct ARegion *region);
 void UI_panel_category_add(struct ARegion *region, const char *name);
@@ -1922,7 +1923,6 @@ float uiLayoutGetUnitsY(uiLayout *layout);
 int uiLayoutGetEmboss(uiLayout *layout);
 bool uiLayoutGetPropSep(uiLayout *layout);
 bool uiLayoutGetPropDecorate(uiLayout *layout);
-void uiLayoutRootSetSearchOnly(uiLayout *layout, bool search_only);
 
 /* layout specifiers */
 uiLayout *uiLayoutRow(uiLayout *layout, bool align);
diff --git a/source/blender/editors/interface/interface_button_group.c b/source/blender/editors/interface/interface_button_group.c
index 455a3c6a69c..1f544831982 100644
--- a/source/blender/editors/interface/interface_button_group.c
+++ b/source/blender/editors/interface/interface_button_group.c
@@ -32,17 +32,26 @@
  * Every function that adds a set of buttons must create another group,
  * then #ui_def_but adds buttons to the current group (the last).
  */
-void ui_block_new_button_group(uiBlock *block)
+void ui_block_new_button_group(uiBlock *block, short flag)
 {
+  /* Don't create a new group if there is a "lock" on new groups. */
+  if (!BLI_listbase_is_empty(&block->button_groups)) {
+    uiButtonGroup *last_button_group = block->button_groups.last;
+    if (last_button_group->flag & UI_BUTTON_GROUP_LOCK) {
+      return;
+    }
+  }
+
   uiButtonGroup *new_group = MEM_mallocN(sizeof(uiButtonGroup), __func__);
   BLI_listbase_clear(&new_group->buttons);
+  new_group->flag = flag;
   BLI_addtail(&block->button_groups, new_group);
 }
 
 void ui_button_group_add_but(uiBlock *block, uiBut *but)
 {
   if (BLI_listbase_is_empty(&block->button_groups)) {
-    ui_block_new_button_group(block);
+    ui_block_new_button_group(block, 0);
   }
 
   uiButtonGroup *current_button_group = block->button_groups.last;
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 5a5e962e2bc..dc1f6cfce50 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -426,8 +426,17 @@ enum eBlockContentHints {
 typedef struct uiButtonGroup {
   void *next, *prev;
   ListBase buttons; /* #LinkData with #uiBut data field. */
+  short flag;
 } uiButtonGroup;
 
+/* #uiButtonGroup.flag. */
+typedef enum uiButtonGroupFlag {
+  /** While this flag is set, don't create new button groups for layout item calls. */
+  UI_BUTTON_GROUP_LOCK = (1 << 0),
+  /** The buttons in this group are inside a panel header. */
+  UI_BUTTON_GROUP_PANEL_HEADER = (1 << 1),
+} uiButtonGroupFlag;
+
 struct uiBlock {
   uiBlock *next, *prev;
 
@@ -1023,7 +1032,7 @@ void ui_item_menutype_func(struct bContext *C, struct uiLayout *layout, void *ar
 void ui_item_paneltype_func(struct bContext *C, struct uiLayout *layout, void *arg_pt);
 
 /* interface_button_group.c */
-void ui_block_new_button_group(uiBlock *block);
+void ui_block_new_button_group(uiBlock *block, short flag);
 void ui_button_group_add_but(uiBlock *block, uiBut *but);
 void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but);
 void ui_block_free_button_groups(uiBlock *block);
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 4315981afb7..8b59e85ec56 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -84,13 +84,6 @@ typedef struct uiLayoutRoot {
   int type;
   int opcontext;
 
-  /**
-   * If true, the root will be removed as part of the property search process.
-   * Necessary for cases like searching the contents of closed panels, where the
-   * block-level tag isn't enough, as there might be visible buttons in the header.
-   */
-  bool search_only;
-
   int emw, emh;
   int padding;
 
@@ -1985,7 +1978,7 @@ void uiItemFullR(uiLayout *layout,
 #endif /* UI_PROP_DECORATE */
 
   UI_block_layout_set_current(block, layout);
-  ui_block_new_button_group(block);
+  ui_block_new_button_group(block, 0);
 
   /* retrieve info */
   const PropertyType type = RNA_property_type(prop);
@@ -2723,7 +2716,7 @@ void uiItemPointerR_prop(uiLayout *layout,
 {
   const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0);
 
-  ui_block_new_button_group(uiLayoutGetBlock(layout));
+  ui_block_new_button_group(uiLayoutGetBlock(layout), 0);
 
   const PropertyType type = RNA_property_type(prop);
   if (!ELEM(type, PROP_POINTER, PROP_STRING, PROP_ENUM)) {
@@ -2829,7 +2822,7 @@ static uiBut *ui_item_menu(uiLayout *layout,
   uiLayout *heading_layout = ui_layout_heading_find(layout);
 
   UI_block_layout_set_current(block, layout);
-  ui_block_new_button_group(block);
+  ui_block_new_button_group(block, 0);
 
   if (!name) {
     name = "";
@@ -3095,7 +3088,7 @@ static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon)
   uiBlock *block = layout->root->block;
 
   UI_block_layout_set_current(block, layout);
-  ui_block_new_button_group(block);
+  ui_block_new_button_group(block, 0);
 
   if (!name) {
     name = "";
@@ -5015,16 +5008,6 @@ int uiLayoutGetEmboss(uiLayout *layout)
   return layout->emboss;
 }
 
-/**
- * Tags the layout root as search only, meaning the search process will run, but not the rest of
- * the layout process. Use in situations where part of the block's contents normally wouldn't be
- * drawn, but must be searched anyway, like the contents of closed panels with headers.
- */
-void uiLayoutRootSetSearchOnly(uiLayout *layout, bool search_only)
-{
-  layout->root->search_only = search_only;
-}
-
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -5044,42 +5027,6 @@ static bool block_search_panel_label_matches(const uiBlock *block, const char *s
   return false;
 }
 
-/**
- * Buttons for search only layouts (closed panel sub-panels) have still been added from the
- * layout functions, but they need to be hidden. Theoretically they could be removed too.
- */
-static void layout_free_and_hide_buttons(uiLayout *layout)
-{
-  LISTBASE_FOREACH_MUTABLE (uiItem *, item, &layout->items) {
-    if (item->type == ITEM_BUTTON) {
-      uiButtonItem *button_item = (uiButtonItem *)item;
-      BLI_assert(button_item->but != NULL);
-      button_item->but->flag |= UI_HIDDEN;
-      MEM_freeN(item);
-    }
-    else {
-      layout_free_and_hide_buttons((uiLayout *)item);
-    }
-  }
-
-  MEM_freeN(layout);
-}
-
-/**
- * Remove layouts used only for search and hide their buttons.
- * (See comment for #uiLayoutRootSetSearchOnly and in #uiLayoutRoot).
- */
-static void block_search_remove_search_only_roots(uiBlock *block)
-{
-  LISTBASE_FOREACH_MUTABLE (uiLayoutRoot *, root, &block->layouts) {
-    if (root->search_only) {
-      layout_free_and_hide_buttons(root->layout);
-      BLI_remlink(&block->layouts, root);
-      MEM_freeN(root);
-    }
-  }
-}
-
 /**
  * Returns true if a button or the data / operator it represents matches the search filter.
  */
@@ -5198,8 +5145,6 @@ bool UI_block_apply_search_filter(uiBlock *block, const char *search_filter)
                               true :
                               block_search_filter_tag_buttons(block, search_filter);
 
-  block_search_remove_search_only_roots(block);
-
   if (block->panel != NULL) {
     if (has_result) {
       ui_panel_tag_search_filter_match(block->panel);
@@ -5642,9 +5587,6 @@ void UI_block_layout_resolve(uiBlock *block, int *r_x, int *r_y)
   block->curlayout = NULL;
 
   LISTBASE_FOREACH_MUTABLE (uiLayoutRoot *, root, &block->layouts) {
-    /* Search only roots should be removed by #UI_block_apply_search_filter. */
-    BLI_assert(!root->search_only);
-
     ui_layout_add_padding_button(root);
 
     /* NULL in advance so we don't interfere when adding button */
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 974e2c62ab2..f50975760f1 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -193,10 +193,11 @@ static bool panel_active_animation_changed(ListBase *lb,
   return false;
 }
 
-static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_animation)
+/**
+ * \return True if the properties editor switch tabs since the last layout pass.
+ */
+static bool properties_space_needs_realign(ScrArea *area, ARegion *region)
 {
-  *r_panel_animation = NULL;
-
   if (area->spacetype == SPACE_PROPERTIES && region->regiontype == RGN_TYPE_WINDOW) {
     SpaceProperties *sbuts = area->spacedata.first;
 
@@ -205,6 +206,17 @@ static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_
     }
   }
 
+  return false;
+}
+
+static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_animation)
+{
+  *r_panel_animation = NULL;
+
+  if (properties_space_needs_realign(area, region)) {
+    return true;
+  }
+
   /* Detect if a panel was added or removed. */
   Panel *panel_animation = NULL;
   bool no_animatio

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list