UI: Improve/correct vertical widget positioning in header-like regions
There was code to vertically offset layouts in header-like regions to ensure widgets are centered properly. It wasn't clear why this was necessary so far. I noticed this is region alignment dependent though: The offset is only needed when the upper region edge matches the upper area edge. I'm not entirely sure if it is the edge drawing or a slightly smaller drawable surface of the region (clipped to be 1px less than the area height), think it is the latter. But either way, this offsetting makes a lot more sense now. Fix is to only apply the offset for regions sharing the upper edge with the area. Edges at the window differ a bit, so the offset is not applied there. Fixes the slightly off vertical positioning of widgets in the asset shelf header.
This commit is contained in:
@@ -3464,6 +3464,31 @@ bool ED_region_property_search(const bContext *C,
|
||||
return has_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The drawable part of the region might be slightly smaller because of area edges. This is
|
||||
* especially visible for header-like regions, where vertical space around widgets is small, and
|
||||
* it's quite visible when widgets aren't centered properly.
|
||||
*/
|
||||
static void layout_coordinates_correct_for_drawable_rect(
|
||||
const wmWindow *win, const ScrArea *area, const ARegion *region, int * /*r_xco*/, int *r_yco)
|
||||
{
|
||||
/* Don't do corrections at the window borders where the region rectangles are clipped already. */
|
||||
{
|
||||
rcti win_rect;
|
||||
WM_window_rect_calc(win, &win_rect);
|
||||
if (region->winrct.ymin == win_rect.ymin) {
|
||||
return;
|
||||
}
|
||||
if (region->winrct.ymax == (win_rect.ymax - 1)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (region->winrct.ymax == area->totrct.ymax) {
|
||||
*r_yco -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ED_region_header_layout(const bContext *C, ARegion *region)
|
||||
{
|
||||
const uiStyle *style = UI_style_get_dpi();
|
||||
@@ -3478,11 +3503,8 @@ void ED_region_header_layout(const bContext *C, ARegion *region)
|
||||
int yco = buttony + (region->winy - buttony) / 2;
|
||||
int maxco = xco;
|
||||
|
||||
/* XXX workaround for 1 px alignment issue. Not sure what causes it...
|
||||
* Would prefer a proper fix - Julian */
|
||||
if (!ELEM(CTX_wm_area(C)->spacetype, SPACE_TOPBAR, SPACE_STATUSBAR)) {
|
||||
yco -= 1;
|
||||
}
|
||||
layout_coordinates_correct_for_drawable_rect(
|
||||
CTX_wm_window(C), CTX_wm_area(C), region, &xco, &yco);
|
||||
|
||||
/* set view2d view matrix for scrolling (without scrollers) */
|
||||
UI_view2d_view_ortho(®ion->v2d);
|
||||
|
||||
Reference in New Issue
Block a user