Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2018-06-11 15:33:53 +0300
committerDalai Felinto <dfelinto@gmail.com>2018-06-11 15:46:35 +0300
commitd90fc119c204c760c4c8dcb269706c82bf51ca4b (patch)
tree33059e9bac58118019502a337b1a6436ace6d1c3 /source/blender/editors/interface
parent74051111eb2b0a0453d497018c48b0f33cfa8db7 (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')
-rw-r--r--source/blender/editors/interface/interface.c44
-rw-r--r--source/blender/editors/interface/interface_align.c5
-rw-r--r--source/blender/editors/interface/interface_handlers.c1
-rw-r--r--source/blender/editors/interface/interface_layout.c22
-rw-r--r--source/blender/editors/interface/interface_widgets.c1
5 files changed, 68 insertions, 5 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 */
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c
index 619dce1b9d9..c945746c2df 100644
--- a/source/blender/editors/interface/interface_align.c
+++ b/source/blender/editors/interface/interface_align.c
@@ -111,7 +111,7 @@ enum {
bool ui_but_can_align(const uiBut *but)
{
const bool btype_can_align = !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_CHECKBOX, UI_BTYPE_CHECKBOX_N,
- UI_BTYPE_TAB, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE);
+ UI_BTYPE_TAB, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR_SPACER);
return (btype_can_align && (BLI_rctf_size_x(&but->rect) > 0.0f) && (BLI_rctf_size_y(&but->rect) > 0.0f));
}
@@ -499,7 +499,8 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region)
bool ui_but_can_align(uiBut *but)
{
- return !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_CHECKBOX, UI_BTYPE_CHECKBOX_N, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE);
+ return !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_CHECKBOX, UI_BTYPE_CHECKBOX_N,
+ UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR_SPACER);
}
static bool buts_are_horiz(uiBut *but1, uiBut *but2)
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 43eadc1ee32..02844f5e861 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -7177,6 +7177,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
/* quiet warnings for unhandled types */
case UI_BTYPE_SEPR:
case UI_BTYPE_SEPR_LINE:
+ case UI_BTYPE_SEPR_SPACER:
case UI_BTYPE_EXTRA:
break;
}
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 64d1641be15..f031017c213 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -2216,6 +2216,26 @@ void uiItemS(uiLayout *layout)
uiDefBut(block, (is_menu) ? UI_BTYPE_SEPR_LINE : UI_BTYPE_SEPR, 0, "", 0, 0, space, space, NULL, 0.0, 0.0, 0, 0, "");
}
+/* Flexible spacing. */
+void uiItemSpacer(uiLayout *layout)
+{
+ uiBlock *block = layout->root->block;
+ bool is_menu = ui_block_is_menu(block);
+
+ if (is_menu) {
+ printf("Error: separator_spacer() not supported in menus.\n");
+ return;
+ }
+
+ if (block->direction != UI_DIR_RIGHT) {
+ printf("Error: separator_spacer() only supported in horizontal blocks\n.");
+ return;
+ }
+
+ UI_block_layout_set_current(block, layout);
+ uiDefBut(block, UI_BTYPE_SEPR_SPACER, 0, "", 0, 0, 0.3f * UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
+}
+
/* level items */
void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg)
{
@@ -2599,7 +2619,7 @@ static bool ui_item_is_radial_displayable(uiItem *item)
static bool ui_item_is_radial_drawable(uiButtonItem *bitem)
{
- if (ELEM(bitem->but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE))
+ if (ELEM(bitem->but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE, UI_BTYPE_SEPR_SPACER))
return false;
return true;
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 3188bc847a7..ac8d900f560 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -4423,6 +4423,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
case UI_BTYPE_SEPR:
case UI_BTYPE_SEPR_LINE:
+ case UI_BTYPE_SEPR_SPACER:
break;
case UI_BTYPE_BUT: