diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-06 14:28:40 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-06 17:00:25 +0300 |
commit | bb09556be5d341b6578ee40c30942fbeb0ffb2a3 (patch) | |
tree | a8762132be1896aa448b2ca2578011a8029c25fd | |
parent | f55f418867162994c9a0cf7ba89bed3f27a2a354 (diff) |
UI: sub panel titles draw smaller and indented.
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_panel.c | 35 | ||||
-rw-r--r-- | source/blender/editors/screen/area.c | 8 |
3 files changed, 34 insertions, 10 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index b5d59f42b8d..ee1c4b30eef 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -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); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 3847aa72519..8021495b832 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -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); diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 9a70d6f23de..034ccdf2e7b 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -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 { |