diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2011-10-28 17:09:43 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2011-10-28 17:09:43 +0400 |
commit | 7627a742ab6e630522186b04a71fa40533d87db2 (patch) | |
tree | 5ba14f7b4c3cbaaad4109713ce0423dc002961aa /source/blender/editors | |
parent | 2ed7a66653c9c94cb47064cb12092c2e81331b9b (diff) |
UI list template: committing patch [#26629].
This adds the ability (esp. for py scripts) to add some controls for each list element. See http://wiki.blender.org/index.php/User:Mont29/UI_Template_List_Enhancement for details.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 52 |
2 files changed, 50 insertions, 4 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index a7ced565403..cb18ea37ffc 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -749,7 +749,7 @@ void uiTemplateTextureImage(uiLayout *layout, struct bContext *C, struct Tex *te void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C); void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr); -void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, int rows, int maxrows, int type); +void uiTemplateList(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *activeptr, const char *activeprop, const char *prop_list, int rows, int maxrows, int type); /* items */ void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index b816d1a8f9c..e714d0bbc17 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -2059,7 +2059,7 @@ static int list_item_icon_get(bContext *C, PointerRNA *itemptr, int rnaicon, int return rnaicon; } -static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop) +static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, PointerRNA *itemptr, int i, int rnaicon, PointerRNA *activeptr, PropertyRNA *activeprop, const char *prop_list) { uiBlock *block= uiLayoutGetBlock(layout); uiBut *but; @@ -2164,6 +2164,52 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe /* nothing else special to do... */ uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */ } + /* There is a last chance to display custom controls (in addition to the name/label): + * If the given item property group features a string property named as prop_list, + * this tries to add controls for all properties of the item listed in that string property. + * (colon-separated names). + * + * This is especially useful for python. E.g., if you list a collection of this property + * group: + * + * class TestPropertyGroup(bpy.types.PropertyGroup): + * bool = BoolProperty(default=False) + * integer = IntProperty() + * string = StringProperty() + * + * # A string of all identifiers (colon-separated) which property’s controls should be + * # displayed in a template_list. + * template_list_controls = StringProperty(default="integer:bool:string", options={"HIDDEN"}) + * + * … you’ll get a numfield for the integer prop, a check box for the bool prop, and a textfield + * for the string prop, after the name of each item of the collection. + */ + else if (prop_list) { + PropertyRNA *prop_ctrls; + row = uiLayoutRow(sub, 1); + uiItemL(row, name, icon); + + /* XXX: Check, as sometimes we get an itemptr looking like + * {id = {data = 0x0}, type = 0x0, data = 0x0} + * which would obviously produce a sigsev… */ + if (itemptr->type) { + /* If the special property is set for the item, and it is a collection… */ + prop_ctrls = RNA_struct_find_property(itemptr, prop_list); + if(prop_ctrls) { + if(RNA_property_type(prop_ctrls) == PROP_STRING) { + char *prop_names = RNA_property_string_get_alloc(itemptr, prop_ctrls, NULL, 0, NULL); + char *id = NULL; + char *ctx = NULL; + for(id = BLI_strtok_r(prop_names, ":", &ctx); id; id = BLI_strtok_r(NULL, ":", &ctx)) { + uiItemR(row, itemptr, id, 0, NULL, 0); + MEM_freeN(id); + } + MEM_freeN(prop_names); + } + } + } + } + else uiItemL(sub, name, icon); /* fails, backdrop LISTROW... */ @@ -2172,7 +2218,7 @@ static void list_item_row(bContext *C, uiLayout *layout, PointerRNA *ptr, Pointe MEM_freeN(namebuf); } -void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, int rows, int maxrows, int listtype) +void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *activeptr, const char *activepropname, const char *prop_list, int rows, int maxrows, int listtype) { //Scene *scene= CTX_data_scene(C); PropertyRNA *prop= NULL, *activeprop; @@ -2326,7 +2372,7 @@ void uiTemplateList(uiLayout *layout, bContext *C, PointerRNA *ptr, const char * /* create list items */ RNA_PROP_BEGIN(ptr, itemptr, prop) { if(i >= pa->list_scroll && i<pa->list_scroll+items) - list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop); + list_item_row(C, col, ptr, &itemptr, i, rnaicon, activeptr, activeprop, prop_list); i++; } |