Fix 'outliner_scroll_view()' not reaching wanted element

Scrolling to an item after opening relevant parents can go wrong if said
parent e.g. the last in the list [as in: then the Outliner does not
scroll down all the way]
It stems from the fact that 'region->v2d.tot.ymin' is not up-to-date in
outliner_scroll_view after outliner_show_active opens up parents, 'tot'
will only update on a redraw.

Now calculate the trees height on the fly using
'outliner_tree_dimensions()'.

ref D9521
ref T82553

Maniphest Tasks: T82553

Differential Revision: https://developer.blender.org/D9523
This commit is contained in:
Philipp Oeser 2020-11-10 13:53:05 +01:00
parent 12168ccf18
commit 2d48f3e445
Notes: blender-bot 2023-02-14 07:31:32 +01:00
Referenced by issue #82553, Outliner F2 renaiming problem
5 changed files with 15 additions and 10 deletions

View File

@ -109,7 +109,7 @@ static void outliner_tree_dimensions_impl(SpaceOutliner *space_outliner,
}
}
static void outliner_tree_dimensions(SpaceOutliner *space_outliner, int *r_width, int *r_height)
void outliner_tree_dimensions(SpaceOutliner *space_outliner, int *r_width, int *r_height)
{
*r_width = 0;
*r_height = 0;

View File

@ -1343,7 +1343,7 @@ static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
int ytop = (active_element->ys + (size_y / 2));
int delta_y = ytop - v2d->cur.ymax;
outliner_scroll_view(region, delta_y);
outliner_scroll_view(space_outliner, region, delta_y);
}
else {
return OPERATOR_CANCELLED;
@ -1375,6 +1375,7 @@ void OUTLINER_OT_show_active(wmOperatorType *ot)
static int outliner_scroll_page_exec(bContext *C, wmOperator *op)
{
SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
ARegion *region = CTX_wm_region(C);
int size_y = BLI_rcti_size_y(&region->v2d.mask) + 1;
@ -1384,7 +1385,7 @@ static int outliner_scroll_page_exec(bContext *C, wmOperator *op)
size_y = -size_y;
}
outliner_scroll_view(region, size_y);
outliner_scroll_view(space_outliner, region, size_y);
ED_region_tag_redraw_no_rebuild(region);

View File

@ -251,6 +251,8 @@ TreeTraversalAction outliner_find_selected_objects(struct TreeElement *te, void
void draw_outliner(const struct bContext *C);
void outliner_tree_dimensions(struct SpaceOutliner *space_outliner, int *r_width, int *r_height);
TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te);
void outliner_collection_isolate_flag(struct Scene *scene,
@ -525,7 +527,7 @@ bool outliner_tree_traverse(const SpaceOutliner *space_outliner,
float outliner_restrict_columns_width(const struct SpaceOutliner *space_outliner);
TreeElement *outliner_find_element_with_flag(const ListBase *lb, short flag);
bool outliner_is_element_visible(const TreeElement *te);
void outliner_scroll_view(struct ARegion *region, int delta_y);
void outliner_scroll_view(struct SpaceOutliner *space_outliner, struct ARegion *region, int delta_y);
void outliner_tag_redraw_avoid_rebuild_on_open_change(const struct SpaceOutliner *space_outliner,
struct ARegion *region);

View File

@ -1709,7 +1709,7 @@ static TreeElement *find_walk_select_start_element(SpaceOutliner *space_outliner
}
/* Scroll the outliner when the walk element reaches the top or bottom boundary */
static void outliner_walk_scroll(ARegion *region, TreeElement *te)
static void outliner_walk_scroll(SpaceOutliner *space_outliner, ARegion *region, TreeElement *te)
{
/* Account for the header height */
int y_max = region->v2d.cur.ymax - UI_UNIT_Y;
@ -1717,10 +1717,10 @@ static void outliner_walk_scroll(ARegion *region, TreeElement *te)
/* Scroll if walked position is beyond the border */
if (te->ys > y_max) {
outliner_scroll_view(region, te->ys - y_max);
outliner_scroll_view(space_outliner, region, te->ys - y_max);
}
else if (te->ys < y_min) {
outliner_scroll_view(region, -(y_min - te->ys));
outliner_scroll_view(space_outliner, region, -(y_min - te->ys));
}
}
@ -1747,7 +1747,7 @@ static int outliner_walk_select_invoke(bContext *C, wmOperator *op, const wmEven
OL_ITEM_SELECT | OL_ITEM_ACTIVATE | (extend ? OL_ITEM_EXTEND : 0));
/* Scroll outliner to focus on walk element */
outliner_walk_scroll(region, active_te);
outliner_walk_scroll(space_outliner, region, active_te);
ED_outliner_select_sync_from_outliner(C, space_outliner);
outliner_tag_redraw_avoid_rebuild_on_open_change(space_outliner, region);

View File

@ -442,9 +442,11 @@ bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_c
}
/* Scroll view vertically while keeping within total bounds */
void outliner_scroll_view(ARegion *region, int delta_y)
void outliner_scroll_view(SpaceOutliner *space_outliner, ARegion *region, int delta_y)
{
int y_min = MIN2(region->v2d.cur.ymin, region->v2d.tot.ymin);
int tree_width, tree_height;
outliner_tree_dimensions(space_outliner, &tree_width, &tree_height);
int y_min = MIN2(region->v2d.cur.ymin, -tree_height);
region->v2d.cur.ymax += delta_y;
region->v2d.cur.ymin += delta_y;