Cleanup: Deduplicate Outliner item culling logic

For whatever reason the "in-view" check was using 2x the element height.
From what I can see this isn't needed, so I'll remove it in a follow-up
commit.
This commit is contained in:
Julian Eisel 2022-03-09 15:14:57 +01:00
parent beaf2baeff
commit c4d3d10401
3 changed files with 16 additions and 5 deletions

View File

@ -1721,7 +1721,7 @@ static void outliner_draw_userbuts(uiBlock *block,
LISTBASE_FOREACH (TreeElement *, te, lb) {
TreeStoreElem *tselem = TREESTORE(te);
if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
if (outliner_is_element_in_view(te, &region->v2d)) {
if (tselem->type == TSE_SOME_ID) {
uiBut *bt;
ID *id = tselem->id;
@ -1792,8 +1792,7 @@ static bool outliner_draw_overrides_buts(uiBlock *block,
LISTBASE_FOREACH (TreeElement *, te, lb) {
bool item_has_warnings = false;
const bool do_draw = (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin &&
te->ys <= region->v2d.cur.ymax);
const bool do_draw = outliner_is_element_in_view(te, &region->v2d);
int but_flag = UI_BUT_DRAG_LOCK;
const char *tip = nullptr;
@ -1903,7 +1902,7 @@ static void outliner_draw_rnabuts(
LISTBASE_FOREACH (TreeElement *, te, lb) {
TreeStoreElem *tselem = TREESTORE(te);
if (te->ys + 2 * UI_UNIT_Y >= region->v2d.cur.ymin && te->ys <= region->v2d.cur.ymax) {
if (outliner_is_element_in_view(te, &region->v2d)) {
if (TreeElementRNAProperty *te_rna_prop = tree_element_cast<TreeElementRNAProperty>(te)) {
ptr = te_rna_prop->getPointerRNA();
prop = te_rna_prop->getPropertyRNA();

View File

@ -33,6 +33,7 @@ struct ViewLayer;
struct bContext;
struct bContextDataResult;
struct bPoseChannel;
struct View2D;
struct wmKeyConfig;
struct wmOperatorType;
@ -642,9 +643,15 @@ float outliner_restrict_columns_width(const struct SpaceOutliner *space_outliner
*/
TreeElement *outliner_find_element_with_flag(const ListBase *lb, short flag);
/**
* Find if element is visible in the outliner tree.
* Find if element is visible in the outliner tree, i.e. if all of its parents are expanded.
* Doesn't check if the item is in view-bounds, for that use #outliner_is_element_in_view().
*/
bool outliner_is_element_visible(const TreeElement *te);
/**
* Check if the element is displayed within the view bounds. Doesn't check if all parents are
* open/uncollapsed.
*/
bool outliner_is_element_in_view(const TreeElement *te, const struct View2D *v2d);
/**
* Scroll view vertically while keeping within total bounds.
*/

View File

@ -386,6 +386,11 @@ bool outliner_is_element_visible(const TreeElement *te)
return true;
}
bool outliner_is_element_in_view(const TreeElement *te, const View2D *v2d)
{
return ((te->ys + 2 * UI_UNIT_Y) >= v2d->cur.ymin) && (te->ys <= v2d->cur.ymax);
}
bool outliner_item_is_co_over_name_icons(const TreeElement *te, float view_co_x)
{
/* Special case: count area left of Scene Collection as empty space */