Revision: 19735
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19735
Author:   blendix
Date:     2009-04-15 17:09:36 +0200 (Wed, 15 Apr 2009)

Log Message:
-----------
UI:
* Added simple row template to layout buttons
  in a horizontal row, so you don't need to use
  columns for it.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
    branches/blender2.5/blender/source/blender/editors/interface/interface_api.c
    
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c

Modified: 
branches/blender2.5/blender/source/blender/editors/include/UI_interface.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-04-15 14:43:54 UTC (rev 19734)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_interface.h   
2009-04-15 15:09:36 UTC (rev 19735)
@@ -573,6 +573,7 @@
 #define UI_TSLOT_LR_RIGHT      1
 
 void uiTemplateLeftRight(uiLayout *layout);
+void uiTemplateRow(uiLayout *layout);
 void uiTemplateColumn(uiLayout *layout);
 void uiTemplateColumnFlow(uiLayout *layout, int columns);
 uiLayout *uiTemplateStack(uiLayout *layout);
@@ -588,21 +589,21 @@
 void uiTemplateSlot(uiLayout *layout, int slot);
 
 /* items */
-void uiItemO(uiLayout *layout, const char *name, int icon, char *opname);
-void uiItemEnumO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, int value);
+void uiItemO(uiLayout *layout, char *name, int icon, char *opname);
+void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, int value);
 void uiItemsEnumO(uiLayout *layout, char *opname, char *propname);
-void uiItemBooleanO(uiLayout *layout, const char *name, int icon, char 
*opname, char *propname, int value);
-void uiItemIntO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, int value);
-void uiItemFloatO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, float value);
-void uiItemStringO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, char *value);
-void uiItemFullO(uiLayout *layout, const char *name, int icon, char *idname, 
struct IDProperty *properties, int context);
+void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, int value);
+void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, int value);
+void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, float value);
+void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, char *value);
+void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, struct 
IDProperty *properties, int context);
 
-void uiItemR(uiLayout *layout, const char *name, int icon, struct PointerRNA 
*ptr, char *propname);
-void uiItemFullR(uiLayout *layout, const char *name, int icon, struct 
PointerRNA *ptr, char *propname, int index);
+void uiItemR(uiLayout *layout, char *name, int icon, struct PointerRNA *ptr, 
char *propname);
+void uiItemFullR(uiLayout *layout, char *name, int icon, struct PointerRNA 
*ptr, struct PropertyRNA *prop, int index);
 
-void uiItemL(uiLayout *layout, const char *name, int icon);
+void uiItemL(uiLayout *layout, char *name, int icon);
 
-void uiItemM(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc 
func);
+void uiItemM(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func);
 
 /* utilities */
 #define UI_PANEL_WIDTH                 340

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_api.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_api.c    
    2009-04-15 14:43:54 UTC (rev 19734)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_api.c    
    2009-04-15 15:09:36 UTC (rev 19735)
@@ -58,6 +58,7 @@
        };
 
        /* templates */
+       func= RNA_def_function(srna, "template_row", "uiTemplateRow");
        func= RNA_def_function(srna, "template_column", "uiTemplateColumn");
        func= RNA_def_function(srna, "template_left_right", 
"uiTemplateLeftRight");
 

Modified: 
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- 
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c 
    2009-04-15 14:43:54 UTC (rev 19734)
+++ 
branches/blender2.5/blender/source/blender/editors/interface/interface_layout.c 
    2009-04-15 15:09:36 UTC (rev 19735)
@@ -65,7 +65,7 @@
        uiItemType type;
        int slot;
 
-       const char *name;
+       char *name;
        int icon;
 } uiItem;
 
@@ -94,6 +94,7 @@
 /* Template */
 
 typedef enum uiTemplateType {
+       TEMPLATE_ROW,
        TEMPLATE_COLUMN,
        TEMPLATE_COLUMN_FLOW,
        TEMPLATE_LR,
@@ -254,11 +255,10 @@
        uiBlockEndAlign(block);
 }
 
-/* create lable + button for RNA property */
+/* create label + button for RNA property */
 static void ui_item_with_label(uiBlock *block, uiItemRNA *rnaitem, int x, int 
y, int w, int h)
 {
        char *name;
-       int butw;
 
        if(rnaitem->item.name)
                name= (char*)rnaitem->item.name;
@@ -266,11 +266,9 @@
                name= (char*)RNA_property_ui_name(&rnaitem->ptr, rnaitem->prop);
        
        if(strcmp(name, "") != 0) {
-               butw= GetButStringLength(name);
-               uiDefBut(block, LABEL, 0, name, x, y, butw, h, NULL, 0.0, 0.0, 
0, 0, "");
-
-               x += butw;
-               w -= butw;
+               w= w/2;
+               uiDefBut(block, LABEL, 0, name, x, y, w, h, NULL, 0.0, 0.0, 0, 
0, "");
+               x += w;
        }
 
        uiDefAutoButR(block, &rnaitem->ptr, rnaitem->prop, rnaitem->index, "", 
rnaitem->item.icon, x, y, w, h);
@@ -342,7 +340,7 @@
 }
 
 /* estimated size of text + icon */
