UI: sub panel titles draw smaller and indented.

This commit is contained in:
Brecht Van Lommel
2018-06-06 13:28:40 +02:00
parent f55f418867
commit bb09556be5
3 changed files with 34 additions and 10 deletions

View File

@@ -828,6 +828,7 @@ struct Panel *UI_panel_begin(struct ScrArea *sa, struct ARegion *ar, struct List
bool *r_open);
void UI_panel_end(uiBlock *block, int width, int height);
void UI_panels_scale(struct ARegion *ar, float new_width);
void UI_panel_label_offset(struct uiBlock *block, int *x, int *y);
bool UI_panel_category_is_visible(struct ARegion *ar);
void UI_panel_category_add(struct ARegion *ar, const char *name);

View File

@@ -612,6 +612,20 @@ static void ui_draw_panel_dragwidget(unsigned int pos, unsigned int col, const r
immEnd();
}
/* For button layout next to label. */
void UI_panel_label_offset(uiBlock *block, int *x, int *y)
{
Panel *panel = block->panel;
uiStyle *style = UI_style_get_dpi();
const bool is_subpanel = (panel->type && panel->type->parent);
*x = UI_UNIT_X * 1.1f;
*y = (UI_UNIT_Y * 1.1f) + style->panelspace;
if (is_subpanel) {
*x += 5.0f / block->aspect;
}
}
static void ui_draw_aligned_panel_header(uiStyle *style, uiBlock *block, const rcti *rect, char dir)
{
@@ -619,6 +633,8 @@ static void ui_draw_aligned_panel_header(uiStyle *style, uiBlock *block, const r
rcti hrect;
int pnl_icons;
const char *activename = panel->drawname[0] ? panel->drawname : panel->panelname;
const bool is_subpanel = (panel->type && panel->type->parent);
uiFontStyle *fontstyle = (is_subpanel) ? &style->widgetlabel : &style->paneltitle;
unsigned char col_title[4];
/* + 0.001f to avoid flirting with float inaccuracy */
@@ -635,14 +651,14 @@ static void ui_draw_aligned_panel_header(uiStyle *style, uiBlock *block, const r
if (dir == 'h') {
hrect.xmin = rect->xmin + pnl_icons;
hrect.ymin += 2.0f / block->aspect;
UI_fontstyle_draw(&style->paneltitle, &hrect, activename, col_title);
UI_fontstyle_draw(fontstyle, &hrect, activename, col_title);
}
else {
/* ignore 'pnl_icons', otherwise the text gets offset horizontally
* + 0.001f to avoid flirting with float inaccuracy
*/
hrect.xmin = rect->xmin + (PNL_ICON + 5) / block->aspect + 0.001f;
UI_fontstyle_draw_rotated(&style->paneltitle, &hrect, activename, col_title);
UI_fontstyle_draw_rotated(fontstyle, &hrect, activename, col_title);
}
}
@@ -667,6 +683,11 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
headrect.ymin = headrect.ymax;
headrect.ymax = headrect.ymin + floor(PNL_HEADER / block->aspect + 0.001f);
rcti titlerect = headrect;
if (is_subpanel) {
titlerect.xmin += 5.0f / block->aspect;
}
unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
@@ -738,7 +759,7 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
/* horizontal title */
if (is_closed_x == false) {
ui_draw_aligned_panel_header(style, block, &headrect, 'h');
ui_draw_aligned_panel_header(style, block, &titlerect, 'h');
if (show_drag) {
unsigned int col;
@@ -817,10 +838,10 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
/* draw collapse icon */
/* itemrect smaller */
itemrect.xmin = headrect.xmin + 3.0f / block->aspect;
itemrect.xmax = itemrect.xmin + BLI_rcti_size_y(&headrect);
itemrect.ymin = headrect.ymin;
itemrect.ymax = headrect.ymax;
itemrect.xmin = titlerect.xmin + 3.0f / block->aspect;
itemrect.xmax = itemrect.xmin + BLI_rcti_size_y(&titlerect);
itemrect.ymin = titlerect.ymin;
itemrect.ymax = titlerect.ymax;
BLI_rctf_scale(&itemrect, 0.25f);

View File

@@ -1825,19 +1825,21 @@ static void ed_panel_draw(const bContext *C,
panel = UI_panel_begin(sa, ar, lb, block, pt, panel, &open);
/* bad fixed values */
int triangle = (int)(UI_UNIT_Y * 1.1f);
int xco, yco, h = 0;
if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
int labelx, labely;
UI_panel_label_offset(block, &labelx, &labely);
/* 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);
labelx, labely, UI_UNIT_Y, 1, 0, style);
pt->draw_header(C, panel);
UI_block_layout_resolve(block, &xco, &yco);
panel->labelofs = xco - triangle;
panel->labelofs = xco - labelx;
panel->layout = NULL;
}
else {