[Bf-blender-cvs] [712ccc26028] property-search-ui: Property Search: Improve interaction with panels

Hans Goudey noreply at git.blender.org
Wed Jun 17 19:15:39 CEST 2020


Commit: 712ccc2602828cac164f00bb662051f2cf5da065
Author: Hans Goudey
Date:   Wed Jun 17 13:14:58 2020 -0400
Branches: property-search-ui
https://developer.blender.org/rB712ccc2602828cac164f00bb662051f2cf5da065

Property Search: Improve interaction with panels

This isn't perfect yet, but the animation is back, and it works much better.
There are still two issues though:
  1. Order doesn't update sometimes while searching / ending search.
  2. Panels are still displayed when empty in some situations.
The solution is probably just adding some more special cases. Possibly
a tag for panel aligning when the search filter is changed to force special
ordering calculations.

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

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/space_buttons/space_buttons.c

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 8b3831596ca..2353106c908 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1689,6 +1689,7 @@ void UI_panels_scale(struct ARegion *region, float new_width);
 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_is_search_filtered(const struct Panel *panel);
 
 bool UI_panel_category_is_visible(const struct ARegion *region);
 void UI_panel_category_add(struct ARegion *region, const char *name);
@@ -1708,8 +1709,6 @@ void UI_panel_category_draw_all(struct ARegion *region, const char *category_id_
 
 struct PanelType *UI_paneltype_find(int space_id, int region_id, const char *idname);
 
-void UI_panels_remove_search_filtered(struct ARegion *region);
-
 /* Polyinstantiated panels for representing a list of data. */
 struct Panel *UI_panel_add_instanced(struct ScrArea *area,
                                      struct ARegion *region,
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index d3601df9874..908bea847d4 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -167,6 +167,7 @@ static int panel_aligned(const ScrArea *area, const ARegion *region)
     return BUT_VERTICAL;
   }
 
+  printf("REGION IS ALIGNED HORIZONTAL\n");
   return 0;
 }
 
@@ -814,56 +815,28 @@ static void ui_offset_panel_block(uiBlock *block)
   block->rect.xmin = block->rect.ymin = 0.0;
 }
 
-/**
- * T
- *
- * \return True if the block was removed because its panel was empty
- */
-static bool panels_remove_search_filtered_recursive(ARegion *region, uiBlock *block)
+void ui_panel_set_search_filtered(struct Panel *panel, const bool value)
 {
-  BLI_assert(block->panel != NULL);
-
-  Panel *panel = block->panel;
-
-  bool all_children_filtered = true;
-  LISTBASE_FOREACH (Panel *, child_panel, &panel->children) {
-    uiBlock *child_block = child_panel->runtime.block;
-    if (child_block != NULL) {
-      all_children_filtered &= panels_remove_search_filtered_recursive(region, child_block);
-    }
-  }
-
-  if (all_children_filtered && panel->runtime_flag & PNL_SEARCH_FILTERED) {
-    // printf("Removing panel %s\n", panel->panelname);
-    panel->runtime_flag &= ~PNL_ACTIVE;
-    panel->runtime_flag |= PNL_WAS_ACTIVE;
-    panel->runtime.block = NULL;
-    BLI_remlink(&region->uiblocks, block);
-    UI_block_free(NULL, block);
-    return true;
-  }
-  return false;
+  SET_FLAG_FROM_TEST(panel->runtime_flag, value, PNL_SEARCH_FILTERED);
 }
 