-static int ui_text_icon_width(const char *name, int icon)
+static int ui_text_icon_width(char *name, int icon)
 {
        if(icon && name && strcmp(name, "") == 0)
                return XIC; /* icon only */
@@ -357,7 +355,7 @@
 /* estimated size of an item */
 static void ui_item_size(uiItem *item, int *r_w, int *r_h)
 {
-       const char *name;
+       char *name;
        int w, h;
 
        if(item->type == ITEM_RNA_PROPERTY) {
@@ -369,7 +367,7 @@
 
                name= item->name;
                if(!name)
-                       name= RNA_property_ui_name(&rnaitem->ptr, 
rnaitem->prop);
+                       name= (char*)RNA_property_ui_name(&rnaitem->ptr, 
rnaitem->prop);
 
                w= ui_text_icon_width(name, item->icon);
                h= YIC;
@@ -433,7 +431,7 @@
 }
 
 /* operator items */
-void uiItemFullO(uiLayout *layout, const char *name, int icon, char *idname, 
IDProperty *properties, int context)
+void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, 
IDProperty *properties, int context)
 {
        uiTemplate *template= layout->templates.last;
        wmOperatorType *ot= WM_operatortype_find(idname);
@@ -458,7 +456,7 @@
        BLI_addtail(&template->items, opitem);
 }
 
-void uiItemEnumO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, int value)
+void uiItemEnumO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, int value)
 {
        PointerRNA ptr;
 
@@ -491,7 +489,7 @@
        }
 }
 
-void uiItemBooleanO(uiLayout *layout, const char *name, int icon, char 
*opname, char *propname, int value)
+void uiItemBooleanO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, int value)
 {
        PointerRNA ptr;
 
@@ -501,7 +499,7 @@
        uiItemFullO(layout, name, icon, opname, ptr.data, layout->opcontext);
 }
 
-void uiItemIntO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, int value)
+void uiItemIntO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, int value)
 {
        PointerRNA ptr;
 
@@ -511,7 +509,7 @@
        uiItemFullO(layout, name, icon, opname, ptr.data, layout->opcontext);
 }
 
-void uiItemFloatO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, float value)
+void uiItemFloatO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, float value)
 {
        PointerRNA ptr;
 
@@ -521,7 +519,7 @@
        uiItemFullO(layout, name, icon, opname, ptr.data, layout->opcontext);
 }
 
-void uiItemStringO(uiLayout *layout, const char *name, int icon, char *opname, 
char *propname, char *value)
+void uiItemStringO(uiLayout *layout, char *name, int icon, char *opname, char 
*propname, char *value)
 {
        PointerRNA ptr;
 
@@ -531,29 +529,22 @@
        uiItemFullO(layout, name, icon, opname, ptr.data, layout->opcontext);
 }
 
-void uiItemO(uiLayout *layout, const char *name, int icon, char *opname)
+void uiItemO(uiLayout *layout, char *name, int icon, char *opname)
 {
        uiItemFullO(layout, name, icon, opname, NULL, layout->opcontext);
 }
 
 /* RNA property items */
-void uiItemFullR(uiLayout *layout, const char *name, int icon, PointerRNA 
*ptr, char *propname, int index)
+void uiItemFullR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, 
PropertyRNA *prop, int index)
 {
        uiTemplate *template= layout->templates.last;
-       PropertyRNA *prop;
        uiItemRNA *rnaitem;
 
-       if(!ptr->data)
+       if(!ptr->data || !prop)
                return;
        if(!template)
                return;
-       
-       prop= RNA_struct_find_property(ptr, propname);
-       if(!prop){
-               printf("uiItemR: property not found: %s\n",propname);
-               return;
-       }
-       
+
        rnaitem= MEM_callocN(sizeof(uiItemRNA), "uiItemRNA");
 
        rnaitem->item.name= name;
@@ -568,13 +559,24 @@
        BLI_addtail(&template->items, rnaitem);
 }
 
-void uiItemR(uiLayout *layout, const char *name, int icon, PointerRNA *ptr, 
char *propname)
+void uiItemR(uiLayout *layout, char *name, int icon, PointerRNA *ptr, char 
*propname)
 {
-       uiItemFullR(layout, name, icon, ptr, propname, RNA_NO_INDEX);
+       PropertyRNA *prop;
+
+       prop= RNA_struct_find_property(ptr, propname);
+
+       if(!ptr->data)
+               return;
+       if(!prop) {
+               printf("uiItemR: property not found: %s\n",propname);
+               return;
+       }
+       
+       uiItemFullR(layout, name, icon, ptr, prop, RNA_NO_INDEX);
 }
 
 /* menu item */
-void uiItemM(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc 
func)
+void uiItemM(uiLayout *layout, char *name, int icon, uiMenuCreateFunc func)
 {
        uiTemplate *template= layout->templates.last;
        uiItemLMenu *menuitem;
@@ -595,7 +597,7 @@
 }
 
 /* label item */
-void uiItemL(uiLayout *layout, const char *name, int icon)
+void uiItemL(uiLayout *layout, char *name, int icon)
 {
        uiTemplate *template= layout->templates.last;
        uiItem *item;
@@ -653,6 +655,38 @@
        *y= miny;
 }
 
+/* single row layout */
+static void ui_layout_row(uiLayout *layout, uiBlock *block, uiTemplate 
*template, int *x, int *y, int w, int h)
+{
+       uiItem *item;
+       int totw= 0, maxh= 0, itemw, itemh, leftx;
+
+       /* estimate total width of buttons */
+       for(item=template->items.first; item; item=item->next) {
+               ui_item_size(item, &itemw, &itemh);
+               totw += itemw;
+               maxh= MAX2(maxh, itemh);
+       }
+
+       if(totw == 0)
+               return;
+       
+       /* create buttons starting from left */
+       leftx= *x;
+
+       for(item=template->items.first; item; item=item->next) {
+               ui_item_size(item, &itemw, &itemh);
+               if(totw < w)
+                       itemw= (itemw*w)/totw;
+               itemw= ui_item_fit(itemw, MAX2(totw, w), w);
+
+               ui_item_buts(block, item, leftx, *y-itemh, itemw, itemh);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to