File Browser: Scroll view on normal selection too

Adjusts view after mouse/border selection if some selected items are out of view bounds.
To get as much of the selection into view as possible, this adjusts view first for the last, then for the first element in the selection.
Also, if region is pretty small, view adjustment is skipped, as otherwise the view is focused on the first element only, which isn't really useful IMHO.

Maybe not so nice: Since we do two view alignment iterations, UI_view2d_curRect_validate, which is a rather big function *might* be called twice under certain circumstances (border select & total size of selected elements is exceeds view bounds). I think that's totally acceptable though.
This commit is contained in:
Julian Eisel 2015-09-19 04:24:48 +02:00
parent d7e88fe1fd
commit 36d64240e6
Notes: blender-bot 2023-02-14 08:47:25 +01:00
Referenced by issue #46175, Screen not slide in File Browser with Arrow-key navigation
Referenced by issue #46166, Rendering only takes into account the render border of the current scene when compositing
Referenced by issue #46155, Sequencer Text Effect: wrong vertical 'TOP' alignment
1 changed files with 14 additions and 0 deletions

View File

@ -305,6 +305,20 @@ static FileSelect file_select(bContext *C, const rcti *rect, FileSelType select,
if (select != FILE_SEL_ADD && !file_is_any_selected(sfile->files)) {
sfile->params->active_file = -1;
}
else {
ARegion *ar = CTX_wm_region(C);
const FileLayout *layout = ED_fileselect_get_layout(sfile, ar);
/* Adjust view to display selection. Doing iterations for first and last
* selected item makes view showing as much of the selection possible.
* Not really useful if tiles are (almost) bigger than viewbounds though. */
if (((layout->flag & FILE_LAYOUT_HOR) && ar->winx > (1.2f * layout->tile_w)) ||
((layout->flag & FILE_LAYOUT_VER) && ar->winy > (2.0f * layout->tile_h)))
{
file_ensure_inside_viewbounds(ar, sfile, sel.last);
file_ensure_inside_viewbounds(ar, sfile, sel.first);
}
}
/* update operator for name change event */
file_draw_check(C);