-void UI_panels_remove_search_filtered(ARegion *region)
+static bool panel_is_search_filtered_recursive(const Panel *panel)
 {
-  LISTBASE_FOREACH_MUTABLE (uiBlock *, block, &region->uiblocks) {
-    if (block->panel == NULL) {
-      continue;
-    }
+  bool is_search_filtered = panel->runtime_flag & PNL_SEARCH_FILTERED;
 
-    panels_remove_search_filtered_recursive(region, block);
+  /* If the panel is filtered (removed) we need to check that its children are too. */
+  if (is_search_filtered) {
+    LISTBASE_FOREACH (const Panel *, child_panel, &panel->children) {
+      is_search_filtered &= panel_is_search_filtered_recursive(child_panel);
+    }
   }
+
+  return is_search_filtered;
 }
 
-void ui_panel_set_search_filtered(struct Panel *panel, const bool value)
+bool UI_panel_is_search_filtered(const Panel *panel)
 {
-  if (value) {
-    panel->runtime_flag |= PNL_SEARCH_FILTERED;
-  }
-  else {
-    panel->runtime_flag &= ~PNL_SEARCH_FILTERED;
-  }
+  return panel_is_search_filtered_recursive(panel);
 }
 
 /**************************** drawing *******************************/
@@ -1388,6 +1361,18 @@ static int find_highest_panel(const void *a1, const void *a2)
 {
   const PanelSort *ps1 = a1, *ps2 = a2;
 
+  /* Sort search-filtered panels to the bottom */
+  if (ps1->panel->runtime_flag & PNL_SEARCH_FILTERED &&
+      ps2->panel->runtime_flag & PNL_SEARCH_FILTERED) {
+    /* Skip and check for offset and sort order below. */
+  }
+  else if (ps2->panel->runtime_flag & PNL_SEARCH_FILTERED) {
+    return -1;
+  }
+  else if (ps1->panel->runtime_flag & PNL_SEARCH_FILTERED) {
+    return 1;
+  }
+
   /* stick uppermost header-less panels to the top of the region -
    * prevent them from being sorted (multiple header-less panels have to be sorted though) */
   if (ps1->panel->type->flag & PNL_NO_HEADER && ps2->panel->type->flag & PNL_NO_HEADER) {
@@ -1467,7 +1452,6 @@ static bool uiAlignPanelStep(ScrArea *area, ARegion *region, const float fac, co
   if (tot == 0) {
     return 0;
   }
-  // printf("Aligning %d panels, factor = %.2f\n", tot, fac);
 
   /* extra; change close direction? */
   LISTBASE_FOREACH (Panel *, panel, &region->panels) {
@@ -1496,6 +1480,7 @@ static bool uiAlignPanelStep(ScrArea *area, ARegion *region, const float fac, co
   if (drag) {
     /* while we are dragging, we sort on location and update sortorder */
     if (align == BUT_VERTICAL) {
+      printf("FIND HIGHEST PANEL\n");
       qsort(panelsort, tot, sizeof(PanelSort), find_highest_panel);
     }
     else {
@@ -1590,7 +1575,7 @@ static void ui_panels_size(ScrArea *area, ARegion *region, int *r_x, int *r_y)
 
   /* compute size taken up by panels, for setting in view2d */
   LISTBASE_FOREACH (Panel *, panel, &region->panels) {
-    if (panel->runtime_flag & PNL_ACTIVE) {
+    if (panel->runtime_flag & PNL_ACTIVE && !(panel->runtime_flag & PNL_SEARCH_FILTERED)) {
       int pa_sizex, pa_sizey;
 
       if (align == BUT_VERTICAL) {
@@ -1723,14 +1708,14 @@ void UI_panels_draw(const bContext *C, ARegion *region)
    * to draw on top. */
   LISTBASE_FOREACH_BACKWARD (uiBlock *, block, &region->uiblocks) {
     if (block->active && block->panel && !(block->panel->flag & PNL_SELECT) &&
-        !(block->flag & UI_BLOCK_FILTERED_EMPTY)) {
+        !UI_panel_is_search_filtered(block->panel)) {
       UI_block_draw(C, block);
     }
   }
 
   LISTBASE_FOREACH_BACKWARD (uiBlock *, block, &region->uiblocks) {
     if (block->active && block->panel && (block->panel->flag & PNL_SELECT) &&
-        !(block->flag & UI_BLOCK_FILTERED_EMPTY)) {
+        !UI_panel_is_search_filtered(block->panel)) {
       UI_block_draw(C, block);
     }
   }
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index 938418939c4..5c21bd50707 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2801,7 +2801,6 @@ void ED_region_panels_ex(
   /* TODO: remove? */
   ED_region_panels_layout_ex(
       C, region, &region->type->paneltypes, contexts, contextnr, vertical, NULL);
-  UI_panels_remove_search_filtered(region);
   ED_region_panels_draw(C, region);
 }
 
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index b55d70d5bba..599c021e4de 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -218,7 +218,6 @@ static void buttons_main_region_layout(const bContext *C, ARegion *region)
   }
   else {
     buttons_main_region_layout_properties(C, sbuts, region);
-    UI_panels_remove_search_filtered(region);
   }
 
   sbuts->mainbo = sbuts->mainb;



More information about the Bf-blender-cvs mailing list