diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-06-11 15:33:53 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-06-11 15:46:35 +0300 |
commit | d90fc119c204c760c4c8dcb269706c82bf51ca4b (patch) | |
tree | 33059e9bac58118019502a337b1a6436ace6d1c3 /source/blender/editors/interface/interface.c | |
parent | 74051111eb2b0a0453d497018c48b0f33cfa8db7 (diff) |
UI: Separator spacer
This support layout.separator_spacer() to be used by headers as a way to
dynamically separate the ui buttons.
Right now no UI file is changed, though we can use this right away in the
timeline, and shortly after in the viewport header (moving settings from
the topbar to it).
Original design by William Reynish.
Review: Campbell Barton
D3468
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r-- | source/blender/editors/interface/interface.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 28f4c40469a..811bd4457d8 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -86,6 +86,9 @@ #include "interface_intern.h" +/* prototypes. */ +static void ui_but_to_pixelrect(struct rcti *rect, const struct ARegion *ar, struct uiBlock *block, struct uiBut *but); + /* avoid unneeded calls to ui_but_value_get */ #define UI_BUT_VALUE_UNSET DBL_MAX #define UI_GET_BUT_VALUE_INIT(_but, _value) if (_value == DBL_MAX) { (_value) = ui_but_value_get(_but); } (void)0 @@ -225,6 +228,39 @@ void ui_region_to_window(const ARegion *ar, int *x, int *y) *y += ar->winrct.ymin; } +static void ui_update_flexible_spacing(const ARegion *region, uiBlock *block) +{ + int sepr_flex_len = 0; + for (uiBut *but = block->buttons.first; but; but = but->next) { + if (but->type == UI_BTYPE_SEPR_SPACER) { + sepr_flex_len++; + } + } + + if (sepr_flex_len == 0) { + return; + } + + rcti rect; + ui_but_to_pixelrect(&rect, region, block, block->buttons.last); + const float buttons_width = (float)rect.xmax + UI_HEADER_OFFSET_START; + const float region_width = (float)region->sizex * U.dpi_fac; + + if (region_width <= buttons_width) { + return; + } + + const float spacing = ((region_width - buttons_width) / (float)sepr_flex_len); + float offset = 0; + for (uiBut *but = block->buttons.first; but; but = but->next) { + BLI_rctf_translate(&but->rect, offset, 0); + if (but->type == UI_BTYPE_SEPR_SPACER) { + offset += spacing; + } + } + ui_block_bounds_calc(block); +} + static void ui_update_window_matrix(const wmWindow *window, const ARegion *region, uiBlock *block) { /* window matrix and aspect */ @@ -283,7 +319,7 @@ static void ui_block_bounds_calc_text(uiBlock *block, float offset) UI_fontstyle_set(&style->widget); for (init_col_bt = bt = block->buttons.first; bt; bt = bt->next) { - if (!ELEM(bt->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE)) { + if (!ELEM(bt->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR_SPACER)) { j = BLF_width(style->widget.uifont_id, bt->drawstr, sizeof(bt->drawstr)); if (j > i) @@ -1182,6 +1218,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x { wmWindow *window = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); + ARegion *region = CTX_wm_region(C); uiBut *but; BLI_assert(block->active); @@ -1258,6 +1295,8 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x UI_block_align_end(block); } + ui_update_flexible_spacing(region, block); + block->endblock = 1; } @@ -3225,7 +3264,8 @@ static uiBut *ui_def_but( UI_BTYPE_BLOCK, UI_BTYPE_BUT, UI_BTYPE_LABEL, UI_BTYPE_PULLDOWN, UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX, UI_BTYPE_BUT_MENU, UI_BTYPE_SCROLL, UI_BTYPE_GRIP, - UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE) || + UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, + UI_BTYPE_SEPR_SPACER) || (but->type >= UI_BTYPE_SEARCH_MENU)) { /* pass */ |