[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48668] branches/soc-2012-bratwurst: Support for columns to lay out items in the center or bottom.

Jorge Rodriguez bs.vino at gmail.com
Fri Jul 6 02:33:12 CEST 2012


Revision: 48668
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48668
Author:   vino
Date:     2012-07-06 00:33:09 +0000 (Fri, 06 Jul 2012)
Log Message:
-----------
Support for columns to lay out items in the center or bottom. Currently it's only used for the 3d view so it uses the entire region height to calculate, this may not work in other cases.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py
    branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h
    branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ui.c

Modified: branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py
===================================================================
--- branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py	2012-07-05 22:47:38 UTC (rev 48667)
+++ branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d.py	2012-07-06 00:33:09 UTC (rev 48668)
@@ -2704,19 +2704,22 @@
 
 
 class VIEW3D_PT_floating_controls(Panel):
-	bl_space_type = 'VIEW_3D'
-	bl_region_type = 'WINDOW'
-	bl_label = "Floating Controls"
-	bl_options = {'HIDE_HEADER'}
+    bl_space_type = 'VIEW_3D'
+    bl_region_type = 'WINDOW'
+    bl_label = "Floating Controls"
+    bl_options = {'HIDE_HEADER'}
 
-	def draw(self, context):
-		layout = self.layout
+    def draw(self, context):
+        layout = self.layout
+        layout.alignment = 'BOTTOM'
 
-		col = layout.column(align=True)
-		col.label(text="Transform:")
-		#col.operator("transform.translate")
-		#col.operator("transform.rotate")
-		#col.operator("transform.resize", text="Scale")
+        row = layout.row(align=True)
+        row.alignment = 'CENTER'
+        row.scale_x = 1.5
+        row.scale_y = 1.5
+        row.operator("transform.translate", text="", icon='MAN_TRANS')
+        row.operator("transform.rotate", text="", icon='MAN_ROT')
+        row.operator("transform.resize", text="", icon='MAN_SCALE')
 
 
 

Modified: branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h	2012-07-05 22:47:38 UTC (rev 48667)
+++ branches/soc-2012-bratwurst/source/blender/editors/include/UI_interface.h	2012-07-06 00:33:09 UTC (rev 48668)
@@ -670,6 +670,8 @@
 #define UI_LAYOUT_ALIGN_LEFT    1
 #define UI_LAYOUT_ALIGN_CENTER  2
 #define UI_LAYOUT_ALIGN_RIGHT   3
+#define UI_LAYOUT_ALIGN_TOP     4
+#define UI_LAYOUT_ALIGN_BOTTOM  5
 
 #define UI_ITEM_O_RETURN_PROPS  1
 #define UI_ITEM_R_EXPAND        2

Modified: branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c	2012-07-05 22:47:38 UTC (rev 48667)
+++ branches/soc-2012-bratwurst/source/blender/editors/interface/interface_layout.c	2012-07-06 00:33:09 UTC (rev 48668)
@@ -1831,9 +1831,19 @@
 
 static void ui_litem_layout_column(uiLayout *litem)
 {
+	ARegion *ar = CTX_wm_region(litem->root->block->evil_C);
 	uiItem *item;
-	int itemh, x, y;
+	int itemh, x, y, offset;
+	int ar_height = ar?(ar->v2d.cur.ymax-ar->v2d.cur.ymin):0;
+	int total_height = 0, num_controls = 0;
 
+	for (item = litem->items.first; item; item = item->next) {
+		ui_item_size(item, NULL, &itemh);
+
+		total_height += itemh;
+		num_controls++;
+	}
+
 	x = litem->x;
 	y = litem->y;
 
@@ -1841,8 +1851,19 @@
 		ui_item_size(item, NULL, &itemh);
 
 		y -= itemh;
-		ui_item_position(item, x, y, litem->w, itemh);
 
+		/* align right/center */
+		offset = 0;
+		if (ar)
+		{
+			if (litem->alignment == UI_LAYOUT_ALIGN_BOTTOM)
+				offset = -ar_height + total_height + litem->space*(num_controls+2);	// add space to offset the space given on the top
+			else if (litem->alignment == UI_LAYOUT_ALIGN_CENTER)
+				offset = (-ar_height + total_height)/2 + litem->space*(num_controls/2+1);
+		}
+
+		ui_item_position(item, x, y + offset, litem->w, itemh);
+
 		if (item->next)
 			y -= litem->space;
 	}
@@ -1853,9 +1874,20 @@
 }
 
 /* root layout */
-static void ui_litem_estimate_root(uiLayout *UNUSED(litem))
+static void ui_litem_estimate_root(uiLayout *litem)
 {
-	/* nothing to do */
+	if (litem->root->type == UI_LAYOUT_HEADER)
+	{
+		int h = litem->h;
+		ui_litem_estimate_row(litem);
+		litem->h = h;
+	}
+	else
+	{
+		int w = litem->w;
+		ui_litem_estimate_column(litem);
+		litem->w = w;
+	}
 }
 
 static void ui_litem_layout_root(uiLayout *litem)

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ui.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ui.c	2012-07-05 22:47:38 UTC (rev 48667)
+++ branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_ui.c	2012-07-06 00:33:09 UTC (rev 48668)
@@ -599,6 +599,8 @@
 		{UI_LAYOUT_ALIGN_LEFT, "LEFT", 0, "Left", ""},
 		{UI_LAYOUT_ALIGN_CENTER, "CENTER", 0, "Center", ""},
 		{UI_LAYOUT_ALIGN_RIGHT, "RIGHT", 0, "Right", ""},
+		{UI_LAYOUT_ALIGN_TOP, "TOP", 0, "Top", ""},
+		{UI_LAYOUT_ALIGN_BOTTOM, "BOTTOM", 0, "Bottom", ""},
 		{0, NULL, 0, NULL, NULL}
 	};
 	




More information about the Bf-blender-cvs mailing list