[Bf-blender-cvs] [658a7cb] ui_layout_gridflow: Fix gridflow layout logic, and building with bplayer.
Bastien Montagne
noreply at git.blender.org
Sun Dec 4 12:45:56 CET 2016
Commit: 658a7cb46faa1c080385ae02af5b994cb1e0adde
Author: Bastien Montagne
Date: Tue Nov 29 11:52:22 2016 +0100
Branches: ui_layout_gridflow
https://developer.blender.org/rB658a7cb46faa1c080385ae02af5b994cb1e0adde
Fix gridflow layout logic, and building with bplayer.
Also add the 'modulo' option for columns number (i.e. set number
automatically, but only allow multiples of given number).
Notes: changes to properties_data_mesh.py are just for testing
obviously, will be reverted for final patch!
===================================================================
M release/scripts/startup/bl_ui/properties_data_mesh.py
M source/blender/editors/interface/interface_layout.c
M source/blender/makesrna/intern/rna_ui_api.c
M source/blenderplayer/bad_level_call_stubs/stubs.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 5990769..c7b931e 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -213,6 +213,20 @@ class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
+ gflow = layout.grid_flow(row_major=True, num_columns=-2, align=True, even_columns=False, even_rows=True)
+ for vg in ob.vertex_groups:
+ gflow.prop(vg, "name", text="")
+ gflow.prop(vg, "lock_weight")
+
+ layout.separator()
+
+ gflow = layout.grid_flow(row_major=False, num_columns=-2, align=True, even_columns=False, even_rows=True)
+ for vg in ob.vertex_groups:
+ gflow.prop(vg, "name", text="")
+ gflow.prop(vg, "lock_weight")
+
+ layout.separator()
+
if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
row = layout.row()
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index a3e77bd..2c7a23c 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -2574,11 +2574,24 @@ static void ui_litem_estimate_grid_flow(uiLayout *litem)
gflow->tot_columns = 1;
}
else {
- gflow->tot_columns = min_ii(max_ii((int)(litem->root->emw / avg_w), 1), gflow->tot_items);
+ gflow->tot_columns = min_ii(max_ii((int)(litem->w / avg_w), 1), gflow->tot_items);
}
}
gflow->tot_rows = (int)ceilf((float)gflow->tot_items / gflow->tot_columns);
+ if (!gflow->row_major && gflow->num_columns <= 0) {
+ /* In column major case, we may need to adjust number of columns, e.g. with 8 items, if we auto-compute
+ * 5 columns, we can only actually fill 4 of them (since we need 2 rows anyway)... */
+ gflow->tot_columns = (int)ceilf((float)gflow->tot_items / gflow->tot_rows);
+ }
+
+ if (gflow->num_columns < -1) {
+ const int modulo = -gflow->num_columns;
+ gflow->tot_columns = max_ii(modulo, gflow->tot_columns - (gflow->tot_columns % modulo));
+ /* Might have changed on the road... */
+ gflow->tot_rows = (int)ceilf((float)gflow->tot_items / gflow->tot_columns);
+ }
+
/* Set evenly-spaced axes size. */
if (gflow->even_columns) {
litem->w = (int)(gflow->tot_columns * avg_w) + style->columnspace * (gflow->tot_columns - 1);
@@ -2625,7 +2638,7 @@ static void ui_litem_estimate_grid_flow(uiLayout *litem)
avg_dim1 += (float)(item_dim1 * item_dim1);
totweight_dim1 += (float)item_dim1;
- if (index_dim2 == num_dim2 - 1) {
+ if (index_dim2 == num_dim2 - 1 || i == gflow->tot_items - 1) {
/* End of a set in first dimension (i.e. end of a row if row_major, of a column otherwise). */
tot_dim1 += (int)(avg_dim1 / totweight_dim1);
avg_dim1 = totweight_dim1 = 0.0f;
@@ -2700,8 +2713,8 @@ static void ui_litem_layout_grid_flow(uiLayout *litem)
even_h = (int)ceilf(avg_h);
for (int row = 0; row < gflow->tot_rows; row++) {
- heights[row] = even_h * row;
- y_cos[row] = litem->y - (even_h + style->buttonspacey) * row;
+ heights[row] = even_h;
+ y_cos[row] = litem->y - even_h * (row + 1) - style->buttonspacey * row;
}
}
@@ -2784,15 +2797,15 @@ static void ui_litem_layout_grid_flow(uiLayout *litem)
}
if (!gflow->even_rows) {
for (int row = 0; row < gflow->tot_rows; row++) {
- y_cos[row] = row ? y_cos[row - 1] - heights[row - 1] - style->buttonspacey : litem->y;
heights[row] = (int)(gflow->row_major ? avg_dim1[row] : avg_dim2[row]);
+ y_cos[row] = row ? y_cos[row - 1] - heights[row - 1] - style->buttonspacey : litem->y - heights[row];
}
}
}
for (item = litem->items.first, i = 0; item; item = item->next, i++) {
- const int col = gflow->row_major ? i % gflow->tot_columns : i / gflow->tot_columns;
- const int row = gflow->row_major ? i / gflow->tot_rows : i % gflow->tot_rows;
+ const int col = gflow->row_major ? i % gflow->tot_columns : i / gflow->tot_rows;
+ const int row = gflow->row_major ? i / gflow->tot_columns : i % gflow->tot_rows;
int item_w, item_h;
ui_item_size(item, &item_w, &item_h);
@@ -2805,7 +2818,7 @@ static void ui_litem_layout_grid_flow(uiLayout *litem)
ui_item_position(item, x_cos[col], y_cos[row], item_w, item_h);
}
- litem->h = (litem->y - y_cos[gflow->tot_columns - 1]) + heights[gflow->tot_rows - 1];
+ litem->h = litem->y - y_cos[gflow->tot_rows - 1];
litem->x = (x_cos[gflow->tot_columns - 1] - litem->x) + widths[gflow->tot_columns - 1];
litem->y = litem->y - litem->h;
}
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index d6c9bc4..6fa5058 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -456,7 +456,10 @@ void RNA_api_ui_layout(StructRNA *srna)
func = RNA_def_function(srna, "grid_flow", "uiLayoutGridFlow");
RNA_def_boolean(func, "row_major", false, "", "Fill row by row, instead of column by column");
- RNA_def_int(func, "num_columns", 0, 0, INT_MAX, "", "Number of columns, 0 is automatic", 0, INT_MAX);
+ RNA_def_int(func, "num_columns", 0, INT_MIN, INT_MAX, "",
+ "Number of columns, positive are absolute fixed numbers, 0 is automatic, negative are "
+ "automatic multiple numbers (e.g. -2 will only produce 2, 4, 6 etc. columns layout)",
+ INT_MIN, INT_MAX);
RNA_def_boolean(func, "align", false, "", "Align buttons to each other");
RNA_def_boolean(func, "even_columns", false, "", "All columns will have the same width");
RNA_def_boolean(func, "even_rows", false, "", "All rows will have the same height");
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c
index 6040dff..cb094d3 100644
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ b/source/blenderplayer/bad_level_call_stubs/stubs.c
@@ -569,6 +569,7 @@ PointerRNA uiItemFullO_ptr(struct uiLayout *layout, struct wmOperatorType *ot, c
struct uiLayout *uiLayoutRow(uiLayout *layout, int align) RET_NULL
struct uiLayout *uiLayoutColumn(uiLayout *layout, int align) RET_NULL
struct uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, int align) RET_NULL
+struct uiLayout *uiLayoutGridFlow(uiLayout *layout, int row_major, int num_columns, int align, int even_columns, int even_rows) RET_NULL
struct uiLayout *uiLayoutBox(struct uiLayout *layout) RET_NULL
struct uiLayout *uiLayoutSplit(uiLayout *layout, float percentage, int align) RET_NULL
bool uiLayoutGetRedAlert(struct uiLayout *layout) RET_ZERO
More information about the Bf-blender-cvs
mailing list