UI: sub panel titles draw smaller and indented.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 6 Jun 2018 11:28:40 +0000 (13:28 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 6 Jun 2018 14:00:25 +0000 (16:00 +0200)
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface_panel.c
source/blender/editors/screen/area.c

index b5d59f42b8d19eab10fdf0c5eaf1a3663d3f6963..ee1c4b30eefd013b704ee09e9af83ba4e6567f41 100644 (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);
index 3847aa725195b54ab6164c35d5557f28987b7b1d..8021495b832755915831f5bb122ddace7bb585cc 100644 (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);
 
index 9a70d6f23de3dd48ddaabf373f294c11c49a6a87..034ccdf2e7b458481e1b80f184c0096e0d90aac6 100644 (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 {