diff options
author | Julian Eisel <julian@blender.org> | 2022-03-15 20:43:26 +0300 |
---|---|---|
committer | Julian Eisel <julian@blender.org> | 2022-03-15 20:48:52 +0300 |
commit | d8e3bcf770c25b0780b2c35a72afae00171ba914 (patch) | |
tree | 521ff41e4a4e8cd7c77e0f4ec51187f01ceb897b /source | |
parent | 7f77bd95d982279766c2bfb38829b18fdbe55f02 (diff) |
Outliner: Display buttons to edit library override properties
As proposed in T95802, this adds buttons to a new column on the right to modify
the override in the Library Override display mode. Some further usability
improvements are planned. E.g. this does not yet expand collections (modifiers,
constraints, etc) nicely or group modified properties of a modifier together.
Vector properties with more than 3 items or matrices aren't displayed nicely
yet, they are just squeezed into the column. If this actually becomes a problem
there are some ideas to address this.
Differential Revision: https://developer.blender.org/D14268
Diffstat (limited to 'source')
8 files changed, 144 insertions, 43 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 060c9dc33d6..a223eac3000 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -1610,6 +1610,14 @@ uiBut *uiDefAutoButR(uiBlock *block, int y, int width, int height); +void uiDefAutoButsArrayR(uiBlock *block, + PointerRNA *ptr, + PropertyRNA *prop, + const int icon, + const int x, + const int y, + const int tot_width, + const int height); /** * \a check_prop callback filters functions to avoid drawing certain properties, * in cases where PROP_HIDDEN flag can't be used for a property. diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c index 814bd956096..728d42a9353 100644 --- a/source/blender/editors/interface/interface_utils.c +++ b/source/blender/editors/interface/interface_utils.c @@ -320,6 +320,7 @@ uiBut *uiDefAutoButR(uiBlock *block, -1, -1, NULL); + ui_but_add_search(but, ptr, prop, NULL, NULL); break; } case PROP_COLLECTION: { @@ -338,6 +339,29 @@ uiBut *uiDefAutoButR(uiBlock *block, return but; } +void uiDefAutoButsArrayR(uiBlock *block, + PointerRNA *ptr, + PropertyRNA *prop, + const int icon, + const int x, + const int y, + const int tot_width, + const int height) +{ + const int len = RNA_property_array_length(ptr, prop); + if (len == 0) { + return; + } + + const int item_width = tot_width / len; + + UI_block_align_begin(block); + for (int i = 0; i < len; i++) { + uiDefAutoButR(block, ptr, prop, i, "", icon, x + i * item_width, y, item_width, height); + } + UI_block_align_end(block); +} + eAutoPropButsReturn uiDefAutoButsRNA(uiLayout *layout, PointerRNA *ptr, bool (*check_prop)(PointerRNA *ptr, diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc index 4ef0bbbcde8..a50dde68d28 100644 --- a/source/blender/editors/space_outliner/outliner_draw.cc +++ b/source/blender/editors/space_outliner/outliner_draw.cc @@ -1082,7 +1082,7 @@ static void outliner_draw_restrictbuts(uiBlock *block, } BLI_assert((restrict_column_offset * UI_UNIT_X + V2D_SCROLL_WIDTH) == - outliner_restrict_columns_width(space_outliner)); + outliner_right_columns_width(space_outliner)); /* Create buttons. */ uiBut *bt; @@ -1779,11 +1779,65 @@ static void outliner_draw_userbuts(uiBlock *block, } } -static bool outliner_draw_overrides_buts(uiBlock *block, - ARegion *region, - SpaceOutliner *space_outliner, - ListBase *lb, - const bool is_open) +static void outliner_draw_overrides_rna_buts(uiBlock *block, + const ARegion *region, + const SpaceOutliner *space_outliner, + const ListBase *lb, + const int x) +{ + LISTBASE_FOREACH (const TreeElement *, te, lb) { + const TreeStoreElem *tselem = TREESTORE(te); + if (TSELEM_OPEN(tselem, space_outliner)) { + outliner_draw_overrides_rna_buts(block, region, space_outliner, &te->subtree, x); + } + + if (!outliner_is_element_in_view(te, ®ion->v2d)) { + continue; + } + if (tselem->type != TSE_LIBRARY_OVERRIDE) { + continue; + } + + TreeElementOverridesProperty &override_elem = *tree_element_cast<TreeElementOverridesProperty>( + te); + + PointerRNA *ptr = &override_elem.override_rna_ptr; + PropertyRNA *prop = &override_elem.override_rna_prop; + const PropertyType prop_type = RNA_property_type(prop); + + const float pad_x = 1 * UI_DPI_FAC; + const float max_width = OL_RNA_COL_SIZEX - 2 * pad_x; + const float height = UI_UNIT_Y - U.pixelsize; + + uiBut *auto_but = uiDefAutoButR(block, + ptr, + prop, + -1, + (prop_type == PROP_ENUM) ? nullptr : "", + ICON_NONE, + x + pad_x, + te->ys, + max_width, + height); + /* Added the button successfully, nothing else to do. Otherwise, cases for multiple buttons + * need to be handled. */ + if (auto_but) { + continue; + } + + if (!auto_but) { + /* TODO what if the array is longer, and doesn't fit nicely? What about multi-dimension + * arrays? */ + uiDefAutoButsArrayR(block, ptr, prop, ICON_NONE, x, te->ys, max_width, height); + } + } +} + +static bool outliner_draw_overrides_warning_buts(uiBlock *block, + ARegion *region, + SpaceOutliner *space_outliner, + ListBase *lb, + const bool is_open) { bool any_item_has_warnings = false; @@ -1829,7 +1883,7 @@ static bool outliner_draw_overrides_buts(uiBlock *block, break; } - const bool any_child_has_warnings = outliner_draw_overrides_buts( + const bool any_child_has_warnings = outliner_draw_overrides_warning_buts( block, region, space_outliner, @@ -1863,28 +1917,20 @@ static bool outliner_draw_overrides_buts(uiBlock *block, return any_item_has_warnings; } -static void outliner_draw_rnacols(ARegion *region, int sizex) +static void outliner_draw_separator(ARegion *region, const int x) { View2D *v2d = ®ion->v2d; - float miny = v2d->cur.ymin; - if (miny < v2d->tot.ymin) { - miny = v2d->tot.ymin; - } - GPU_line_width(1.0f); uint pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); immUniformThemeColorShadeAlpha(TH_BACK, -15, -200); - immBegin(GPU_PRIM_LINES, 4); - - immVertex2f(pos, sizex, v2d->cur.ymax); - immVertex2f(pos, sizex, miny); + immBegin(GPU_PRIM_LINES, 2); - immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, v2d->cur.ymax); - immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, miny); + immVertex2f(pos, x, v2d->cur.ymax); + immVertex2f(pos, x, v2d->cur.ymin); immEnd(); @@ -3637,7 +3683,7 @@ static void outliner_draw_tree(bContext *C, const TreeViewContext *tvc, ARegion *region, SpaceOutliner *space_outliner, - const float restrict_column_width, + const float right_column_width, const bool use_mode_column, const bool use_warning_column, TreeElement **te_edit) @@ -3672,8 +3718,8 @@ static void outliner_draw_tree(bContext *C, /* Set scissor so tree elements or lines can't overlap restriction icons. */ int scissor[4] = {0}; - if (restrict_column_width > 0.0f) { - int mask_x = BLI_rcti_size_x(®ion->v2d.mask) - (int)restrict_column_width + 1; + if (right_column_width > 0.0f) { + int mask_x = BLI_rcti_size_x(®ion->v2d.mask) - (int)right_column_width + 1; CLAMP_MIN(mask_x, 0); GPU_scissor_get(scissor); @@ -3699,11 +3745,11 @@ static void outliner_draw_tree(bContext *C, (te->flag & TE_DRAGGING) != 0, startx, &starty, - restrict_column_width, + right_column_width, te_edit); } - if (restrict_column_width > 0.0f) { + if (right_column_width > 0.0f) { /* Reset scissor. */ GPU_scissor(UNPACK4(scissor)); } @@ -3754,21 +3800,21 @@ static int outliner_data_api_buttons_start_x(int max_tree_width) static int outliner_width(SpaceOutliner *space_outliner, int max_tree_width, - float restrict_column_width) + float right_column_width) { if (space_outliner->outlinevis == SO_DATA_API) { return outliner_data_api_buttons_start_x(max_tree_width) + OL_RNA_COL_SIZEX + 10 * UI_DPI_FAC; } - return max_tree_width + restrict_column_width; + return max_tree_width + right_column_width; } static void outliner_update_viewable_area(ARegion *region, SpaceOutliner *space_outliner, int tree_width, int tree_height, - float restrict_column_width) + float right_column_width) { - int sizex = outliner_width(space_outliner, tree_width, restrict_column_width); + int sizex = outliner_width(space_outliner, tree_width, right_column_width); int sizey = tree_height; /* Extend size to allow for horizontal scrollbar and extra offset. */ @@ -3829,7 +3875,7 @@ void draw_outliner(const bContext *C) space_outliner->runtime->tree_display->hasWarnings(); /* Draw outliner stuff (background, hierarchy lines and names). */ - const float restrict_column_width = outliner_restrict_columns_width(space_outliner); + const float right_column_width = outliner_right_columns_width(space_outliner); outliner_back(region); block = UI_block_begin(C, region, __func__, UI_EMBOSS); outliner_draw_tree((bContext *)C, @@ -3837,7 +3883,7 @@ void draw_outliner(const bContext *C) &tvc, region, space_outliner, - restrict_column_width, + right_column_width, use_mode_column, use_warning_column, &te_edit); @@ -3852,7 +3898,8 @@ void draw_outliner(const bContext *C) if (space_outliner->outlinevis == SO_DATA_API) { int buttons_start_x = outliner_data_api_buttons_start_x(tree_width); /* draw rna buttons */ - outliner_draw_rnacols(region, buttons_start_x); + outliner_draw_separator(region, buttons_start_x); + outliner_draw_separator(region, buttons_start_x + OL_RNA_COL_SIZEX); UI_block_emboss_set(block, UI_EMBOSS); outliner_draw_rnabuts(block, region, space_outliner, buttons_start_x, &space_outliner->tree); @@ -3864,9 +3911,16 @@ void draw_outliner(const bContext *C) } else if (space_outliner->outlinevis == SO_OVERRIDES_LIBRARY) { /* Draw overrides status columns. */ - outliner_draw_overrides_buts(block, region, space_outliner, &space_outliner->tree, true); + outliner_draw_overrides_warning_buts( + block, region, space_outliner, &space_outliner->tree, true); + + UI_block_emboss_set(block, UI_EMBOSS); + const int x = region->v2d.cur.xmax - OL_RNA_COL_SIZEX; + outliner_draw_separator(region, x); + outliner_draw_overrides_rna_buts(block, region, space_outliner, &space_outliner->tree, x); + UI_block_emboss_set(block, UI_EMBOSS_NONE_OR_STATUS); } - else if (restrict_column_width > 0.0f) { + else if (right_column_width > 0.0f) { /* draw restriction columns */ RestrictPropertiesActive props_active; memset(&props_active, 1, sizeof(RestrictPropertiesActive)); @@ -3893,7 +3947,7 @@ void draw_outliner(const bContext *C) /* Draw edit buttons if necessary. */ if (te_edit) { - outliner_buttons(C, block, region, restrict_column_width, te_edit); + outliner_buttons(C, block, region, right_column_width, te_edit); } UI_block_end(C, block); @@ -3901,7 +3955,7 @@ void draw_outliner(const bContext *C) /* Update total viewable region. */ outliner_update_viewable_area( - region, space_outliner, tree_width, tree_height, restrict_column_width); + region, space_outliner, tree_width, tree_height, right_column_width); } /** \} */ diff --git a/source/blender/editors/space_outliner/outliner_intern.hh b/source/blender/editors/space_outliner/outliner_intern.hh index a9bdcc56787..7970841b4fd 100644 --- a/source/blender/editors/space_outliner/outliner_intern.hh +++ b/source/blender/editors/space_outliner/outliner_intern.hh @@ -638,7 +638,7 @@ bool outliner_tree_traverse(const SpaceOutliner *space_outliner, int filter_tselem_flag, TreeTraversalFunc func, void *customdata); -float outliner_restrict_columns_width(const struct SpaceOutliner *space_outliner); +float outliner_right_columns_width(const struct SpaceOutliner *space_outliner); /** * Find first tree element in tree with matching tree-store flag. */ diff --git a/source/blender/editors/space_outliner/outliner_select.cc b/source/blender/editors/space_outliner/outliner_select.cc index a583eb0364f..a202ded6deb 100644 --- a/source/blender/editors/space_outliner/outliner_select.cc +++ b/source/blender/editors/space_outliner/outliner_select.cc @@ -1551,7 +1551,7 @@ static bool outliner_is_co_within_restrict_columns(const SpaceOutliner *space_ou const ARegion *region, float view_co_x) { - return (view_co_x > region->v2d.cur.xmax - outliner_restrict_columns_width(space_outliner)); + return (view_co_x > region->v2d.cur.xmax - outliner_right_columns_width(space_outliner)); } bool outliner_is_co_within_mode_column(SpaceOutliner *space_outliner, const float view_mval[2]) diff --git a/source/blender/editors/space_outliner/outliner_utils.cc b/source/blender/editors/space_outliner/outliner_utils.cc index 556f87617f6..ed5a2108d3c 100644 --- a/source/blender/editors/space_outliner/outliner_utils.cc +++ b/source/blender/editors/space_outliner/outliner_utils.cc @@ -314,7 +314,7 @@ bool outliner_tree_traverse(const SpaceOutliner *space_outliner, return true; } -float outliner_restrict_columns_width(const SpaceOutliner *space_outliner) +float outliner_right_columns_width(const SpaceOutliner *space_outliner) { int num_columns = 0; @@ -322,8 +322,10 @@ float outliner_restrict_columns_width(const SpaceOutliner *space_outliner) case SO_DATA_API: case SO_SEQUENCE: case SO_LIBRARIES: - case SO_OVERRIDES_LIBRARY: return 0.0f; + case SO_OVERRIDES_LIBRARY: + num_columns = OL_RNA_COL_SIZEX / UI_UNIT_X; + break; case SO_ID_ORPHANS: num_columns = 3; break; diff --git a/source/blender/editors/space_outliner/tree/tree_element_overrides.cc b/source/blender/editors/space_outliner/tree/tree_element_overrides.cc index 64c390d29b3..857f5577e59 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_overrides.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_overrides.cc @@ -73,7 +73,8 @@ void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const } } - TreeElementOverridesData data = {id, *override_prop, is_rna_path_valid}; + TreeElementOverridesData data = { + id, *override_prop, override_rna_ptr, *override_rna_prop, is_rna_path_valid}; outliner_add_element( &space_outliner, &legacy_te_.subtree, &data, &legacy_te_, TSE_LIBRARY_OVERRIDE, index++); } @@ -81,11 +82,13 @@ void TreeElementOverridesBase::expand(SpaceOutliner &space_outliner) const TreeElementOverridesProperty::TreeElementOverridesProperty(TreeElement &legacy_te, TreeElementOverridesData &override_data) - : AbstractTreeElement(legacy_te), override_prop_(override_data.override_property) + : AbstractTreeElement(legacy_te), + override_rna_ptr(override_data.override_rna_ptr), + override_rna_prop(override_data.override_rna_prop) { BLI_assert(legacy_te.store_elem->type == TSE_LIBRARY_OVERRIDE); - legacy_te.name = override_prop_.rna_path; + legacy_te.name = override_data.override_property.rna_path; /* Abusing this for now, better way to do it is also pending current refactor of the whole tree * code to use C++. */ legacy_te.directdata = POINTER_FROM_UINT(override_data.is_rna_path_valid); diff --git a/source/blender/editors/space_outliner/tree/tree_element_overrides.hh b/source/blender/editors/space_outliner/tree/tree_element_overrides.hh index 1987efcf6f6..a2d1409f193 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_overrides.hh +++ b/source/blender/editors/space_outliner/tree/tree_element_overrides.hh @@ -6,13 +6,21 @@ #pragma once +#include "RNA_types.h" + #include "tree_element.hh" +struct ID; +struct IDOverrideLibraryProperty; + namespace blender::ed::outliner { struct TreeElementOverridesData { ID &id; IDOverrideLibraryProperty &override_property; + PointerRNA &override_rna_ptr; + PropertyRNA &override_rna_prop; + bool is_rna_path_valid; }; @@ -27,7 +35,9 @@ class TreeElementOverridesBase final : public AbstractTreeElement { }; class TreeElementOverridesProperty final : public AbstractTreeElement { - IDOverrideLibraryProperty &override_prop_; + public: + PointerRNA override_rna_ptr; + PropertyRNA &override_rna_prop; public: TreeElementOverridesProperty(TreeElement &legacy_te, TreeElementOverridesData &override_data); |