Fix T83027: Incorrect outliner collection state after operator
The "Hide Collection" operators assigned to the number keys in edit mode trigger a redraw of the outliner, but as an optimization, they do *not* trigger a rebuild of the tree. This optimization is valid because unlike the collection exclude toggle, the heirarchy is not affected by collection visibility. However, it means that currently you must trigger a rebuild to get the correct "grayed out" status after using the operator. Rather than trigger a rebuild in this case to solve the bug, this patch moves the decision for whether to gray out the text of a tree element to the draw step rather than the build step. This means that any change to the corresponding properties doesn't require a full tree rebuild. Note that changing the "hide_viewport" property from the outliner still causes a tree rebuild. I think that's because of the checks in `outliner_collection_set_flag_recursive_fn`. That could be optimized in the future. Differential Revision: https://developer.blender.org/D10240
This commit is contained in:
parent
55700ac390
commit
34580748dc
Notes:
blender-bot
2023-02-14 08:06:33 +01:00
Referenced by issue #83027, The active state of collection Incorrect
|
@ -2958,6 +2958,41 @@ static void outliner_set_coord_tree_element(TreeElement *te, int startx, int sta
|
|||
}
|
||||
}
|
||||
|
||||
static bool element_should_draw_faded(const TreeViewContext *tvc,
|
||||
const TreeElement *te,
|
||||
const TreeStoreElem *tselem)
|
||||
{
|
||||
if (tselem->type == 0) {
|
||||
switch (te->idcode) {
|
||||
case ID_OB: {
|
||||
const Object *ob = (const Object *)tselem->id;
|
||||
/* Lookup in view layer is logically const as it only checks a cache. */
|
||||
const Base *base = (te->directdata) ? (const Base *)te->directdata :
|
||||
BKE_view_layer_base_find(
|
||||
(ViewLayer *)tvc->view_layer, (Object *)ob);
|
||||
const bool is_visible = (base != NULL) && (base->flag & BASE_VISIBLE_VIEWLAYER);
|
||||
if (!is_visible) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (tselem->type) {
|
||||
case TSE_LAYER_COLLECTION: {
|
||||
const LayerCollection *layer_collection = (const LayerCollection *)te->directdata;
|
||||
const bool is_visibe = layer_collection->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER;
|
||||
const bool is_excluded = layer_collection->flag & LAYER_COLLECTION_EXCLUDE;
|
||||
return !is_visibe || is_excluded;
|
||||
}
|
||||
}
|
||||
|
||||
if (te->flag & TE_CHILD_NOT_IN_COLLECTION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void outliner_draw_tree_element(bContext *C,
|
||||
uiBlock *block,
|
||||
const uiFontStyle *fstyle,
|
||||
|
@ -2981,10 +3016,7 @@ static void outliner_draw_tree_element(bContext *C,
|
|||
outliner_icon_background_colors(icon_bgcolor, icon_border);
|
||||
|
||||
if (*starty + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && *starty <= region->v2d.cur.ymax) {
|
||||
const float alpha_fac = ((te->flag & TE_DISABLED) || (te->flag & TE_CHILD_NOT_IN_COLLECTION) ||
|
||||
draw_grayed_out) ?
|
||||
0.5f :
|
||||
1.0f;
|
||||
const float alpha_fac = element_should_draw_faded(tvc, te, tselem) ? 0.5f : 1.0f;
|
||||
int xmax = region->v2d.cur.xmax;
|
||||
|
||||
if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == NULL)) {
|
||||
|
|
|
@ -153,8 +153,7 @@ enum {
|
|||
TE_ICONROW = (1 << 1),
|
||||
TE_LAZY_CLOSED = (1 << 2),
|
||||
TE_FREE_NAME = (1 << 3),
|
||||
TE_DISABLED = (1 << 4),
|
||||
TE_DRAGGING = (1 << 5),
|
||||
TE_DRAGGING = (1 << 4),
|
||||
TE_CHILD_NOT_IN_COLLECTION = (1 << 6),
|
||||
/* Child elements of the same type in the icon-row are drawn merged as one icon.
|
||||
* This flag is set for an element that is part of these merged child icons. */
|
||||
|
|
|
@ -143,10 +143,6 @@ void TreeDisplayViewLayer::add_layer_collections_recursive(ListBase &tree,
|
|||
if (!(tselem->used || ID_IS_LINKED(id) || ID_IS_OVERRIDE_LIBRARY(id))) {
|
||||
tselem->flag &= ~TSE_CLOSED;
|
||||
}
|
||||
|
||||
if (exclude || (lc->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER) == 0) {
|
||||
ten->flag |= TE_DISABLED;
|
||||
}
|
||||
}
|
||||
|
||||
add_layer_collections_recursive(ten->subtree, lc->layer_collections, *ten);
|
||||
|
@ -165,10 +161,6 @@ void TreeDisplayViewLayer::add_layer_collection_objects(ListBase &tree,
|
|||
TreeElement *te_object = outliner_add_element(
|
||||
&space_outliner_, &tree, base->object, &ten, 0, 0);
|
||||
te_object->directdata = base;
|
||||
|
||||
if (!(base->flag & BASE_VISIBLE_VIEWLAYER)) {
|
||||
te_object->flag |= TE_DISABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue