[Bf-blender-cvs] [80d8a497027] temp-flexible-spacing: UI: Flexible spacing

Dalai Felinto noreply at git.blender.org
Mon Jun 11 14:19:51 CEST 2018


Commit: 80d8a497027c859befef16788f1934bb3ba01363
Author: Dalai Felinto
Date:   Mon Jun 11 14:18:38 2018 +0200
Branches: temp-flexible-spacing
https://developer.blender.org/rB80d8a497027c859befef16788f1934bb3ba01363

UI: Flexible spacing

This support layout.flexible_spacing() 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).

===================================================================

M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/interface/interface_align.c
M	source/blender/editors/interface/interface_handlers.c
M	source/blender/editors/interface/interface_layout.c
M	source/blender/editors/interface/interface_widgets.c
M	source/blender/editors/screen/area.c
M	source/blender/makesrna/intern/rna_ui_api.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 42b78fa4800..85b79952b07 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -306,6 +306,7 @@ typedef enum {
 	UI_BTYPE_SEPR                   = (54 << 9),
 	UI_BTYPE_SEPR_LINE              = (55 << 9),
 	UI_BTYPE_GRIP                   = (56 << 9),  /* resize handle (resize uilist) */
+	UI_BTYPE_FLEXIBLE_SPACING       = (57 << 9),
 } eButType;
 
 #define BUTTYPE     (63 << 9)
@@ -904,6 +905,7 @@ void UI_exit(void);
 #define UI_ITEM_O_DEPRESS       (1 << 9)
 #define UI_ITEM_R_COMPACT       (1 << 10)
 
+#define UI_HEADER_OFFSET_START ((void)0, 0.4f * UI_UNIT_X)
 
 /* uiLayoutOperatorButs flags */
 enum {
@@ -1126,6 +1128,7 @@ void uiItemLDrag(uiLayout *layout, struct PointerRNA *ptr, const char *name, int
 void uiItemM(uiLayout *layout, struct bContext *C, const char *menuname, const char *name, int icon); /* menu */
 void uiItemV(uiLayout *layout, const char *name, int icon, int argval); /* value */
 void uiItemS(uiLayout *layout); /* separator */
+void uiItemSFlexible(uiLayout *layout); /* Special separator. */
 
 void uiItemPopoverPanel_ptr(
         uiLayout *layout, struct bContext *C,
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 28f4c40469a..743c17bc20e 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 num_spaces = 0;
+	for (uiBut *but = block->buttons.first; but; but = but->next) {
+		if (but->type == UI_BTYPE_FLEXIBLE_SPACING) {
+			num_spaces++;
+		}
+	}
+
+	if (num_spaces == 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)num_spaces);
+	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_FLEXIBLE_SPACING) {
+			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_FLEXIBLE_SPACING)) {
 			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_FLEXIBLE_SPACING) ||
 	    (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..e7981fb31dd 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_FLEXIBLE_SPACING);
 	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_FLEXIBLE_SPACING);
 }
 
 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..0128c0d5fa1 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_FLEXIBLE_SPACING:
 		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..52ba50e93d8 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -2216,6 +2216,20 @@ 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 uiItemSFlexible(uiLayout *layout)
+{
+	uiBlock *block = layout->root->block;
+	bool is_menu = ui_block_is_menu(block);
+
+	if (is_menu) {
+		return;
+	}
+
+	UI_block_layout_set_current(block, layout);
+	uiDefBut(block, UI_BTYPE_FLEXIBLE_SPACING, 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 +2613,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_FLEXIBLE_SPACING))
 		return false;
 
 	return true;
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 3188bc847a7..cf209d75fc2 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_FLEXIBLE_SPACING:
 				break;
 
 			case UI_BTYPE_BUT:
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index b4d932d3272..f73ce24c24b 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -2102,7 +2102,7 @@ void ED_region_header_layout(const bContext *C, ARegion *ar)
 	Header header = {NULL};
 	int maxco, xco, yco;
 	int headery = ED_area_headersize();
-	const int start_ofs = 0.4f * UI_UNIT_X;
+	const int start_ofs = UI_HEADER_OFFSET_START;
 	bool region_layout_based = ar->flag & RGN_FLAG_DYNAMIC_SIZE;
 
 	/* set view2d view matrix for scrolling (without scrollers) */
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index 618a754c1b2..230052e73fc 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -742,6 +742,9 @@ void RNA_api_ui_layout(StructRNA *srna)
 	func = RNA_def_function(srna, "separator", "uiItemS");
 	RNA_def_function_ui_description(func, "Item. Inserts empty space into the layout between items");
 
+	func = RNA_def_function(srna, "flexible_spacing", "uiItemSFlexible");
+	RNA_def_function_ui_description(func, "Item. Inserts horizontal spacing empty space into the layout between items");
+
 	/* context */
 	func = RNA_def_function(srna, "context_pointer_set", "uiLayoutSetContextPointer");
 	parm = RNA_def_string(func, "name", NULL, 0, "Name", "Name of entry in the context");



More information about the Bf-blender-cvs mailing list