UI:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 7 Jun 2009 13:20:41 +0000 (13:20 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 7 Jun 2009 13:20:41 +0000 (13:20 +0000)
* layout.split() now takes a percentage argument to control
  the split position.
* ID template now works for more than just the Text ID type,
  includes and icon, and some other fixes.

release/ui/space_text.py
source/blender/editors/include/UI_interface.h
source/blender/editors/include/UI_resources.h
source/blender/editors/interface/interface_api.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_utils.c

index d4187c10b69beb752ad3938705f2059efcf234f1..5c6c5c0d21b18cad0c438345d9a5c94a4f50f861 100644 (file)
@@ -38,7 +38,7 @@ class TEXT_HT_header(bpy.types.Header):
                row.itemR(st, "syntax_highlight", text="", icon=ICON_SYNTAX_OFF)
                # row.itemR(st, "do_python_plugins", text="", icon=ICON_SCRIPTPLUGINS)
 
-               layout.template_header_ID(context, st, "text", new="TEXT_OT_new", open="TEXT_OT_open", unlink="TEXT_OT_unlink")
+               layout.template_ID(context, st, "text", new="TEXT_OT_new", open="TEXT_OT_open", unlink="TEXT_OT_unlink")
 
                if text:
                        row = layout.row()
index 53fcf581f7eca66c23b5816603cdf26e8671f938..cb105f2ea3ef4ffaa066424b7d5ec0f0e64062a0 100644 (file)
@@ -594,13 +594,13 @@ uiLayout *uiLayoutColumn(uiLayout *layout, int align);
 uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, int align);
 uiLayout *uiLayoutBox(uiLayout *layout);
 uiLayout *uiLayoutFree(uiLayout *layout, int align);
-uiLayout *uiLayoutSplit(uiLayout *layout);
+uiLayout *uiLayoutSplit(uiLayout *layout, float percentage);
 
 uiBlock *uiLayoutFreeBlock(uiLayout *layout);
 
 /* templates */
 void uiTemplateHeader(uiLayout *layout, struct bContext *C);
-void uiTemplateHeaderID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname,
+void uiTemplateID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, char *propname,
        char *newop, char *openop, char *unlinkop);
 uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr);
 uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
