UI: Hide & shrink scroll-bars based on cursor position

Scroll-bars are now hidden unless the cursor approaches them, in which case they
smoothly grow and become more & more visible. Note that since 0d309144020168e55,
scroll-bars are drawn on top of editor contents. There's no more jumping of
buttons when scroll-bars appear.

Technical notes:
* AZones are used to adjust scrollbars based on mouse movements

  We may want to support screen level AZones if we want scrollbars to also
  smoothly appear when approaching them from a different area.
  I also plan to make further changes to AZones to clean up stuff a bit.
* Had to move AZone handling to a post ARegion init stage, since we need the
  updated View2D data from there.
* View2D masks and scroller rectangles are now updated on every redraw. It's
  cheap to do that though.
This commit is contained in:
Julian Eisel
2018-05-07 01:31:18 +02:00
parent 4ec467d3b5
commit 51efeb6834
7 changed files with 214 additions and 50 deletions

View File

@@ -152,10 +152,11 @@ static void view2d_masks(View2D *v2d, bool check_scrollers)
* - if they overlap, they must not occupy the corners (which are reserved for other widgets)
*/
if (scroll) {
const int scroll_width = (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) ?
V2D_SCROLL_WIDTH_TEXT : V2D_SCROLL_WIDTH;
const int scroll_height = (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) ?
V2D_SCROLL_HEIGHT_TEXT : V2D_SCROLL_HEIGHT;
int scroll_width = (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) ? V2D_SCROLL_WIDTH_TEXT : v2d->size_vert;
int scroll_height = (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) ? V2D_SCROLL_HEIGHT_TEXT : v2d->size_hor;
CLAMP_MIN(scroll_width, V2D_SCROLL_WIDTH_MIN);
CLAMP_MIN(scroll_height, V2D_SCROLL_HEIGHT_MIN);
/* vertical scroller */
if (scroll & V2D_SCROLL_LEFT) {
@@ -357,6 +358,11 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
/* set masks (always do), but leave scroller scheck to totrect_set */
view2d_masks(v2d, 0);
if (do_init) {
/* Visible by default. */
v2d->alpha_hor = v2d->alpha_vert = 255;
}
/* set 'tot' rect before setting cur? */
/* XXX confusing stuff here still - I made this function not check scroller hide - that happens in totrect_set */
if (tot_changed)
@@ -1641,6 +1647,9 @@ View2DScrollers *UI_view2d_scrollers_calc(
/* scrollers is allocated here... */
scrollers = MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
/* Always update before drawing (for dynamically sized scrollers). */
view2d_masks(v2d, false);
vert = v2d->vert;
hor = v2d->hor;
@@ -1804,9 +1813,11 @@ static void scroll_printstr(Scene *scene, float x, float y, float val, int power
/* Draw scrollbars in the given 2d-region */
void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *vs)
{
bTheme *btheme = UI_GetTheme();
Scene *scene = CTX_data_scene(C);
rcti vert, hor;
int scroll = view2d_scroll_mapped(v2d->scroll);
const int scroll = view2d_scroll_mapped(v2d->scroll);
const char emboss_alpha = btheme->tui.widget_emboss[3];
unsigned char scrollers_back_color[4];
/* Color for scrollbar backs */
@@ -1818,8 +1829,8 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
/* horizontal scrollbar */
if (scroll & V2D_SCROLL_HORIZONTAL) {
bTheme *btheme = UI_GetTheme();
uiWidgetColors wcol = btheme->tui.wcol_scroll;
const float alpha_fac = v2d->alpha_hor / 255.0f;
rcti slider;
int state;
@@ -1830,6 +1841,11 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
state = (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE) ? UI_SCROLL_PRESSED : 0;
wcol.inner[3] *= alpha_fac;
wcol.item[3] *= alpha_fac;
wcol.outline[3] *= alpha_fac;
btheme->tui.widget_emboss[3] *= alpha_fac; /* will be reset later */
/* show zoom handles if:
* - zooming on x-axis is allowed (no scroll otherwise)
* - slider bubble is large enough (no overdraw confusion)
@@ -1916,9 +1932,9 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
/* vertical scrollbar */
if (scroll & V2D_SCROLL_VERTICAL) {
bTheme *btheme = UI_GetTheme();
uiWidgetColors wcol = btheme->tui.wcol_scroll;
rcti slider;
const float alpha_fac = v2d->alpha_vert / 255.0f;
int state;
slider.xmin = vert.xmin;
@@ -1928,6 +1944,11 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
state = (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE) ? UI_SCROLL_PRESSED : 0;
wcol.inner[3] *= alpha_fac;
wcol.item[3] *= alpha_fac;
wcol.outline[3] *= alpha_fac;
btheme->tui.widget_emboss[3] *= alpha_fac; /* will be reset later */
/* show zoom handles if:
* - zooming on y-axis is allowed (no scroll otherwise)
* - slider bubble is large enough (no overdraw confusion)
@@ -1990,6 +2011,8 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
}
}
/* Was changed above, so reset. */
btheme->tui.widget_emboss[3] = emboss_alpha;
}
/* free temporary memory used for drawing scrollers */