[Bf-blender-cvs] [16bf1807a12] property-search-ui: Merge branch 'master' into property-search-ui

Hans Goudey noreply at git.blender.org
Tue Jul 7 16:18:53 CEST 2020


Commit: 16bf1807a1235edd73caa9c25239a9f68de24315
Author: Hans Goudey
Date:   Tue Jul 7 10:18:44 2020 -0400
Branches: property-search-ui
https://developer.blender.org/rB16bf1807a1235edd73caa9c25239a9f68de24315

Merge branch 'master' into property-search-ui

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



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

diff --cc source/blender/editors/interface/interface_layout.c
index c9958386b34,858b48ba9fa..76c3f410aa0
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@@ -5109,423 -5035,9 +5099,421 @@@ int uiLayoutGetEmboss(uiLayout *layout
    if (layout->emboss == UI_EMBOSS_UNDEFINED) {
      return layout->root->block->dt;
    }
-   else {
-     return layout->emboss;
-   }
+   return layout->emboss;
  }
  
 +void uiLayoutRootSetSearchOnly(uiLayout *layout, bool search_only)
 +{
 +  layout->root->search_only = search_only;
 +}
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Block Layout Search Filtering
 + * \{ */
 +
 +// #define PROPERTY_SEARCH_USE_TOOLTIPS
 +#define DEBUG_LAYOUT_ROOTS
 +
 +static void ui_layout_free(uiLayout *layout);
 +
 +#ifdef DEBUG_LAYOUT_ROOTS
 +
 +/* clang-format off */
 +static const char *but_type_string(eButType type) {
 +  switch (type) {
 +    case UI_BTYPE_BUT: return  "But";
 +    case UI_BTYPE_ROW: return  "Row But";
 +    case UI_BTYPE_TEXT: return  "Text";
 +    case UI_BTYPE_MENU: return  "Menu";
 +    case UI_BTYPE_BUT_MENU: return  "But Menu";
 +    case UI_BTYPE_NUM: return  "Number";
 +    case UI_BTYPE_NUM_SLIDER: return  "Number Slider";
 +    case UI_BTYPE_TOGGLE: return  "Toggle";
 +    case UI_BTYPE_TOGGLE_N: return  "Toggle N";
 +    case UI_BTYPE_ICON_TOGGLE: return  "Icon Toggle";
 +    case UI_BTYPE_ICON_TOGGLE_N: return  "Icon Toggle N";
 +    case UI_BTYPE_BUT_TOGGLE: return  "But Toggle";
 +    case UI_BTYPE_CHECKBOX: return  "Checkbox";
 +    case UI_BTYPE_CHECKBOX_N: return  "Checkbox N";
 +    case UI_BTYPE_COLOR: return  "Color";
 +    case UI_BTYPE_TAB: return  "Tab";
 +    case UI_BTYPE_POPOVER: return  "Popover";
 +    case UI_BTYPE_SCROLL: return  "Scroll";
 +    case UI_BTYPE_BLOCK: return  "Block";
 +    case UI_BTYPE_LABEL: return  "Label";
 +    case UI_BTYPE_KEY_EVENT: return  "Key Event";
 +    case UI_BTYPE_HSVCUBE: return  "HSV Cube";
 +    case UI_BTYPE_PULLDOWN: return  "Pulldown";
 +    case UI_BTYPE_ROUNDBOX: return  "Roundbox";
 +    case UI_BTYPE_COLORBAND: return  "Colorband";
 +    case UI_BTYPE_UNITVEC: return  "Unit Vector";
 +    case UI_BTYPE_CURVE: return  "Curve";
 +    case UI_BTYPE_CURVEPROFILE: return  "Curve Profile";
 +    case UI_BTYPE_LISTBOX: return  "Listbox";
 +    case UI_BTYPE_LISTROW: return  "List Row";
 +    case UI_BTYPE_HSVCIRCLE: return  "HSV Circle";
 +    case UI_BTYPE_TRACK_PREVIEW: return  "Track Preview";
 +    case UI_BTYPE_SEARCH_MENU: return  "Search Menu";
 +    case UI_BTYPE_EXTRA: return  "Extra";
 +    case UI_BTYPE_HOTKEY_EVENT: return  "Hotkey Event";
 +    case UI_BTYPE_IMAGE: return  "Image";
 +    case UI_BTYPE_HISTOGRAM: return  "Histogram";
 +    case UI_BTYPE_WAVEFORM: return  "Waveform";
 +    case UI_BTYPE_VECTORSCOPE: return  "Vectorscope";
 +    case UI_BTYPE_PROGRESS_BAR: return  "Progress Bar";
 +    case UI_BTYPE_NODE_SOCKET: return  "Node Socket";
 +    case UI_BTYPE_SEPR: return  "Spacer";
 +    case UI_BTYPE_SEPR_LINE: return  "Spacer Line";
 +    case UI_BTYPE_SEPR_SPACER: return  "Dynamic Spacer";
 +    case UI_BTYPE_GRIP: return  "Grip";
 +    default: return "Unkown Button Type";
 +  }         
 +}
 +/* clang-format on */
 +
 +/* Keep order the same as enum above. */
 +const char *item_type_names[12] = {
 +    "Button",      /* ITEM_BUTTON */
 +    "Row",         /* ITEM_LAYOUT_ROW */
 +    "Column",      /* ITEM_LAYOUT_COLUMN */
 +    "Column Flow", /* ITEM_LAYOUT_COLUMN_FLOW */
 +    "Row Flow",    /* ITEM_LAYOUT_ROW_FLOW */
 +    "Grid Flow",   /* ITEM_LAYOUT_GRID_FLOW */
 +    "Box",         /* ITEM_LAYOUT_BOX */
 +    "Absolute",    /* ITEM_LAYOUT_ABSOLUTE */
 +    "Split",       /* ITEM_LAYOUT_SPLIT */
 +    "Overlap",     /* ITEM_LAYOUT_OVERLAP */
 +    "Radial",      /* ITEM_LAYOUT_RADIAL */
 +    "Root",        /* ITEM_LAYOUT_ROOT */
 +};
 +
 +#  define PRINT_DEFAULT "\x1B[0m"
 +#  define PRINT_GREEN "\x1B[32m"
 +#  define PRINT_RED "\x1B[31m"
 +#  define PRINT_WHITE "\x1B[37m"
 +static void debug_print_button_item(uiButtonItem *button_item)
 +{
 +  uiBut *but = button_item->but;
 +
 +  if (but == NULL) {
 +    printf("NULL BUT");
 +    return;
 +  }
 +
 +  printf("%s%s%s: ", PRINT_RED, but_type_string(but->type), PRINT_DEFAULT);
 +
 +  if (but->str && but->str[0]) {
 +    printf(but->str);
 +  }
 +  else if (!RNA_pointer_is_null(&but->rnapoin)) {
 +    printf(RNA_property_ui_name(but->rnaprop));
 +  }
 +}
 +
 +static void debug_print_layout(uiItem *item, int depth, bool child_items_layout)
 +{
 +  uiItemType type = item->type;
 +
 +  printf("%s", PRINT_WHITE);
 +  for (int i = 0; i < depth; i++) {
 +    printf("| ");
 +  }
 +  printf("%s", PRINT_DEFAULT);
 +
 +  if (type == ITEM_BUTTON) {
 +    uiButtonItem *button_item = (uiButtonItem *)item;
 +
 +    debug_print_button_item(button_item);
 +    printf("\n");
 +  }
 +  else {
 +    printf("%s%s%s: ", PRINT_GREEN, item_type_names[item->type], PRINT_DEFAULT);
 +    uiLayout *layout = (uiLayout *)item;
 +
 +    printf("%s", PRINT_WHITE);
 +    if (layout->property_search_layout_temp_debug) {
 +      printf("(search layout)");
 +    }
 +    if (child_items_layout) {
 +      printf("(child_items_layout)");
 +    }
 +    printf("%s", PRINT_DEFAULT);
 +
 +    printf("\n");
 +
 +    if (layout->child_items_layout != NULL) {
 +
 +      debug_print_layout((uiItem *)layout->child_items_layout, depth + 1, true);
 +    }
 +    LISTBASE_FOREACH (uiItem *, child_item, &layout->items) {
 +      debug_print_layout(child_item, depth + 1, false);
 +    }
 +  }
 +}
 +#endif /* DEBUG_LAYOUT_ROOTS */
 +
 +static void ui_layout_free_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 {
 +      ui_layout_free_hide_buttons((uiLayout *)item);
 +    }
 +  }
 +
 +  MEM_freeN(layout);
 +}
 +
 +/**
 + * Tag all buttons with whether they matched the search filter or not.
 + *
 + * \note This doesn't actually remove any buttons, and buttons that were tagged might
 + * not even be removed if they were in a layout with property search turned off.
 + */
 +static void ui_block_search_filter_tag_buttons(uiBlock *block)
 +{
 +  LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
 +    /* Flag all buttons with no RNA property. This is probably too strict. */
 +    if (but->rnaprop == NULL) {
 +      but->flag |= UI_FILTERED;
 +      continue;
 +    }
 +
 +    /* Flag all label buttons, we don't want to re-display them. */
 +    if (but->type == UI_BTYPE_LABEL) {
 +      but->flag |= UI_FILTERED;
 +    }
 +
 +    /* Do the shorter check first, in case the check returns true. */
 +    if (BLI_strcasestr(but->str, block->search_filter) ||
 +        BLI_strcasestr(RNA_property_ui_name(but->rnaprop), block->search_filter)
 +#ifdef PROPERTY_SEARCH_USE_TOOLTIPS
 +        || BLI_strcasestr(RNA_property_description(but->rnaprop), block->search_filter)
 +#endif
 +    ) {
 +      continue;
 +    }
 +
 +    but->flag |= UI_FILTERED;
 +  }
 +
 +  /* Remove filter from labels and decorators that correspond to un-filtered buttons. */
 +  LISTBASE_FOREACH (uiBut *, but, &block->buttons) {
 +    if ((but->flag & UI_FILTERED) == 0) {
 +      uiBut *label_but = but->label_but;
 +      uiBut *decorator_but = but->decorator_but;
 +      if (label_but != NULL) {
 +        label_but->flag &= ~UI_FILTERED;
 +      }
 +      if (decorator_but != NULL) {
 +        decorator_but->flag &= ~UI_FILTERED;
 +      }
 +    }
 +  }
 +}
 +
 +/**
 + * Recursive implementation for #ui_block_search_filter_clean.
 + */
 +static bool ui_layout_search_clean_recursive(uiLayout *layout)
 +{
 +  /* Remove all search filtered button items. */
 +  bool layout_emptied = uiLayoutGetPropSearch(layout);
 +  if (uiLayoutGetPropSearch(layout)) {
 +    LISTBASE_FOREACH_MUTABLE (uiItem *, item, &layout->items) {
 +      if (item->type == ITEM_BUTTON) {
 +        uiButtonItem *button_item = (uiButtonItem *)item;
 +        uiBut *but = button_item->but;
 +        if (but->flag & UI_FILTERED) {
 +          but->flag |= UI_HIDDEN;
 +          BLI_remlink(&layout->items, item);
 +          MEM_freeN(item);
 +        }
 +        else {
 +          layout_emptied = false;
 +        }
 +      }
 +    }
 +  }
 +
 +  /* Recursively clean sub-layouts. */
 +  bool all_children_empty = true;
 +  LISTBASE_FOREACH_MUTABLE (uiItem *, item, &layout->items) {
 +    if (item->type == ITEM_BUTTON) {
 +      BLI_assert(!layout_emptied || !uiLayoutGetPropSearch(layout));
 +      continue;
 +    }
 +
 +    bool empty = ui_layout_search_clean_recursive((uiLayout *)item);
 +    all_children_empty &= empty;
 +
 +    if (empty) {
 +      BLI_assert(BLI_findindex(&layout->items, item) != -1);
 +      BLI_remlink(&layout->items, item);
 +      MEM_freeN(item);
 +    }
 +  }
 +
 +  return layout_emptied && all_children_empty;
 +}
 +
 +/**
 + * Remove buttons on layouts with property search set to true,
 + * and remove layouts with no buttons and empty child layouts.
 + */
 +static bool ui_block_layout_search_clean(uiBlock *block)
 +{
 +  bool all_roots_empty = true;
 +  LISTBASE_FOREACH_MUTABLE (uiLayoutRoot *, root, &block->layouts) {
 +    /* Find exceptions to search layout. */
 +    if (root->type == UI_LAYOUT_HEADER) {
 +      continue;
 +    }
 +
 +    bool empty = ui_layout_search_clean_recursive(root->layout);
 +    all_roots_empty &= empty;
 +
 +    /* Empty roots should have all sublayouts freed, but they needs to be freed too. */
 +    if (empty) {
 +      BLI_assert(BLI_findindex(&block->layouts, root) != -1);
 +      BLI_remlink(&block->layouts, root);
 +      MEM_freeN(root);
 +    }
 +  }
 +
 +  return all_roots_empty;
 +}
 +
 +static void ui_layout_search_replace_labels(uiLayout *layout)
 +{
 +  LISTBASE_FOREACH_MUTABLE (uiItem *, item, &layout->items) {
 +    if (item->type == ITEM_BUTTON) {
 +      uiButtonItem *button_item = (uiButtonItem *)item;
 +      uiBut *but = 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list