Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface/interface_utils.c')
-rw-r--r--source/blender/editors/interface/interface_utils.c77
1 files changed, 47 insertions, 30 deletions
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 37278340275..842dc40a39f 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -26,11 +26,14 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "DNA_object_types.h"
+#include "BLI_utildefines.h"
+
#include "BKE_context.h"
-#include "BKE_utildefines.h"
+
#include "RNA_access.h"
@@ -40,7 +43,7 @@
/*************************** RNA Utilities ******************************/
-uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, char *name, int icon, int x1, int y1, int x2, int y2)
+uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, const char *name, int icon, int x1, int y1, int x2, int y2)
{
uiBut *but=NULL;
const char *propname= RNA_property_identifier(prop);
@@ -55,19 +58,11 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
switch(RNA_property_type(prop)) {
case PROP_BOOLEAN: {
- int value, length;
if(arraylen && index == -1)
return NULL;
-
- length= RNA_property_array_length(ptr, prop);
-
- if(length)
- value= RNA_property_boolean_get_index(ptr, prop, index);
- else
- value= RNA_property_boolean_get(ptr, prop);
- if(icon && name && strcmp(name, "") == 0)
+ if(icon && name && name[0] == '\0')
but= uiDefIconButR(block, ICONTOG, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
else if(icon)
but= uiDefIconTextButR(block, ICONTOG, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
@@ -87,7 +82,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
but= uiDefButR(block, NUM, 0, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
break;
case PROP_ENUM:
- if(icon && name && strcmp(name, "") == 0)
+ if(icon && name && name[0] == '\0')
but= uiDefIconButR(block, MENU, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
else if(icon)
but= uiDefIconTextButR(block, MENU, 0, icon, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
@@ -95,7 +90,7 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
break;
case PROP_STRING:
- if(icon && name && strcmp(name, "") == 0)
+ if(icon && name && name[0] == '\0')
but= uiDefIconButR(block, TEX, 0, icon, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
else if(icon)
but= uiDefIconTextButR(block, TEX, 0, icon, name, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
@@ -131,35 +126,57 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
return but;
}
-void uiDefAutoButsRNA(const bContext *C, uiLayout *layout, PointerRNA *ptr, int columns)
+int uiDefAutoButsRNA(uiLayout *layout, PointerRNA *ptr, int (*check_prop)(PropertyRNA *), const char label_align)
{
uiLayout *split, *col;
int flag;
- char *name;
+ const char *name;
+ int tot= 0;
+
+ assert(ELEM3(label_align, '\0', 'H', 'V'));
RNA_STRUCT_BEGIN(ptr, prop) {
flag= RNA_property_flag(prop);
- if(flag & PROP_HIDDEN)
+ if(flag & PROP_HIDDEN || (check_prop && check_prop(prop)==FALSE))
continue;
- name= (char*)RNA_property_ui_name(prop);
+ if(label_align != '\0') {
+ name= RNA_property_ui_name(prop);
- if(columns == 1) {
- col= uiLayoutColumn(layout, 1);
- uiItemL(col, name, 0);
- }
- else if(columns == 2) {
- split = uiLayoutSplit(layout, 0.5f, 0);
+ if(label_align=='V') {
+ col= uiLayoutColumn(layout, 1);
+ uiItemL(col, name, ICON_NULL);
+ }
+ else if(label_align=='H') {
+ split = uiLayoutSplit(layout, 0.5f, 0);
- uiItemL(uiLayoutColumn(split, 0), name, 0);
- col= uiLayoutColumn(split, 0);
+ uiItemL(uiLayoutColumn(split, 0), name, ICON_NULL);
+ col= uiLayoutColumn(split, 0);
+ }
+ else {
+ col= NULL;
+ }
+
+ /* may meed to add more cases here.
+ * don't override enum flag names */
+ if(flag & PROP_ENUM_FLAG) {
+ name= NULL;
+ }
+ else {
+ name= ""; /* name is shown above, empty name for button below */
+ }
+ }
+ else {
+ col= layout;
+ name= NULL; /* no smart label alignment, show default name with button */
}
- else
- col= NULL;
- uiItemFullR(col, ptr, prop, -1, 0, 0, "", 0);
+ uiItemFullR(col, ptr, prop, -1, 0, 0, name, ICON_NULL);
+ tot++;
}
RNA_STRUCT_END;
+
+ return tot;
}
/***************************** ID Utilities *******************************/
@@ -171,7 +188,7 @@ int uiIconFromID(ID *id)
short idcode;
if(id==NULL)
- return 0;
+ return ICON_NULL;
idcode= GS(id->name);
@@ -189,5 +206,5 @@ int uiIconFromID(ID *id)
will set the right type, also with subclassing */
RNA_id_pointer_create(id, &ptr);
- return (ptr.type)? RNA_struct_ui_icon(ptr.type): 0;
+ return (ptr.type)? RNA_struct_ui_icon(ptr.type) : ICON_NULL;
}