static void rna_uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, const char *name, const char *text_ctxt, int translate, int icon, int expand, int slider, int toggle, int icon_only, int event, int full_event, int emboss, int index, int icon_value) { PropertyRNA *prop = RNA_struct_find_property(ptr, propname); int flag = 0; if (!prop) { RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname); return; } if (icon_value && !icon) { icon = icon_value; } /* Get translated name (label). */ name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate); flag |= (slider) ? UI_ITEM_R_SLIDER : 0; flag |= (expand) ? UI_ITEM_R_EXPAND : 0; flag |= (toggle) ? UI_ITEM_R_TOGGLE : 0; flag |= (icon_only) ? UI_ITEM_R_ICON_ONLY : 0; flag |= (event) ? UI_ITEM_R_EVENT : 0; flag |= (full_event) ? UI_ITEM_R_FULL_EVENT : 0; flag |= (emboss) ? 0 : UI_ITEM_R_NO_BG; uiItemFullR(layout, ptr, prop, index, 0, flag, name, icon); }
int UI_pie_menu_invoke_from_rna_enum( struct bContext *C, const char *title, const char *path, const wmEvent *event) { PointerRNA ctx_ptr; PointerRNA r_ptr; PropertyRNA *r_prop; uiPieMenu *pie; uiLayout *layout; RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr); if (!RNA_path_resolve(&ctx_ptr, path, &r_ptr, &r_prop)) { return OPERATOR_CANCELLED; } /* invalid property, only accept enums */ if (RNA_property_type(r_prop) != PROP_ENUM) { BLI_assert(0); return OPERATOR_CANCELLED; } pie = UI_pie_menu_begin(C, IFACE_(title), ICON_NONE, event); layout = UI_pie_menu_layout(pie); layout = uiLayoutRadial(layout); uiItemFullR(layout, &r_ptr, r_prop, RNA_NO_INDEX, 0, UI_ITEM_R_EXPAND, NULL, 0); UI_pie_menu_end(C, pie); return OPERATOR_INTERFACE; }
/** * \a check_prop callback filters functions to avoid drawing certain properties, * in cases where PROP_HIDDEN flag can't be used for a property. */ int uiDefAutoButsRNA(uiLayout *layout, PointerRNA *ptr, int (*check_prop)(PointerRNA *, PropertyRNA *), const char label_align) { uiLayout *split, *col; int flag; 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 || (check_prop && check_prop(ptr, prop) == FALSE)) continue; if (label_align != '\0') { PropertyType type = RNA_property_type(prop); int is_boolean = (type == PROP_BOOLEAN && !RNA_property_array_check(prop)); name = RNA_property_ui_name(prop); if (label_align == 'V') { col = uiLayoutColumn(layout, TRUE); if (!is_boolean) uiItemL(col, name, ICON_NONE); } else if (label_align == 'H') { split = uiLayoutSplit(layout, 0.5f, FALSE); col = uiLayoutColumn(split, FALSE); uiItemL(col, (is_boolean) ? "" : name, ICON_NONE); col = uiLayoutColumn(split, FALSE); } else { col = NULL; } /* may meed to add more cases here. * don't override enum flag names */ /* name is shown above, empty name for button below */ name = (flag & PROP_ENUM_FLAG || is_boolean) ? NULL : ""; } else { col = layout; name = NULL; /* no smart label alignment, show default name with button */ } uiItemFullR(col, ptr, prop, -1, 0, 0, name, ICON_NONE); tot++; }
static void rna_uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, const char *name, int icon, int expand, int slider, int toggle, int icon_only, int event, int full_event, int emboss, int index) { PropertyRNA *prop= RNA_struct_find_property(ptr, propname); int flag= 0; if(!prop) { RNA_warning("rna_uiItemR: property not found: %s.%s\n", RNA_struct_identifier(ptr->type), propname); return; } flag |= (slider)? UI_ITEM_R_SLIDER: 0; flag |= (expand)? UI_ITEM_R_EXPAND: 0; flag |= (toggle)? UI_ITEM_R_TOGGLE: 0; flag |= (icon_only)? UI_ITEM_R_ICON_ONLY: 0; flag |= (event)? UI_ITEM_R_EVENT: 0; flag |= (full_event)? UI_ITEM_R_FULL_EVENT: 0; flag |= (emboss)? 0: UI_ITEM_R_NO_BG; uiItemFullR(layout, ptr, prop, index, 0, flag, name, icon); }