diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2018-04-27 01:49:00 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2018-05-07 12:42:12 +0300 |
commit | 4ec467d3b52744ba2aa4f938973efa27202b23ee (patch) | |
tree | 598d7e8506b68a8a909dd3e427e9eb34810ecd27 /source/blender/editors/screen/area.c | |
parent | 2349b9777a551ac062f7ef9e93a64cfc228d0071 (diff) |
UI: Draw scroll-bars overlapping with editor content
Scroll-bars used to draw in a little extra space in the editor, causing
buttons to jump a bit when they appeared/disappeared. Now they draw on
top of the buttons, just small enough to avoid bigger overlaps. Followup commits
will do further adjustments.
With this we can get rid of a hack that was calling the (often Python
defined) panel definition - the panel 'draw' callback - twice.
Diffstat (limited to 'source/blender/editors/screen/area.c')
-rw-r--r-- | source/blender/editors/screen/area.c | 206 |
1 files changed, 98 insertions, 108 deletions
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 89e22aebed0..58dbebd2b75 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -1986,7 +1986,6 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c View2DScrollers *scrollers; int x, y, xco, yco, w, em, triangle; bool is_context_new = 0; - int redo; int scroll; bool use_category_tabs = (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI)); /* XXX, should use some better check? */ @@ -2064,140 +2063,131 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c } - /* sortof hack - but we cannot predict the height of panels, until it's being generated */ - /* the layout engine works with fixed width (from v2d->cur), which is being set at end of the loop */ - /* in case scroller settings (hide flags) differ from previous, the whole loop gets done again */ - for (redo = 2; redo > 0; redo--) { - - if (vertical) { - w = BLI_rctf_size_x(&v2d->cur); - em = (ar->type->prefsizex) ? 10 : 20; /* works out to 10*UI_UNIT_X or 20*UI_UNIT_X */ - } - else { - w = UI_PANEL_WIDTH; - em = (ar->type->prefsizex) ? 10 : 20; - } + if (vertical) { + w = BLI_rctf_size_x(&v2d->cur); + em = (ar->type->prefsizex) ? 10 : 20; /* works out to 10*UI_UNIT_X or 20*UI_UNIT_X */ + } + else { + w = UI_PANEL_WIDTH; + em = (ar->type->prefsizex) ? 10 : 20; + } - w -= margin_x; - - /* create panels */ - UI_panels_begin(C, ar); + w -= margin_x; - /* set view2d view matrix - UI_block_begin() stores it */ - UI_view2d_view_ortho(v2d); + /* create panels */ + UI_panels_begin(C, ar); - BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt) - { - bool open; + /* set view2d view matrix - UI_block_begin() stores it */ + UI_view2d_view_ortho(v2d); - panel = UI_panel_find_by_type(ar, pt); + BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt) + { + bool open; - if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) { - if ((panel == NULL) || ((panel->flag & PNL_PIN) == 0)) { - continue; - } + panel = UI_panel_find_by_type(ar, pt); + + if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) { + if ((panel == NULL) || ((panel->flag & PNL_PIN) == 0)) { + continue; } + } - /* draw panel */ - block = UI_block_begin(C, ar, pt->idname, UI_EMBOSS); - panel = UI_panel_begin(sa, ar, block, pt, panel, &open); + /* draw panel */ + block = UI_block_begin(C, ar, pt->idname, UI_EMBOSS); + panel = UI_panel_begin(sa, ar, block, pt, panel, &open); - /* bad fixed values */ - triangle = (int)(UI_UNIT_Y * 1.1f); + /* bad fixed values */ + triangle = (int)(UI_UNIT_Y * 1.1f); - if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) { - /* for enabled buttons */ - panel->layout = UI_block_layout( - block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, - triangle, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, 0, style); + if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) { + /* for enabled buttons */ + panel->layout = UI_block_layout( + block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, + triangle, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, 0, style); - pt->draw_header(C, panel); + pt->draw_header(C, panel); - UI_block_layout_resolve(block, &xco, &yco); - panel->labelofs = xco - triangle; - panel->layout = NULL; - } - else { - panel->labelofs = 0; - } + UI_block_layout_resolve(block, &xco, &yco); + panel->labelofs = xco - triangle; + panel->layout = NULL; + } + else { + panel->labelofs = 0; + } - if (open) { - short panelContext; + if (open) { + short panelContext; - /* panel context can either be toolbar region or normal panels region */ - if (ar->regiontype == RGN_TYPE_TOOLS) - panelContext = UI_LAYOUT_TOOLBAR; - else - panelContext = UI_LAYOUT_PANEL; + /* panel context can either be toolbar region or normal panels region */ + if (ar->regiontype == RGN_TYPE_TOOLS) + panelContext = UI_LAYOUT_TOOLBAR; + else + panelContext = UI_LAYOUT_PANEL; - panel->layout = UI_block_layout( - block, UI_LAYOUT_VERTICAL, panelContext, - style->panelspace, 0, w - 2 * style->panelspace, em, 0, style); + panel->layout = UI_block_layout( + block, UI_LAYOUT_VERTICAL, panelContext, + style->panelspace, 0, w - 2 * style->panelspace, em, 0, style); - pt->draw(C, panel); + pt->draw(C, panel); - UI_block_layout_resolve(block, &xco, &yco); - panel->layout = NULL; + UI_block_layout_resolve(block, &xco, &yco); + panel->layout = NULL; + + yco -= 2 * style->panelspace; + UI_panel_end(block, w, -yco); + } + else { + yco = 0; + UI_panel_end(block, w, 0); + } + + UI_block_end(C, block); + } + BLI_SMALLSTACK_ITER_END; - yco -= 2 * style->panelspace; - UI_panel_end(block, w, -yco); + /* align panels and return size */ + UI_panels_end(C, ar, &x, &y); + + /* before setting the view */ + if (vertical) { + /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */ + if (v2d->cur.ymax < -FLT_EPSILON) { + /* Clamp to lower view boundary */ + if (v2d->tot.ymin < -v2d->winy) { + y = min_ii(y, 0); } else { - yco = 0; - UI_panel_end(block, w, 0); + y = min_ii(y, v2d->cur.ymin); } - - UI_block_end(C, block); } - BLI_SMALLSTACK_ITER_END; - /* align panels and return size */ - UI_panels_end(C, ar, &x, &y); - - /* before setting the view */ - if (vertical) { - /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */ - if (v2d->cur.ymax < -FLT_EPSILON) { - /* Clamp to lower view boundary */ - if (v2d->tot.ymin < -v2d->winy) { - y = min_ii(y, 0); - } - else { - y = min_ii(y, v2d->cur.ymin); - } + y = -y; + } + else { + /* don't jump back when panels close or hide */ + if (!is_context_new) { + if (v2d->tot.xmax > v2d->winx) { + x = max_ii(x, 0); } - - y = -y; - } - else { - /* don't jump back when panels close or hide */ - if (!is_context_new) { - if (v2d->tot.xmax > v2d->winx) { - x = max_ii(x, 0); - } - else { - x = max_ii(x, v2d->cur.xmax); - } + else { + x = max_ii(x, v2d->cur.xmax); } - - y = -y; } - - /* this also changes the 'cur' */ - UI_view2d_totRect_set(v2d, x, y); - - if (scroll != v2d->scroll) { - /* Note: this code scales fine, but because of rounding differences, positions of elements - * flip +1 or -1 pixel compared to redoing the entire layout again. - * Leaving in commented code for future tests */ + + y = -y; + } + + /* this also changes the 'cur' */ + UI_view2d_totRect_set(v2d, x, y); + + if (scroll != v2d->scroll) { + /* Note: this code scales fine, but because of rounding differences, positions of elements + * flip +1 or -1 pixel compared to redoing the entire layout again. + * Leaving in commented code for future tests */ #if 0 - UI_panels_scale(ar, BLI_rctf_size_x(&v2d->cur)); - break; + UI_panels_scale(ar, BLI_rctf_size_x(&v2d->cur)); + break; #endif - } - else { - break; - } } region_clear_color(C, ar, (ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK); |