index 5339a255dbcbd4fcc7603dd58d00021949ae3911..6fa0eb90c5fc423722d9b90dc24382b52b410d18 100644 (file)
@@ -83,8 +83,8 @@ typedef enum {
        ICON_CHECKBOX_HLT,
        ICON_UNLOCKED,
        ICON_LOCKED,
-       ICON_BLANK013,
-       ICON_BLANK014,
+       ICON_PINNED,
+       ICON_UNPINNED,
        ICON_BLANK015,
        ICON_RIGHTARROW,
        ICON_DOWNARROW_HLT,
index 5aff0c0ad824ed4f7947e30d8152e88a193459b8..6aed1bc0b524bb7561bceb88e4e52a53e6eb69e2 100644 (file)
@@ -86,6 +86,7 @@ void RNA_api_ui_layout(StructRNA *srna)
        func= RNA_def_function(srna, "split", "uiLayoutSplit");
        parm= RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in.");
        RNA_def_function_return(func, parm);
+       RNA_def_float(func, "percentage", 0.5f, 0.0f, 1.0f, "Percentage", "Percentage of width to split at.", 0.0f, 1.0f);
 
        /* items */
        func= RNA_def_function(srna, "itemR", "uiItemR");
@@ -193,7 +194,7 @@ void RNA_api_ui_layout(StructRNA *srna)
        parm= RNA_def_pointer(func, "context", "Context", "", "Current context.");
        RNA_def_property_flag(parm, PROP_REQUIRED);
 
-       func= RNA_def_function(srna, "template_header_ID", "uiTemplateHeaderID");
+       func= RNA_def_function(srna, "template_ID", "uiTemplateID");
        parm= RNA_def_pointer(func, "context", "Context", "", "Current context.");
        RNA_def_property_flag(parm, PROP_REQUIRED);
        parm= RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property.");
index 8ef1cd32f224d3c486f789f24092557f63c45894..ea576ad726340f88f0cb793002b841e4b1154dba 100644 (file)
@@ -147,17 +147,16 @@ typedef struct uiLayoutItemFlow {
        int totcol;
 } uiLayoutItemFlow;
 
-typedef struct uiLayoutItemSplt {
-       uiLayout litem;
-       int number;
-       int lr;
-} uiLayoutItemSplt;
-
 typedef struct uiLayoutItemBx {
        uiLayout litem;
        uiBut *roundbox;
 } uiLayoutItemBx;
 
+typedef struct uiLayoutItemSplt {
+       uiLayout litem;
+       float percentage;
+} uiLayoutItemSplt;
+
 typedef struct uiLayoutItemRoot {
        uiLayout litem;
 } uiLayoutItemRoot;
@@ -1084,7 +1083,7 @@ static void ui_litem_layout_row(uiLayout *litem)
 
                        x += neww;
 
-                       if(neww < minw && w != 0) {
+                       if((neww < minw || itemw == minw) && w != 0) {
                                /* fixed size */
                                item->flag= 1;
                                fixedw += minw;
@@ -1450,12 +1449,12 @@ static void ui_litem_estimate_split(uiLayout *litem)
 
 static void ui_litem_layout_split(uiLayout *litem)
 {
+       uiLayoutItemSplt *split= (uiLayoutItemSplt*)litem;
        uiItem *item;
        int itemh, x, y, w, tot=0, colw=0;
 
        x= litem->x;
        y= litem->y;
-       w= litem->w;
 
        for(item=litem->items.first; item; item=item->next)
                tot++;
@@ -1463,7 +1462,8 @@ static void ui_litem_layout_split(uiLayout *litem)
        if(tot == 0)
                return;
        
-       colw= (litem->w - (tot-1)*litem->space)/tot;
+       w= (litem->w - (tot-1)*litem->space);
+       colw= w*split->percentage;
        colw= MAX2(colw, 0);
 
        for(item=litem->items.first; item; item=item->next) {
@@ -1472,8 +1472,12 @@ static void ui_litem_layout_split(uiLayout *litem)
                ui_item_position(item, x, y-itemh, colw, itemh);
                x += colw;
 
-               if(item->next)
+               if(item->next) {
+                       colw= (w - (w*split->percentage))/(tot-1);
+                       colw= MAX2(colw, 0);
+
                        x += litem->space;
+               }
        }
 
        litem->w= x - litem->x;
@@ -1589,18 +1593,23 @@ uiBlock *uiLayoutFreeBlock(uiLayout *layout)
        return block;
 }
 
-uiLayout *uiLayoutSplit(uiLayout *layout)
+uiLayout *uiLayoutSplit(uiLayout *layout, float percentage)
 {
-       uiLayout *litem;
+       uiLayoutItemSplt *split;
 
-       litem= uiLayoutRow(layout, 0);
-       litem->item.type = ITEM_LAYOUT_SPLIT;
-       litem->root= layout->root;
-       litem->space= layout->root->style->columnspace;
+       split= MEM_callocN(sizeof(uiLayoutItemSplt), "uiLayoutItemSplt");
+       split->litem.item.type= ITEM_LAYOUT_SPLIT;
+       split->litem.root= layout->root;
+       split->litem.active= 1;
+       split->litem.enabled= 1;
+       split->litem.context= layout->context;
+       split->litem.space= layout->root->style->columnspace;
+       split->percentage= (percentage == 0.0f)? 0.5f: percentage;
+       BLI_addtail(&layout->items, split);
 
-       uiBlockSetCurLayout(layout->root->block, litem);
+       uiBlockSetCurLayout(layout->root->block, &split->litem);
 
-       return litem;
+       return &split->litem;
 }
 
 void uiLayoutSetActive(uiLayout *layout, int active)
index d5b48c3da6dca40dda4fbb84979d7cdd91226c56..1d44fc90ce9c4da36a5d78c8dd73a64190c7a934 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "MEM_guardedalloc.h"
 
@@ -59,7 +60,7 @@ void uiTemplateHeader(uiLayout *layout, bContext *C)
 
 /******************* Header ID Template ************************/
 
-typedef struct TemplateHeaderID {
+typedef struct TemplateID {
        PointerRNA ptr;
        PropertyRNA *prop;
 
@@ -69,14 +70,16 @@ typedef struct TemplateHeaderID {
        char newop[256];
        char openop[256];
        char unlinkop[256];
-} TemplateHeaderID;
+       
+       short idtype;
+} TemplateID;
 
-static void template_header_id_cb(bContext *C, void *arg_litem, void *arg_event)
+static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
 {
-       TemplateHeaderID *template= (TemplateHeaderID*)arg_litem;
+       TemplateID *template= (TemplateID*)arg_litem;
        PointerRNA idptr= RNA_property_pointer_get(&template->ptr, template->prop);
        ID *idtest, *id= idptr.data;
-       ListBase *lb= wich_libbase(CTX_data_main(C), ID_TXT);
+       ListBase *lb= wich_libbase(CTX_data_main(C), template->idtype);
        int nr, event= GET_INT_FROM_POINTER(arg_event);
        
        if(event == UI_ID_BROWSE && template->browse == 32767)
@@ -110,9 +113,10 @@ static void template_header_id_cb(bContext *C, void *arg_litem, void *arg_event)
                        }
                        break;
                }
-#if 0
                case UI_ID_DELETE:
-                       id= NULL;
+                       memset(&idptr, 0, sizeof(idptr));
+                       RNA_property_pointer_set(&template->ptr, template->prop, idptr);
+                       RNA_property_update(C, &template->ptr, template->prop);
                        break;
                case UI_ID_FAKE_USER:
                        if(id) {
@@ -121,7 +125,6 @@ static void template_header_id_cb(bContext *C, void *arg_litem, void *arg_event)
                        }
                        else return;
                        break;
-#endif
                case UI_ID_PIN:
                        break;
                case UI_ID_ADD_NEW:
@@ -145,22 +148,26 @@ static void template_header_id_cb(bContext *C, void *arg_litem, void *arg_event)
        }
 }
 
-static void template_header_ID(bContext *C, uiBlock *block, TemplateHeaderID *template)
+static void template_header_ID(bContext *C, uiBlock *block, TemplateID *template, StructRNA *type)
 {
        uiBut *but;
-       TemplateHeaderID *duptemplate;
+       TemplateID *duptemplate;
        PointerRNA idptr;
        ListBase *lb;
-       int x= 0, y= 0;
 
        idptr= RNA_property_pointer_get(&template->ptr, template->prop);
-       lb= wich_libbase(CTX_data_main(C), ID_TXT);
+       lb= wich_libbase(CTX_data_main(C), template->idtype);
+
+       if(idptr.type)
+               type= idptr.type;
+       if(type)
+               uiDefIconBut(block, LABEL, 0, RNA_struct_ui_icon(type), 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
 
        uiBlockBeginAlign(block);
        if(template->flag & UI_ID_BROWSE) {
                char *extrastr, *str;
                
-               if((template->flag & UI_ID_ADD_NEW) && (template->flag && UI_ID_OPEN))
+               if((template->flag & UI_ID_ADD_NEW) && (template->flag & UI_ID_OPEN))
                        extrastr= "OPEN NEW %x 32766 |ADD NEW %x 32767";
                else if(template->flag & UI_ID_ADD_NEW)
                        extrastr= "ADD NEW %x 32767";
@@ -172,9 +179,8 @@ static void template_header_ID(bContext *C, uiBlock *block, TemplateHeaderID *te
                duptemplate= MEM_dupallocN(template);
                IDnames_to_pupstring(&str, NULL, extrastr, lb, idptr.data, &duptemplate->browse);
 
-               but= uiDefButS(block, MENU, 0, str, x, y, UI_UNIT_X, UI_UNIT_Y, &duptemplate->browse, 0, 0, 0, 0, "Browse existing choices, or add new");
-               uiButSetNFunc(but, template_header_id_cb, duptemplate, SET_INT_IN_POINTER(UI_ID_BROWSE));
-               x+= UI_UNIT_X;
+               but= uiDefButS(block, MENU, 0, str, 0, 0, UI_UNIT_X, UI_UNIT_Y, &duptemplate->browse, 0, 0, 0, 0, "Browse existing choices, or add new");
+               uiButSetNFunc(but, template_id_cb, duptemplate, SET_INT_IN_POINTER(UI_ID_BROWSE));
        
                MEM_freeN(str);
        }
@@ -183,40 +189,46 @@ static void template_header_ID(bContext *C, uiBlock *block, TemplateHeaderID *te
        if(idptr.data) {
                char name[64];
 
-               text_idbutton(idptr.data, name);
-               but= uiDefButR(block, TEX, 0, name, x, y, UI_UNIT_X*6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL);
-               uiButSetNFunc(but, template_header_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
-               x += UI_UNIT_X*6;
+               //text_idbutton(idptr.data, name);
+               name[0]= '\0';
+               but= uiDefButR(block, TEX, 0, name, 0, 0, UI_UNIT_X*6, UI_UNIT_Y, &idptr, "name", -1, 0, 0, -1, -1, NULL);
+               uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_RENAME));
 
                /* delete button */
                if(template->flag & UI_ID_DELETE) {
-                       but= uiDefIconButO(block, BUT, template->unlinkop, WM_OP_EXEC_REGION_WIN, ICON_X, x, y, UI_UNIT_X, UI_UNIT_Y, NULL);
-                       x += UI_UNIT_X;
+                       if(template->unlinkop[0]) {
+                               but= uiDefIconButO(block, BUT, template->unlinkop, WM_OP_EXEC_REGION_WIN, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+                       }
+                       else {
+                               but= uiDefIconBut(block, BUT, 0, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+                               uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_DELETE));
+                       }
                }
        }
        uiBlockEndAlign(block);
 }
 
-void uiTemplateHeaderID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, char *newop, char *openop, char *unlinkop)
+void uiTemplateID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *propname, char *newop, char *openop, char *unlinkop)
 {
-       TemplateHeaderID *template;
+       TemplateID *template;
        uiBlock *block;
        PropertyRNA *prop;
+       StructRNA *type;
 
        if(!ptr->data)
                return;
 
        prop= RNA_struct_find_property(ptr, propname);
 
-       if(!prop) {
-               printf("uiTemplateHeaderID: property not found: %s\n", propname);
+       if(!prop || RNA_property_type(prop) != PROP_POINTER) {
+               printf("uiTemplateID: pointer property not found: %s\n", propname);
                return;
        }
 
-       template= MEM_callocN(sizeof(TemplateHeaderID), "TemplateHeaderID");
+       template= MEM_callocN(sizeof(TemplateID), "TemplateID");
        template->ptr= *ptr;
        template->prop= prop;
-       template->flag= UI_ID_BROWSE|UI_ID_RENAME;
+       template->flag= UI_ID_BROWSE|UI_ID_RENAME|UI_ID_DELETE;
 
        if(newop) {
                template->flag |= UI_ID_ADD_NEW;
@@ -226,13 +238,17 @@ void uiTemplateHeaderID(uiLayout *layout, bContext *C, PointerRNA *ptr, char *pr
                template->flag |= UI_ID_OPEN;
                BLI_strncpy(template->openop, openop, sizeof(template->openop));
        }
-       if(unlinkop) {
-               template->flag |= UI_ID_DELETE;
+       if(unlinkop)
                BLI_strncpy(template->unlinkop, unlinkop, sizeof(template->unlinkop));
-       }
 
-       block= uiLayoutFreeBlock(layout);
-       template_header_ID(C, block, template);
+       type= RNA_property_pointer_type(ptr, prop);
+       template->idtype = RNA_type_to_ID_code(type);
+
+       if(template->idtype) {
+               uiLayoutRow(layout, 1);
+               block= uiLayoutGetBlock(layout);
+               template_header_ID(C, block, template, type);
+       }
 
        MEM_freeN(template);
 }
@@ -1311,19 +1327,20 @@ void uiTemplatePreview(uiLayout *layout, ID *id)
        
        uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
        
-       if(GS(id->name) == ID_MA) {
-               ma= (Material*)id;
-
-               uiLayoutColumn(row, 1);
-
-               uiDefIconButC(block, ROW, B_MATPRV, ICON_MATPLANE,  0, 0,UI_UNIT_X,UI_UNIT_Y, &(ma->pr_type), 10, MA_FLAT, 0, 0, "Preview type: Flat XY plane");
-               uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE, 0, 0, "Preview type: Sphere");
-               uiDefIconButC(block, ROW, B_MATPRV, ICON_MATCUBE,   0, 0,UI_UNIT_X,UI_UNIT_Y, &(ma->pr_type), 10, MA_CUBE, 0, 0, "Preview type: Cube");
-               uiDefIconButC(block, ROW, B_MATPRV, ICON_MONKEY,    0, 0,UI_UNIT_X,UI_UNIT_Y, &(ma->pr_type), 10, MA_MONKEY, 0, 0, "Preview type: Monkey");
-               uiDefIconButC(block, ROW, B_MATPRV, ICON_HAIR,      0, 0,UI_UNIT_X,UI_UNIT_Y, &(ma->pr_type), 10, MA_HAIR, 0, 0, "Preview type: Hair strands");
-               uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE_A, 0, 0, "Preview type: Large sphere with sky");
+       if(id) {
+               if(GS(id->name) == ID_MA) {
+                       ma= (Material*)id;
+
+                       uiLayoutColumn(row, 1);
+
+                       uiDefIconButC(block, ROW, B_MATPRV, ICON_MATPLANE,  0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_FLAT, 0, 0, "Preview type: Flat XY plane");
+                       uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE, 0, 0, "Preview type: Sphere");
+                       uiDefIconButC(block, ROW, B_MATPRV, ICON_MATCUBE,   0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_CUBE, 0, 0, "Preview type: Cube");
+                       uiDefIconButC(block, ROW, B_MATPRV, ICON_MONKEY,    0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_MONKEY, 0, 0, "Preview type: Monkey");
+                       uiDefIconButC(block, ROW, B_MATPRV, ICON_HAIR,      0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_HAIR, 0, 0, "Preview type: Hair strands");
+                       uiDefIconButC(block, ROW, B_MATPRV, ICON_MATSPHERE, 0, 0,UI_UNIT_X*1.5,UI_UNIT_Y, &(ma->pr_type), 10, MA_SPHERE_A, 0, 0, "Preview type: Large sphere with sky");
+               }
        }
-
 }
 
 /********************** ColorRamp Template **************************/
index 97ae2c01c55b27560dd820b23db1afb7cb17bc22..fa7de1151a316a3dadc2f2c88b894984653f4f45 100644 (file)
@@ -155,7 +155,7 @@ void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr)
                if(strcmp(RNA_property_identifier(prop), "rna_type") == 0)
                        continue;
 
-               split = uiLayoutSplit(layout);
+               split = uiLayoutSplit(layout, 0.5f);
 
                name= (char*)RNA_property_ui_name(prop);