1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2009 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup RNA
22  */
23 
24 #include <stdio.h>
25 #include <stdlib.h>
26 
27 #include "BLI_utildefines.h"
28 
29 #include "BLT_translation.h"
30 
31 #include "RNA_define.h"
32 #include "RNA_enum_types.h"
33 
34 #include "DNA_screen_types.h"
35 
36 #include "UI_interface.h"
37 #include "UI_interface_icons.h"
38 #include "UI_resources.h"
39 
40 #include "rna_internal.h"
41 
42 #define DEF_ICON(name) {ICON_##name, (#name), 0, (#name), ""},
43 #define DEF_ICON_VECTOR(name) {ICON_##name, (#name), 0, (#name), ""},
44 #define DEF_ICON_COLOR(name) {ICON_##name, (#name), 0, (#name), ""},
45 #define DEF_ICON_BLANK(name)
46 const EnumPropertyItem rna_enum_icon_items[] = {
47 #include "UI_icons.h"
48     {0, NULL, 0, NULL, NULL},
49 };
50 
51 #ifdef RNA_RUNTIME
52 
rna_translate_ui_text(const char * text,const char * text_ctxt,StructRNA * type,PropertyRNA * prop,bool translate)53 const char *rna_translate_ui_text(
54     const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, bool translate)
55 {
56   /* Also return text if UI labels translation is disabled. */
57   if (!text || !text[0] || !translate || !BLT_translate_iface()) {
58     return text;
59   }
60 
61   /* If a text_ctxt is specified, use it! */
62   if (text_ctxt && text_ctxt[0]) {
63     return BLT_pgettext(text_ctxt, text);
64   }
65 
66   /* Else, if an RNA type or property is specified, use its context. */
67 #  if 0
68   /* XXX Disabled for now. Unfortunately, their is absolutely no way from py code to get the RNA
69    *     struct corresponding to the 'data' (in functions like prop() & co),
70    *     as this is pure runtime data. Hence, messages extraction script can't determine the
71    *     correct context it should use for such 'text' messages...
72    *     So for now, one have to explicitly specify the 'text_ctxt' when using prop() etc.
73    *     functions, if default context is not suitable.
74    */
75   if (prop) {
76     return BLT_pgettext(RNA_property_translation_context(prop), text);
77   }
78 #  else
79   (void)prop;
80 #  endif
81   if (type) {
82     return BLT_pgettext(RNA_struct_translation_context(type), text);
83   }
84 
85   /* Else, default context! */
86   return BLT_pgettext(BLT_I18NCONTEXT_DEFAULT, text);
87 }
88 
rna_uiItemR(uiLayout * layout,PointerRNA * ptr,const char * propname,const char * name,const char * text_ctxt,bool translate,int icon,bool expand,bool slider,int toggle,bool icon_only,bool event,bool full_event,bool emboss,int index,int icon_value,bool invert_checkbox)89 static void rna_uiItemR(uiLayout *layout,
90                         PointerRNA *ptr,
91                         const char *propname,
92                         const char *name,
93                         const char *text_ctxt,
94                         bool translate,
95                         int icon,
96                         bool expand,
97                         bool slider,
98                         int toggle,
99                         bool icon_only,
100                         bool event,
101                         bool full_event,
102                         bool emboss,
103                         int index,
104                         int icon_value,
105                         bool invert_checkbox)
106 {
107   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
108   int flag = 0;
109 
110   if (!prop) {
111     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
112     return;
113   }
114 
115   if (icon_value && !icon) {
116     icon = icon_value;
117   }
118 
119   /* Get translated name (label). */
120   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
121 
122   flag |= (slider) ? UI_ITEM_R_SLIDER : 0;
123   flag |= (expand) ? UI_ITEM_R_EXPAND : 0;
124   if (toggle == 1) {
125     flag |= UI_ITEM_R_TOGGLE;
126   }
127   else if (toggle == 0) {
128     flag |= UI_ITEM_R_ICON_NEVER;
129   }
130   flag |= (icon_only) ? UI_ITEM_R_ICON_ONLY : 0;
131   flag |= (event) ? UI_ITEM_R_EVENT : 0;
132   flag |= (full_event) ? UI_ITEM_R_FULL_EVENT : 0;
133   flag |= (emboss) ? 0 : UI_ITEM_R_NO_BG;
134   flag |= (invert_checkbox) ? UI_ITEM_R_CHECKBOX_INVERT : 0;
135 
136   uiItemFullR(layout, ptr, prop, index, 0, flag, name, icon);
137 }
138 
rna_uiItemR_with_popover(uiLayout * layout,struct PointerRNA * ptr,const char * propname,const char * name,const char * text_ctxt,bool translate,int icon,bool icon_only,const char * panel_type)139 static void rna_uiItemR_with_popover(uiLayout *layout,
140                                      struct PointerRNA *ptr,
141                                      const char *propname,
142                                      const char *name,
143                                      const char *text_ctxt,
144                                      bool translate,
145                                      int icon,
146                                      bool icon_only,
147                                      const char *panel_type)
148 {
149   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
150 
151   if (!prop) {
152     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
153     return;
154   }
155   if ((RNA_property_type(prop) != PROP_ENUM) &&
156       !ELEM(RNA_property_subtype(prop), PROP_COLOR, PROP_COLOR_GAMMA)) {
157     RNA_warning(
158         "property is not an enum or color: %s.%s", RNA_struct_identifier(ptr->type), propname);
159     return;
160   }
161   int flag = 0;
162 
163   flag |= (icon_only) ? UI_ITEM_R_ICON_ONLY : 0;
164 
165   /* Get translated name (label). */
166   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
167   uiItemFullR_with_popover(layout, ptr, prop, -1, 0, flag, name, icon, panel_type);
168 }
169 
rna_uiItemR_with_menu(uiLayout * layout,struct PointerRNA * ptr,const char * propname,const char * name,const char * text_ctxt,bool translate,int icon,bool icon_only,const char * menu_type)170 static void rna_uiItemR_with_menu(uiLayout *layout,
171                                   struct PointerRNA *ptr,
172                                   const char *propname,
173                                   const char *name,
174                                   const char *text_ctxt,
175                                   bool translate,
176                                   int icon,
177                                   bool icon_only,
178                                   const char *menu_type)
179 {
180   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
181 
182   if (!prop) {
183     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
184     return;
185   }
186   if (RNA_property_type(prop) != PROP_ENUM) {
187     RNA_warning("property is not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
188     return;
189   }
190   int flag = 0;
191 
192   flag |= (icon_only) ? UI_ITEM_R_ICON_ONLY : 0;
193 
194   /* Get translated name (label). */
195   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
196   uiItemFullR_with_menu(layout, ptr, prop, -1, 0, flag, name, icon, menu_type);
197 }
198 
rna_uiItemMenuEnumR(uiLayout * layout,struct PointerRNA * ptr,const char * propname,const char * name,const char * text_ctxt,bool translate,int icon)199 static void rna_uiItemMenuEnumR(uiLayout *layout,
200                                 struct PointerRNA *ptr,
201                                 const char *propname,
202                                 const char *name,
203                                 const char *text_ctxt,
204                                 bool translate,
205                                 int icon)
206 {
207   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
208 
209   if (!prop) {
210     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
211     return;
212   }
213 
214   /* Get translated name (label). */
215   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
216   uiItemMenuEnumR_prop(layout, ptr, prop, name, icon);
217 }
218 
rna_uiItemTabsEnumR(uiLayout * layout,bContext * C,struct PointerRNA * ptr,const char * propname,struct PointerRNA * ptr_highlight,const char * propname_highlight,bool icon_only)219 static void rna_uiItemTabsEnumR(uiLayout *layout,
220                                 bContext *C,
221                                 struct PointerRNA *ptr,
222                                 const char *propname,
223                                 struct PointerRNA *ptr_highlight,
224                                 const char *propname_highlight,
225                                 bool icon_only)
226 {
227   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
228 
229   if (!prop) {
230     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
231     return;
232   }
233   if (RNA_property_type(prop) != PROP_ENUM) {
234     RNA_warning("property is not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
235     return;
236   }
237 
238   /* Get the highlight property used to gray out some of the tabs. */
239   PropertyRNA *prop_highlight = NULL;
240   if (!RNA_pointer_is_null(ptr_highlight)) {
241     prop_highlight = RNA_struct_find_property(ptr_highlight, propname_highlight);
242     if (!prop_highlight) {
243       RNA_warning("property not found: %s.%s",
244                   RNA_struct_identifier(ptr_highlight->type),
245                   propname_highlight);
246       return;
247     }
248     if (RNA_property_type(prop_highlight) != PROP_BOOLEAN) {
249       RNA_warning("property is not a boolean: %s.%s",
250                   RNA_struct_identifier(ptr_highlight->type),
251                   propname_highlight);
252       return;
253     }
254     if (!RNA_property_array_check(prop_highlight)) {
255       RNA_warning("property is not an array: %s.%s",
256                   RNA_struct_identifier(ptr_highlight->type),
257                   propname_highlight);
258       return;
259     }
260   }
261 
262   uiItemTabsEnumR_prop(layout, C, ptr, prop, ptr_highlight, prop_highlight, icon_only);
263 }
264 
rna_uiItemEnumR_string(uiLayout * layout,struct PointerRNA * ptr,const char * propname,const char * value,const char * name,const char * text_ctxt,bool translate,int icon)265 static void rna_uiItemEnumR_string(uiLayout *layout,
266                                    struct PointerRNA *ptr,
267                                    const char *propname,
268                                    const char *value,
269                                    const char *name,
270                                    const char *text_ctxt,
271                                    bool translate,
272                                    int icon)
273 {
274   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
275 
276   if (!prop) {
277     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
278     return;
279   }
280 
281   /* Get translated name (label). */
282   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
283 
284   uiItemEnumR_string_prop(layout, ptr, prop, value, name, icon);
285 }
286 
rna_uiItemPointerR(uiLayout * layout,struct PointerRNA * ptr,const char * propname,struct PointerRNA * searchptr,const char * searchpropname,const char * name,const char * text_ctxt,bool translate,int icon)287 static void rna_uiItemPointerR(uiLayout *layout,
288                                struct PointerRNA *ptr,
289                                const char *propname,
290                                struct PointerRNA *searchptr,
291                                const char *searchpropname,
292                                const char *name,
293                                const char *text_ctxt,
294                                bool translate,
295                                int icon)
296 {
297   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
298   if (!prop) {
299     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
300     return;
301   }
302   PropertyRNA *searchprop = RNA_struct_find_property(searchptr, searchpropname);
303   if (!searchprop) {
304     RNA_warning(
305         "property not found: %s.%s", RNA_struct_identifier(searchptr->type), searchpropname);
306     return;
307   }
308 
309   /* Get translated name (label). */
310   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
311 
312   uiItemPointerR_prop(layout, ptr, prop, searchptr, searchprop, name, icon);
313 }
314 
rna_uiItemO(uiLayout * layout,const char * opname,const char * name,const char * text_ctxt,bool translate,int icon,bool emboss,bool depress,int icon_value)315 static PointerRNA rna_uiItemO(uiLayout *layout,
316                               const char *opname,
317                               const char *name,
318                               const char *text_ctxt,
319                               bool translate,
320                               int icon,
321                               bool emboss,
322                               bool depress,
323                               int icon_value)
324 {
325   wmOperatorType *ot;
326 
327   ot = WM_operatortype_find(opname, 0); /* print error next */
328   if (!ot || !ot->srna) {
329     RNA_warning("%s '%s'", ot ? "unknown operator" : "operator missing srna", opname);
330     return PointerRNA_NULL;
331   }
332 
333   /* Get translated name (label). */
334   name = rna_translate_ui_text(name, text_ctxt, ot->srna, NULL, translate);
335 
336   if (icon_value && !icon) {
337     icon = icon_value;
338   }
339   int flag = (emboss) ? 0 : UI_ITEM_R_NO_BG;
340   flag |= (depress) ? UI_ITEM_O_DEPRESS : 0;
341 
342   PointerRNA opptr;
343   uiItemFullO_ptr(layout, ot, name, icon, NULL, uiLayoutGetOperatorContext(layout), flag, &opptr);
344   return opptr;
345 }
346 
rna_uiItemOMenuHold(uiLayout * layout,const char * opname,const char * name,const char * text_ctxt,bool translate,int icon,bool emboss,bool depress,int icon_value,const char * menu)347 static PointerRNA rna_uiItemOMenuHold(uiLayout *layout,
348                                       const char *opname,
349                                       const char *name,
350                                       const char *text_ctxt,
351                                       bool translate,
352                                       int icon,
353                                       bool emboss,
354                                       bool depress,
355                                       int icon_value,
356                                       const char *menu)
357 {
358   wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
359   if (!ot || !ot->srna) {
360     RNA_warning("%s '%s'", ot ? "unknown operator" : "operator missing srna", opname);
361     return PointerRNA_NULL;
362   }
363 
364   /* Get translated name (label). */
365   name = rna_translate_ui_text(name, text_ctxt, ot->srna, NULL, translate);
366   if (icon_value && !icon) {
367     icon = icon_value;
368   }
369   int flag = (emboss) ? 0 : UI_ITEM_R_NO_BG;
370   flag |= (depress) ? UI_ITEM_O_DEPRESS : 0;
371 
372   PointerRNA opptr;
373   uiItemFullOMenuHold_ptr(
374       layout, ot, name, icon, NULL, uiLayoutGetOperatorContext(layout), flag, menu, &opptr);
375   return opptr;
376 }
377 
rna_uiItemsEnumO(uiLayout * layout,const char * opname,const char * propname,const bool icon_only)378 static void rna_uiItemsEnumO(uiLayout *layout,
379                              const char *opname,
380                              const char *propname,
381                              const bool icon_only)
382 {
383   int flag = icon_only ? UI_ITEM_R_ICON_ONLY : 0;
384   uiItemsFullEnumO(layout, opname, propname, NULL, uiLayoutGetOperatorContext(layout), flag);
385 }
386 
rna_uiItemMenuEnumO(uiLayout * layout,bContext * C,const char * opname,const char * propname,const char * name,const char * text_ctxt,bool translate,int icon)387 static void rna_uiItemMenuEnumO(uiLayout *layout,
388                                 bContext *C,
389                                 const char *opname,
390                                 const char *propname,
391                                 const char *name,
392                                 const char *text_ctxt,
393                                 bool translate,
394                                 int icon)
395 {
396   wmOperatorType *ot = WM_operatortype_find(opname, 0); /* print error next */
397 
398   if (!ot || !ot->srna) {
399     RNA_warning("%s '%s'", ot ? "unknown operator" : "operator missing srna", opname);
400     return;
401   }
402 
403   /* Get translated name (label). */
404   name = rna_translate_ui_text(name, text_ctxt, ot->srna, NULL, translate);
405 
406   uiItemMenuEnumO_ptr(layout, C, ot, propname, name, icon);
407 }
408 
rna_uiItemL(uiLayout * layout,const char * name,const char * text_ctxt,bool translate,int icon,int icon_value)409 static void rna_uiItemL(uiLayout *layout,
410                         const char *name,
411                         const char *text_ctxt,
412                         bool translate,
413                         int icon,
414                         int icon_value)
415 {
416   /* Get translated name (label). */
417   name = rna_translate_ui_text(name, text_ctxt, NULL, NULL, translate);
418 
419   if (icon_value && !icon) {
420     icon = icon_value;
421   }
422 
423   uiItemL(layout, name, icon);
424 }
425 
rna_uiItemM(uiLayout * layout,const char * menuname,const char * name,const char * text_ctxt,bool translate,int icon,int icon_value)426 static void rna_uiItemM(uiLayout *layout,
427                         const char *menuname,
428                         const char *name,
429                         const char *text_ctxt,
430                         bool translate,
431                         int icon,
432                         int icon_value)
433 {
434   /* Get translated name (label). */
435   name = rna_translate_ui_text(name, text_ctxt, NULL, NULL, translate);
436 
437   if (icon_value && !icon) {
438     icon = icon_value;
439   }
440 
441   uiItemM(layout, menuname, name, icon);
442 }
443 
rna_uiItemM_contents(uiLayout * layout,const char * menuname)444 static void rna_uiItemM_contents(uiLayout *layout, const char *menuname)
445 {
446   uiItemMContents(layout, menuname);
447 }
448 
rna_uiItemPopoverPanel(uiLayout * layout,bContext * C,const char * panel_type,const char * name,const char * text_ctxt,bool translate,int icon,int icon_value)449 static void rna_uiItemPopoverPanel(uiLayout *layout,
450                                    bContext *C,
451                                    const char *panel_type,
452                                    const char *name,
453                                    const char *text_ctxt,
454                                    bool translate,
455                                    int icon,
456                                    int icon_value)
457 {
458   /* Get translated name (label). */
459   name = rna_translate_ui_text(name, text_ctxt, NULL, NULL, translate);
460 
461   if (icon_value && !icon) {
462     icon = icon_value;
463   }
464 
465   uiItemPopoverPanel(layout, C, panel_type, name, icon);
466 }
467 
rna_uiItemPopoverPanelFromGroup(uiLayout * layout,bContext * C,int space_id,int region_id,const char * context,const char * category)468 static void rna_uiItemPopoverPanelFromGroup(uiLayout *layout,
469                                             bContext *C,
470                                             int space_id,
471                                             int region_id,
472                                             const char *context,
473                                             const char *category)
474 {
475   uiItemPopoverPanelFromGroup(layout, C, space_id, region_id, context, category);
476 }
477 
rna_uiTemplateID(uiLayout * layout,bContext * C,PointerRNA * ptr,const char * propname,const char * newop,const char * openop,const char * unlinkop,int filter,const bool live_icon,const char * name,const char * text_ctxt,bool translate)478 static void rna_uiTemplateID(uiLayout *layout,
479                              bContext *C,
480                              PointerRNA *ptr,
481                              const char *propname,
482                              const char *newop,
483                              const char *openop,
484                              const char *unlinkop,
485                              int filter,
486                              const bool live_icon,
487                              const char *name,
488                              const char *text_ctxt,
489                              bool translate)
490 {
491   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
492 
493   if (!prop) {
494     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
495     return;
496   }
497 
498   /* Get translated name (label). */
499   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
500 
501   uiTemplateID(layout, C, ptr, propname, newop, openop, unlinkop, filter, live_icon, name);
502 }
503 
rna_uiTemplateAnyID(uiLayout * layout,PointerRNA * ptr,const char * propname,const char * proptypename,const char * name,const char * text_ctxt,bool translate)504 static void rna_uiTemplateAnyID(uiLayout *layout,
505                                 PointerRNA *ptr,
506                                 const char *propname,
507                                 const char *proptypename,
508                                 const char *name,
509                                 const char *text_ctxt,
510                                 bool translate)
511 {
512   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
513 
514   if (!prop) {
515     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
516     return;
517   }
518 
519   /* Get translated name (label). */
520   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
521 
522   /* XXX This will search property again :( */
523   uiTemplateAnyID(layout, ptr, propname, proptypename, name);
524 }
525 
rna_uiTemplateCacheFile(uiLayout * layout,bContext * C,PointerRNA * ptr,const char * propname)526 static void rna_uiTemplateCacheFile(uiLayout *layout,
527                                     bContext *C,
528                                     PointerRNA *ptr,
529                                     const char *propname)
530 {
531   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
532 
533   if (!prop) {
534     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
535     return;
536   }
537 
538   uiTemplateCacheFile(layout, C, ptr, propname);
539 }
540 
rna_uiTemplatePathBuilder(uiLayout * layout,PointerRNA * ptr,const char * propname,PointerRNA * root_ptr,const char * name,const char * text_ctxt,bool translate)541 static void rna_uiTemplatePathBuilder(uiLayout *layout,
542                                       PointerRNA *ptr,
543                                       const char *propname,
544                                       PointerRNA *root_ptr,
545                                       const char *name,
546                                       const char *text_ctxt,
547                                       bool translate)
548 {
549   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
550 
551   if (!prop) {
552     RNA_warning("property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
553     return;
554   }
555 
556   /* Get translated name (label). */
557   name = rna_translate_ui_text(name, text_ctxt, NULL, prop, translate);
558 
559   /* XXX This will search property again :( */
560   uiTemplatePathBuilder(layout, ptr, propname, root_ptr, name);
561 }
562 
rna_uiTemplateEventFromKeymapItem(uiLayout * layout,wmKeyMapItem * kmi,const char * name,const char * text_ctxt,bool translate)563 static void rna_uiTemplateEventFromKeymapItem(
564     uiLayout *layout, wmKeyMapItem *kmi, const char *name, const char *text_ctxt, bool translate)
565 {
566   /* Get translated name (label). */
567   name = rna_translate_ui_text(name, text_ctxt, NULL, NULL, translate);
568   uiTemplateEventFromKeymapItem(layout, name, kmi, true);
569 }
570 
rna_uiLayoutRowWithHeading(uiLayout * layout,bool align,const char * heading,const char * heading_ctxt,bool translate)571 static uiLayout *rna_uiLayoutRowWithHeading(
572     uiLayout *layout, bool align, const char *heading, const char *heading_ctxt, bool translate)
573 {
574   /* Get translated heading. */
575   heading = rna_translate_ui_text(heading, heading_ctxt, NULL, NULL, translate);
576   return uiLayoutRowWithHeading(layout, align, heading);
577 }
578 
rna_uiLayoutColumnWithHeading(uiLayout * layout,bool align,const char * heading,const char * heading_ctxt,bool translate)579 static uiLayout *rna_uiLayoutColumnWithHeading(
580     uiLayout *layout, bool align, const char *heading, const char *heading_ctxt, bool translate)
581 {
582   /* Get translated heading. */
583   heading = rna_translate_ui_text(heading, heading_ctxt, NULL, NULL, translate);
584   return uiLayoutColumnWithHeading(layout, align, heading);
585 }
586 
rna_ui_get_rnaptr_icon(bContext * C,PointerRNA * ptr_icon)587 static int rna_ui_get_rnaptr_icon(bContext *C, PointerRNA *ptr_icon)
588 {
589   return UI_icon_from_rnaptr(C, ptr_icon, RNA_struct_ui_icon(ptr_icon->type), false);
590 }
591 
rna_ui_get_enum_name(bContext * C,PointerRNA * ptr,const char * propname,const char * identifier)592 static const char *rna_ui_get_enum_name(bContext *C,
593                                         PointerRNA *ptr,
594                                         const char *propname,
595                                         const char *identifier)
596 {
597   PropertyRNA *prop = NULL;
598   const EnumPropertyItem *items = NULL, *item;
599   bool free;
600   const char *name = "";
601 
602   prop = RNA_struct_find_property(ptr, propname);
603   if (!prop || (RNA_property_type(prop) != PROP_ENUM)) {
604     RNA_warning(
605         "Property not found or not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
606     return name;
607   }
608 
609   RNA_property_enum_items_gettexted(C, ptr, prop, &items, NULL, &free);
610 
611   if (items) {
612     for (item = items; item->identifier; item++) {
613       if (item->identifier[0] && STREQ(item->identifier, identifier)) {
614         name = item->name;
615         break;
616       }
617     }
618     if (free) {
619       MEM_freeN((void *)items);
620     }
621   }
622 
623   return name;
624 }
625 
rna_ui_get_enum_description(bContext * C,PointerRNA * ptr,const char * propname,const char * identifier)626 static const char *rna_ui_get_enum_description(bContext *C,
627                                                PointerRNA *ptr,
628                                                const char *propname,
629                                                const char *identifier)
630 {
631   PropertyRNA *prop = NULL;
632   const EnumPropertyItem *items = NULL, *item;
633   bool free;
634   const char *desc = "";
635 
636   prop = RNA_struct_find_property(ptr, propname);
637   if (!prop || (RNA_property_type(prop) != PROP_ENUM)) {
638     RNA_warning(
639         "Property not found or not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
640     return desc;
641   }
642 
643   RNA_property_enum_items_gettexted(C, ptr, prop, &items, NULL, &free);
644 
645   if (items) {
646     for (item = items; item->identifier; item++) {
647       if (item->identifier[0] && STREQ(item->identifier, identifier)) {
648         desc = item->description;
649         break;
650       }
651     }
652     if (free) {
653       MEM_freeN((void *)items);
654     }
655   }
656 
657   return desc;
658 }
659 
rna_ui_get_enum_icon(bContext * C,PointerRNA * ptr,const char * propname,const char * identifier)660 static int rna_ui_get_enum_icon(bContext *C,
661                                 PointerRNA *ptr,
662                                 const char *propname,
663                                 const char *identifier)
664 {
665   PropertyRNA *prop = NULL;
666   const EnumPropertyItem *items = NULL, *item;
667   bool free;
668   int icon = ICON_NONE;
669 
670   prop = RNA_struct_find_property(ptr, propname);
671   if (!prop || (RNA_property_type(prop) != PROP_ENUM)) {
672     RNA_warning(
673         "Property not found or not an enum: %s.%s", RNA_struct_identifier(ptr->type), propname);
674     return icon;
675   }
676 
677   RNA_property_enum_items(C, ptr, prop, &items, NULL, &free);
678 
679   if (items) {
680     for (item = items; item->identifier; item++) {
681       if (item->identifier[0] && STREQ(item->identifier, identifier)) {
682         icon = item->icon;
683         break;
684       }
685     }
686     if (free) {
687       MEM_freeN((void *)items);
688     }
689   }
690 
691   return icon;
692 }
693 
694 #else
695 
api_ui_item_common_heading(FunctionRNA * func)696 static void api_ui_item_common_heading(FunctionRNA *func)
697 {
698   RNA_def_string(func,
699                  "heading",
700                  NULL,
701                  UI_MAX_NAME_STR,
702                  "Heading",
703                  "Label to insert into the layout for this sub-layout");
704   RNA_def_string(func,
705                  "heading_ctxt",
706                  NULL,
707                  0,
708                  "",
709                  "Override automatic translation context of the given heading");
710   RNA_def_boolean(
711       func, "translate", true, "", "Translate the given heading, when UI translation is enabled");
712 }
713 
api_ui_item_common_text(FunctionRNA * func)714 static void api_ui_item_common_text(FunctionRNA *func)
715 {
716   PropertyRNA *prop;
717 
718   prop = RNA_def_string(func, "text", NULL, 0, "", "Override automatic text of the item");
719   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL);
720   prop = RNA_def_string(
721       func, "text_ctxt", NULL, 0, "", "Override automatic translation context of the given text");
722   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL);
723   RNA_def_boolean(
724       func, "translate", true, "", "Translate the given text, when UI translation is enabled");
725 }
726 
api_ui_item_common(FunctionRNA * func)727 static void api_ui_item_common(FunctionRNA *func)
728 {
729   PropertyRNA *prop;
730 
731   api_ui_item_common_text(func);
732 
733   prop = RNA_def_property(func, "icon", PROP_ENUM, PROP_NONE);
734   RNA_def_property_enum_items(prop, rna_enum_icon_items);
735   RNA_def_property_ui_text(prop, "Icon", "Override automatic icon of the item");
736 }
737 
api_ui_item_op(FunctionRNA * func)738 static void api_ui_item_op(FunctionRNA *func)
739 {
740   PropertyRNA *parm;
741   parm = RNA_def_string(func, "operator", NULL, 0, "", "Identifier of the operator");
742   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
743 }
744 
api_ui_item_op_common(FunctionRNA * func)745 static void api_ui_item_op_common(FunctionRNA *func)
746 {
747   api_ui_item_op(func);
748   api_ui_item_common(func);
749 }
750 
api_ui_item_rna_common(FunctionRNA * func)751 static void api_ui_item_rna_common(FunctionRNA *func)
752 {
753   PropertyRNA *parm;
754 
755   parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
756   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
757   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in data");
758   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
759 }
760 
RNA_api_ui_layout(StructRNA * srna)761 void RNA_api_ui_layout(StructRNA *srna)
762 {
763   FunctionRNA *func;
764   PropertyRNA *parm;
765 
766   static const EnumPropertyItem curve_type_items[] = {
767       {0, "NONE", 0, "None", ""},
768       {'v', "VECTOR", 0, "Vector", ""},
769       {'c', "COLOR", 0, "Color", ""},
770       {'h', "HUE", 0, "Hue", ""},
771       {0, NULL, 0, NULL, NULL},
772   };
773 
774   static const EnumPropertyItem id_template_filter_items[] = {
775       {UI_TEMPLATE_ID_FILTER_ALL, "ALL", 0, "All", ""},
776       {UI_TEMPLATE_ID_FILTER_AVAILABLE, "AVAILABLE", 0, "Available", ""},
777       {0, NULL, 0, NULL, NULL},
778   };
779 
780   static float node_socket_color_default[] = {0.0f, 0.0f, 0.0f, 1.0f};
781 
782   /* simple layout specifiers */
783   func = RNA_def_function(srna, "row", "rna_uiLayoutRowWithHeading");
784   parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
785   RNA_def_function_return(func, parm);
786   RNA_def_function_ui_description(
787       func,
788       "Sub-layout. Items placed in this sublayout are placed next to each other "
789       "in a row");
790   RNA_def_boolean(func, "align", false, "", "Align buttons to each other");
791   api_ui_item_common_heading(func);
792 
793   func = RNA_def_function(srna, "column", "rna_uiLayoutColumnWithHeading");
794   parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
795   RNA_def_function_return(func, parm);
796   RNA_def_function_ui_description(
797       func,
798       "Sub-layout. Items placed in this sublayout are placed under each other "
799       "in a column");
800   RNA_def_boolean(func, "align", false, "", "Align buttons to each other");
801   api_ui_item_common_heading(func);
802 
803   func = RNA_def_function(srna, "column_flow", "uiLayoutColumnFlow");
804   RNA_def_int(func, "columns", 0, 0, INT_MAX, "", "Number of columns, 0 is automatic", 0, INT_MAX);
805   parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
806   RNA_def_function_return(func, parm);
807   RNA_def_boolean(func, "align", false, "", "Align buttons to each other");
808 
809   func = RNA_def_function(srna, "grid_flow", "uiLayoutGridFlow");
810   RNA_def_boolean(func, "row_major", false, "", "Fill row by row, instead of column by column");
811   RNA_def_int(
812       func,
813       "columns",
814       0,
815       INT_MIN,
816       INT_MAX,
817       "",
818       "Number of columns, positive are absolute fixed numbers, 0 is automatic, negative are "
819       "automatic multiple numbers along major axis (e.g. -2 will only produce 2, 4, 6 etc. "
820       "columns for row major layout, and 2, 4, 6 etc. rows for column major layout)",
821       INT_MIN,
822       INT_MAX);
823   RNA_def_boolean(func, "even_columns", false, "", "All columns will have the same width");
824   RNA_def_boolean(func, "even_rows", false, "", "All rows will have the same height");
825   RNA_def_boolean(func, "align", false, "", "Align buttons to each other");
826   parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
827   RNA_def_function_return(func, parm);
828 
829   /* box layout */
830   func = RNA_def_function(srna, "box", "uiLayoutBox");
831   parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
832   RNA_def_function_return(func, parm);
833   RNA_def_function_ui_description(func,
834                                   "Sublayout (items placed in this sublayout are placed "
835                                   "under each other in a column and are surrounded by a box)");
836 
837   /* split layout */
838   func = RNA_def_function(srna, "split", "uiLayoutSplit");
839   parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
840   RNA_def_function_return(func, parm);
841   RNA_def_float(func,
842                 "factor",
843                 0.0f,
844                 0.0f,
845                 1.0f,
846                 "Percentage",
847                 "Percentage of width to split at (leave unset for automatic calculation)",
848                 0.0f,
849                 1.0f);
850   RNA_def_boolean(func, "align", false, "", "Align buttons to each other");
851 
852   /* radial/pie layout */
853   func = RNA_def_function(srna, "menu_pie", "uiLayoutRadial");
854   parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
855   RNA_def_function_return(func, parm);
856   RNA_def_function_ui_description(func,
857                                   "Sublayout. Items placed in this sublayout are placed "
858                                   "in a radial fashion around the menu center)");
859 
860   /* Icon of a rna pointer */
861   func = RNA_def_function(srna, "icon", "rna_ui_get_rnaptr_icon");
862   parm = RNA_def_int(func, "icon_value", ICON_NONE, 0, INT_MAX, "", "Icon identifier", 0, INT_MAX);
863   RNA_def_function_return(func, parm);
864   RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
865   parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take the icon");
866   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
867   RNA_def_function_ui_description(func,
868                                   "Return the custom icon for this data, "
869                                   "use it e.g. to get materials or texture icons");
870 
871   /* UI name, description and icon of an enum item */
872   func = RNA_def_function(srna, "enum_item_name", "rna_ui_get_enum_name");
873   parm = RNA_def_string(func, "name", NULL, 0, "", "UI name of the enum item");
874   RNA_def_function_return(func, parm);
875   RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
876   api_ui_item_rna_common(func);
877   parm = RNA_def_string(func, "identifier", NULL, 0, "", "Identifier of the enum item");
878   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
879   RNA_def_function_ui_description(func, "Return the UI name for this enum item");
880 
881   func = RNA_def_function(srna, "enum_item_description", "rna_ui_get_enum_description");
882   parm = RNA_def_string(func, "description", NULL, 0, "", "UI description of the enum item");
883   RNA_def_function_return(func, parm);
884   RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
885   api_ui_item_rna_common(func);
886   parm = RNA_def_string(func, "identifier", NULL, 0, "", "Identifier of the enum item");
887   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
888   RNA_def_function_ui_description(func, "Return the UI description for this enum item");
889 
890   func = RNA_def_function(srna, "enum_item_icon", "rna_ui_get_enum_icon");
891   parm = RNA_def_int(func, "icon_value", ICON_NONE, 0, INT_MAX, "", "Icon identifier", 0, INT_MAX);
892   RNA_def_function_return(func, parm);
893   RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
894   api_ui_item_rna_common(func);
895   parm = RNA_def_string(func, "identifier", NULL, 0, "", "Identifier of the enum item");
896   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
897   RNA_def_function_ui_description(func, "Return the icon for this enum item");
898 
899   /* items */
900   func = RNA_def_function(srna, "prop", "rna_uiItemR");
901   RNA_def_function_ui_description(func, "Item. Exposes an RNA item and places it into the layout");
902   api_ui_item_rna_common(func);
903   api_ui_item_common(func);
904   RNA_def_boolean(func, "expand", false, "", "Expand button to show more detail");
905   RNA_def_boolean(func, "slider", false, "", "Use slider widget for numeric values");
906   RNA_def_int(func,
907               "toggle",
908               -1,
909               -1,
910               1,
911               "",
912               "Use toggle widget for boolean values, "
913               "or a checkbox when disabled "
914               "(the default is -1 which uses toggle only when an icon is displayed)",
915               -1,
916               1);
917   RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in buttons, no text");
918   RNA_def_boolean(func, "event", false, "", "Use button to input key events");
919   RNA_def_boolean(
920       func, "full_event", false, "", "Use button to input full events including modifiers");
921   RNA_def_boolean(func, "emboss", true, "", "Draw the button itself, not just the icon/text");
922   RNA_def_int(func,
923               "index",
924               /* RNA_NO_INDEX == -1 */
925               -1,
926               -2,
927               INT_MAX,
928               "",
929               "The index of this button, when set a single member of an array can be accessed, "
930               "when set to -1 all array members are used",
931               -2,
932               INT_MAX);
933   parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
934   RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item");
935   RNA_def_boolean(func, "invert_checkbox", false, "", "Draw checkbox value inverted");
936 
937   func = RNA_def_function(srna, "props_enum", "uiItemsEnumR");
938   api_ui_item_rna_common(func);
939 
940   func = RNA_def_function(srna, "prop_menu_enum", "rna_uiItemMenuEnumR");
941   api_ui_item_rna_common(func);
942   api_ui_item_common(func);
943 
944   func = RNA_def_function(srna, "prop_with_popover", "rna_uiItemR_with_popover");
945   api_ui_item_rna_common(func);
946   api_ui_item_common(func);
947   RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in tabs, no text");
948   parm = RNA_def_string(func, "panel", NULL, 0, "", "Identifier of the panel");
949   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
950 
951   func = RNA_def_function(srna, "prop_with_menu", "rna_uiItemR_with_menu");
952   api_ui_item_rna_common(func);
953   api_ui_item_common(func);
954   RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in tabs, no text");
955   parm = RNA_def_string(func, "menu", NULL, 0, "", "Identifier of the menu");
956   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
957 
958   func = RNA_def_function(srna, "prop_tabs_enum", "rna_uiItemTabsEnumR");
959   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
960   api_ui_item_rna_common(func);
961   parm = RNA_def_pointer(
962       func, "data_highlight", "AnyType", "", "Data from which to take highlight property");
963   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
964   parm = RNA_def_string(
965       func, "property_highlight", NULL, 0, "", "Identifier of highlight property in data");
966   RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in tabs, no text");
967 
968   func = RNA_def_function(srna, "prop_enum", "rna_uiItemEnumR_string");
969   api_ui_item_rna_common(func);
970   parm = RNA_def_string(func, "value", NULL, 0, "", "Enum property value");
971   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
972   api_ui_item_common(func);
973 
974   func = RNA_def_function(srna, "prop_search", "rna_uiItemPointerR");
975   api_ui_item_rna_common(func);
976   parm = RNA_def_pointer(
977       func, "search_data", "AnyType", "", "Data from which to take collection to search in");
978   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
979   parm = RNA_def_string(
980       func, "search_property", NULL, 0, "", "Identifier of search collection property");
981   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
982   api_ui_item_common(func);
983 
984   func = RNA_def_function(srna, "prop_decorator", "uiItemDecoratorR");
985   api_ui_item_rna_common(func);
986   RNA_def_int(func,
987               "index",
988               /* RNA_NO_INDEX == -1 */
989               -1,
990               -2,
991               INT_MAX,
992               "",
993               "The index of this button, when set a single member of an array can be accessed, "
994               "when set to -1 all array members are used",
995               -2,
996               INT_MAX);
997 
998   for (int is_menu_hold = 0; is_menu_hold < 2; is_menu_hold++) {
999     func = (is_menu_hold) ? RNA_def_function(srna, "operator_menu_hold", "rna_uiItemOMenuHold") :
1000                             RNA_def_function(srna, "operator", "rna_uiItemO");
1001     api_ui_item_op_common(func);
1002     RNA_def_boolean(func, "emboss", true, "", "Draw the button itself, not just the icon/text");
1003     RNA_def_boolean(func, "depress", false, "", "Draw pressed in");
1004     parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
1005     RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item");
1006     if (is_menu_hold) {
1007       parm = RNA_def_string(func, "menu", NULL, 0, "", "Identifier of the menu");
1008       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1009     }
1010     parm = RNA_def_pointer(
1011         func, "properties", "OperatorProperties", "", "Operator properties to fill in");
1012     RNA_def_parameter_flags(parm, 0, PARM_REQUIRED | PARM_RNAPTR);
1013     RNA_def_function_return(func, parm);
1014     RNA_def_function_ui_description(func,
1015                                     "Item. Places a button into the layout to call an Operator");
1016   }
1017 
1018   func = RNA_def_function(srna, "operator_enum", "rna_uiItemsEnumO");
1019   parm = RNA_def_string(func, "operator", NULL, 0, "", "Identifier of the operator");
1020   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1021   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
1022   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1023   RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in buttons, no text");
1024 
1025   func = RNA_def_function(srna, "operator_menu_enum", "rna_uiItemMenuEnumO");
1026   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1027   api_ui_item_op(func); /* cant use api_ui_item_op_common because property must come right after */
1028   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
1029   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1030   api_ui_item_common(func);
1031 
1032   /* useful in C but not in python */
1033 #  if 0
1034 
1035   func = RNA_def_function(srna, "operator_enum_single", "uiItemEnumO_string");
1036   api_ui_item_op_common(func);
1037   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
1038   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1039   parm = RNA_def_string(func, "value", NULL, 0, "", "Enum property value");
1040   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1041 
1042   func = RNA_def_function(srna, "operator_boolean", "uiItemBooleanO");
1043   api_ui_item_op_common(func);
1044   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
1045   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1046   parm = RNA_def_boolean(
1047       func, "value", false, "", "Value of the property to call the operator with");
1048   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1049 
1050   func = RNA_def_function(srna, "operator_int", "uiItemIntO");
1051   api_ui_item_op_common(func);
1052   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
1053   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1054   parm = RNA_def_int(func,
1055                      "value",
1056                      0,
1057                      INT_MIN,
1058                      INT_MAX,
1059                      "",
1060                      "Value of the property to call the operator with",
1061                      INT_MIN,
1062                      INT_MAX);
1063   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1064 
1065   func = RNA_def_function(srna, "operator_float", "uiItemFloatO");
1066   api_ui_item_op_common(func);
1067   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
1068   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1069   parm = RNA_def_float(func,
1070                        "value",
1071                        0,
1072                        -FLT_MAX,
1073                        FLT_MAX,
1074                        "",
1075                        "Value of the property to call the operator with",
1076                        -FLT_MAX,
1077                        FLT_MAX);
1078   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1079 
1080   func = RNA_def_function(srna, "operator_string", "uiItemStringO");
1081   api_ui_item_op_common(func);
1082   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
1083   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1084   parm = RNA_def_string(
1085       func, "value", NULL, 0, "", "Value of the property to call the operator with");
1086   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1087 #  endif
1088 
1089   func = RNA_def_function(srna, "label", "rna_uiItemL");
1090   RNA_def_function_ui_description(func, "Item. Displays text and/or icon in the layout");
1091   api_ui_item_common(func);
1092   parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
1093   RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item");
1094 
1095   func = RNA_def_function(srna, "menu", "rna_uiItemM");
1096   parm = RNA_def_string(func, "menu", NULL, 0, "", "Identifier of the menu");
1097   api_ui_item_common(func);
1098   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1099   parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
1100   RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item");
1101 
1102   func = RNA_def_function(srna, "menu_contents", "rna_uiItemM_contents");
1103   parm = RNA_def_string(func, "menu", NULL, 0, "", "Identifier of the menu");
1104   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1105 
1106   func = RNA_def_function(srna, "popover", "rna_uiItemPopoverPanel");
1107   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1108   parm = RNA_def_string(func, "panel", NULL, 0, "", "Identifier of the panel");
1109   api_ui_item_common(func);
1110   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1111   parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
1112   RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item");
1113 
1114   func = RNA_def_function(srna, "popover_group", "rna_uiItemPopoverPanelFromGroup");
1115   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1116   parm = RNA_def_enum(func, "space_type", rna_enum_space_type_items, 0, "Space Type", "");
1117   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1118   parm = RNA_def_enum(
1119       func, "region_type", rna_enum_region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
1120   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1121   parm = RNA_def_string(func, "context", NULL, 0, "", "panel type context");
1122   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1123   parm = RNA_def_string(func, "category", NULL, 0, "", "panel type category");
1124   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1125 
1126   func = RNA_def_function(srna, "separator", "uiItemS_ex");
1127   RNA_def_function_ui_description(func, "Item. Inserts empty space into the layout between items");
1128   RNA_def_float(func,
1129                 "factor",
1130                 1.0f,
1131                 0.0f,
1132                 FLT_MAX,
1133                 "Percentage",
1134                 "Percentage of width to space (leave unset for default space)",
1135                 0.0f,
1136                 FLT_MAX);
1137 
1138   func = RNA_def_function(srna, "separator_spacer", "uiItemSpacer");
1139   RNA_def_function_ui_description(
1140       func, "Item. Inserts horizontal spacing empty space into the layout between items");
1141 
1142   /* context */
1143   func = RNA_def_function(srna, "context_pointer_set", "uiLayoutSetContextPointer");
1144   parm = RNA_def_string(func, "name", NULL, 0, "Name", "Name of entry in the context");
1145   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1146   parm = RNA_def_pointer(func, "data", "AnyType", "", "Pointer to put in context");
1147   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED | PARM_RNAPTR);
1148 
1149   /* templates */
1150   func = RNA_def_function(srna, "template_header", "uiTemplateHeader");
1151   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1152   RNA_def_function_ui_description(func, "Inserts common Space header UI (editor type selector)");
1153 
1154   func = RNA_def_function(srna, "template_ID", "rna_uiTemplateID");
1155   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1156   api_ui_item_rna_common(func);
1157   RNA_def_string(func, "new", NULL, 0, "", "Operator identifier to create a new ID block");
1158   RNA_def_string(
1159       func, "open", NULL, 0, "", "Operator identifier to open a file for creating a new ID block");
1160   RNA_def_string(func, "unlink", NULL, 0, "", "Operator identifier to unlink the ID block");
1161   RNA_def_enum(func,
1162                "filter",
1163                id_template_filter_items,
1164                UI_TEMPLATE_ID_FILTER_ALL,
1165                "",
1166                "Optionally limit the items which can be selected");
1167   RNA_def_boolean(func, "live_icon", false, "", "Show preview instead of fixed icon");
1168   api_ui_item_common_text(func);
1169 
1170   func = RNA_def_function(srna, "template_ID_preview", "uiTemplateIDPreview");
1171   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1172   api_ui_item_rna_common(func);
1173   RNA_def_string(func, "new", NULL, 0, "", "Operator identifier to create a new ID block");
1174   RNA_def_string(
1175       func, "open", NULL, 0, "", "Operator identifier to open a file for creating a new ID block");
1176   RNA_def_string(func, "unlink", NULL, 0, "", "Operator identifier to unlink the ID block");
1177   RNA_def_int(
1178       func, "rows", 0, 0, INT_MAX, "Number of thumbnail preview rows to display", "", 0, INT_MAX);
1179   RNA_def_int(func,
1180               "cols",
1181               0,
1182               0,
1183               INT_MAX,
1184               "Number of thumbnail preview columns to display",
1185               "",
1186               0,
1187               INT_MAX);
1188   RNA_def_enum(func,
1189                "filter",
1190                id_template_filter_items,
1191                UI_TEMPLATE_ID_FILTER_ALL,
1192                "",
1193                "Optionally limit the items which can be selected");
1194   RNA_def_boolean(func, "hide_buttons", false, "", "Show only list, no buttons");
1195 
1196   func = RNA_def_function(srna, "template_any_ID", "rna_uiTemplateAnyID");
1197   parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
1198   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1199   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in data");
1200   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1201   parm = RNA_def_string(func,
1202                         "type_property",
1203                         NULL,
1204                         0,
1205                         "",
1206                         "Identifier of property in data giving the type of the ID-blocks to use");
1207   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1208   api_ui_item_common_text(func);
1209 
1210   func = RNA_def_function(srna, "template_ID_tabs", "uiTemplateIDTabs");
1211   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1212   api_ui_item_rna_common(func);
1213   RNA_def_string(func, "new", NULL, 0, "", "Operator identifier to create a new ID block");
1214   RNA_def_string(func, "menu", NULL, 0, "", "Context menu identifier");
1215   RNA_def_enum(func,
1216                "filter",
1217                id_template_filter_items,
1218                UI_TEMPLATE_ID_FILTER_ALL,
1219                "",
1220                "Optionally limit the items which can be selected");
1221 
1222   func = RNA_def_function(srna, "template_search", "uiTemplateSearch");
1223   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1224   api_ui_item_rna_common(func);
1225   parm = RNA_def_pointer(
1226       func, "search_data", "AnyType", "", "Data from which to take collection to search in");
1227   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1228   parm = RNA_def_string(
1229       func, "search_property", NULL, 0, "", "Identifier of search collection property");
1230   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1231   RNA_def_string(
1232       func, "new", NULL, 0, "", "Operator identifier to create a new item for the collection");
1233   RNA_def_string(func,
1234                  "unlink",
1235                  NULL,
1236                  0,
1237                  "",
1238                  "Operator identifier to unlink or delete the active "
1239                  "item from the collection");
1240 
1241   func = RNA_def_function(srna, "template_search_preview", "uiTemplateSearchPreview");
1242   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1243   api_ui_item_rna_common(func);
1244   parm = RNA_def_pointer(
1245       func, "search_data", "AnyType", "", "Data from which to take collection to search in");
1246   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1247   parm = RNA_def_string(
1248       func, "search_property", NULL, 0, "", "Identifier of search collection property");
1249   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1250   RNA_def_string(
1251       func, "new", NULL, 0, "", "Operator identifier to create a new item for the collection");
1252   RNA_def_string(func,
1253                  "unlink",
1254                  NULL,
1255                  0,
1256                  "",
1257                  "Operator identifier to unlink or delete the active "
1258                  "item from the collection");
1259   RNA_def_int(
1260       func, "rows", 0, 0, INT_MAX, "Number of thumbnail preview rows to display", "", 0, INT_MAX);
1261   RNA_def_int(func,
1262               "cols",
1263               0,
1264               0,
1265               INT_MAX,
1266               "Number of thumbnail preview columns to display",
1267               "",
1268               0,
1269               INT_MAX);
1270 
1271   func = RNA_def_function(srna, "template_path_builder", "rna_uiTemplatePathBuilder");
1272   parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
1273   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1274   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in data");
1275   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1276   parm = RNA_def_pointer(func, "root", "ID", "", "ID-block from which path is evaluated from");
1277   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED | PARM_RNAPTR);
1278   api_ui_item_common_text(func);
1279 
1280   func = RNA_def_function(srna, "template_modifiers", "uiTemplateModifiers");
1281   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1282   RNA_def_function_ui_description(func, "Generates the UI layout for the modifier stack");
1283 
1284   func = RNA_def_function(srna, "template_constraints", "uiTemplateConstraints");
1285   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1286   RNA_def_function_ui_description(func, "Generates the panels for the constraint stack");
1287   RNA_def_boolean(func,
1288                   "use_bone_constraints",
1289                   true,
1290                   "",
1291                   "Add panels for bone constraints instead of object constraints");
1292 
1293   func = RNA_def_function(srna, "template_grease_pencil_modifiers", "uiTemplateGpencilModifiers");
1294   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1295   RNA_def_function_ui_description(func,
1296                                   "Generates the panels for the grease pencil modifier stack");
1297 
1298   func = RNA_def_function(srna, "template_shaderfx", "uiTemplateShaderFx");
1299   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1300   RNA_def_function_ui_description(func, "Generates the panels for the shader effect stack");
1301 
1302   func = RNA_def_function(srna, "template_greasepencil_color", "uiTemplateGpencilColorPreview");
1303   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1304   api_ui_item_rna_common(func);
1305   RNA_def_int(
1306       func, "rows", 0, 0, INT_MAX, "Number of thumbnail preview rows to display", "", 0, INT_MAX);
1307   RNA_def_int(func,
1308               "cols",
1309               0,
1310               0,
1311               INT_MAX,
1312               "Number of thumbnail preview columns to display",
1313               "",
1314               0,
1315               INT_MAX);
1316   RNA_def_float(func, "scale", 1.0f, 0.1f, 1.5f, "Scale of the image thumbnails", "", 0.5f, 1.0f);
1317   RNA_def_enum(func,
1318                "filter",
1319                id_template_filter_items,
1320                UI_TEMPLATE_ID_FILTER_ALL,
1321                "",
1322                "Optionally limit the items which can be selected");
1323 
1324   func = RNA_def_function(srna, "template_constraint_header", "uiTemplateConstraintHeader");
1325   RNA_def_function_ui_description(func, "Generates the header for constraint panels");
1326   parm = RNA_def_pointer(func, "data", "Constraint", "", "Constraint data");
1327   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1328 
1329   func = RNA_def_function(srna, "template_preview", "uiTemplatePreview");
1330   RNA_def_function_ui_description(
1331       func, "Item. A preview window for materials, textures, lights or worlds");
1332   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1333   parm = RNA_def_pointer(func, "id", "ID", "", "ID data-block");
1334   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1335   RNA_def_boolean(func, "show_buttons", true, "", "Show preview buttons?");
1336   RNA_def_pointer(func, "parent", "ID", "", "ID data-block");
1337   RNA_def_pointer(func, "slot", "TextureSlot", "", "Texture slot");
1338   RNA_def_string(
1339       func,
1340       "preview_id",
1341       NULL,
1342       0,
1343       "",
1344       "Identifier of this preview widget, if not set the ID type will be used "
1345       "(i.e. all previews of materials without explicit ID will have the same size...)");
1346 
1347   func = RNA_def_function(srna, "template_curve_mapping", "uiTemplateCurveMapping");
1348   RNA_def_function_ui_description(
1349       func, "Item. A curve mapping widget used for e.g falloff curves for lights");
1350   api_ui_item_rna_common(func);
1351   RNA_def_enum(func, "type", curve_type_items, 0, "Type", "Type of curves to display");
1352   RNA_def_boolean(func, "levels", false, "", "Show black/white levels");
1353   RNA_def_boolean(func, "brush", false, "", "Show brush options");
1354   RNA_def_boolean(func, "use_negative_slope", false, "", "Use a negative slope by default");
1355   RNA_def_boolean(func, "show_tone", false, "", "Show tone options");
1356 
1357   func = RNA_def_function(srna, "template_curveprofile", "uiTemplateCurveProfile");
1358   RNA_def_function_ui_description(func, "A profile path editor used for custom profiles");
1359   api_ui_item_rna_common(func);
1360 
1361   func = RNA_def_function(srna, "template_color_ramp", "uiTemplateColorRamp");
1362   RNA_def_function_ui_description(func, "Item. A color ramp widget");
1363   api_ui_item_rna_common(func);
1364   RNA_def_boolean(func, "expand", false, "", "Expand button to show more detail");
1365 
1366   func = RNA_def_function(srna, "template_icon", "uiTemplateIcon");
1367   RNA_def_function_ui_description(func, "Display a large icon");
1368   parm = RNA_def_int(func, "icon_value", 0, 0, INT_MAX, "Icon to display", "", 0, INT_MAX);
1369   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1370   RNA_def_float(func,
1371                 "scale",
1372                 1.0f,
1373                 1.0f,
1374                 100.0f,
1375                 "Scale",
1376                 "Scale the icon size (by the button size)",
1377                 1.0f,
1378                 100.0f);
1379 
1380   func = RNA_def_function(srna, "template_icon_view", "uiTemplateIconView");
1381   RNA_def_function_ui_description(func, "Enum. Large widget showing Icon previews");
1382   api_ui_item_rna_common(func);
1383   RNA_def_boolean(func, "show_labels", false, "", "Show enum label in preview buttons");
1384   RNA_def_float(func,
1385                 "scale",
1386                 6.0f,
1387                 1.0f,
1388                 100.0f,
1389                 "UI Units",
1390                 "Scale the button icon size (by the button size)",
1391                 1.0f,
1392                 100.0f);
1393   RNA_def_float(func,
1394                 "scale_popup",
1395                 5.0f,
1396                 1.0f,
1397                 100.0f,
1398                 "Scale",
1399                 "Scale the popup icon size (by the button size)",
1400                 1.0f,
1401                 100.0f);
1402 
1403   func = RNA_def_function(srna, "template_histogram", "uiTemplateHistogram");
1404   RNA_def_function_ui_description(func, "Item. A histogramm widget to analyze imaga data");
1405   api_ui_item_rna_common(func);
1406 
1407   func = RNA_def_function(srna, "template_waveform", "uiTemplateWaveform");
1408   RNA_def_function_ui_description(func, "Item. A waveform widget to analyze imaga data");
1409   api_ui_item_rna_common(func);
1410 
1411   func = RNA_def_function(srna, "template_vectorscope", "uiTemplateVectorscope");
1412   RNA_def_function_ui_description(func, "Item. A vectorscope widget to analyze imaga data");
1413   api_ui_item_rna_common(func);
1414 
1415   func = RNA_def_function(srna, "template_layers", "uiTemplateLayers");
1416   api_ui_item_rna_common(func);
1417   parm = RNA_def_pointer(
1418       func, "used_layers_data", "AnyType", "", "Data from which to take property");
1419   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED | PARM_RNAPTR);
1420   parm = RNA_def_string(
1421       func, "used_layers_property", NULL, 0, "", "Identifier of property in data");
1422   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1423   parm = RNA_def_int(func, "active_layer", 0, 0, INT_MAX, "Active Layer", "", 0, INT_MAX);
1424   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1425 
1426   func = RNA_def_function(srna, "template_color_picker", "uiTemplateColorPicker");
1427   RNA_def_function_ui_description(func, "Item. A color wheel widget to pick colors");
1428   api_ui_item_rna_common(func);
1429   RNA_def_boolean(
1430       func, "value_slider", false, "", "Display the value slider to the right of the color wheel");
1431   RNA_def_boolean(func,
1432                   "lock",
1433                   false,
1434                   "",
1435                   "Lock the color wheel display to value 1.0 regardless of actual color");
1436   RNA_def_boolean(
1437       func, "lock_luminosity", false, "", "Keep the color at its original vector length");
1438   RNA_def_boolean(func, "cubic", false, "", "Cubic saturation for picking values close to white");
1439 
1440   func = RNA_def_function(srna, "template_palette", "uiTemplatePalette");
1441   RNA_def_function_ui_description(func, "Item. A palette used to pick colors");
1442   api_ui_item_rna_common(func);
1443   RNA_def_boolean(func, "color", 0, "", "Display the colors as colors or values");
1444 
1445   func = RNA_def_function(srna, "template_image_layers", "uiTemplateImageLayers");
1446   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1447   parm = RNA_def_pointer(func, "image", "Image", "", "");
1448   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1449   parm = RNA_def_pointer(func, "image_user", "ImageUser", "", "");
1450   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1451 
1452   func = RNA_def_function(srna, "template_image", "uiTemplateImage");
1453   RNA_def_function_ui_description(
1454       func, "Item(s). User interface for selecting images and their source paths");
1455   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1456   api_ui_item_rna_common(func);
1457   parm = RNA_def_pointer(func, "image_user", "ImageUser", "", "");
1458   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1459   RNA_def_boolean(func, "compact", false, "", "Use more compact layout");
1460   RNA_def_boolean(func, "multiview", false, "", "Expose Multi-View options");
1461 
1462   func = RNA_def_function(srna, "template_image_settings", "uiTemplateImageSettings");
1463   RNA_def_function_ui_description(func, "User interface for setting image format options");
1464   parm = RNA_def_pointer(func, "image_settings", "ImageFormatSettings", "", "");
1465   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1466   RNA_def_boolean(func, "color_management", false, "", "Show color management settings");
1467 
1468   func = RNA_def_function(srna, "template_image_stereo_3d", "uiTemplateImageStereo3d");
1469   RNA_def_function_ui_description(func, "User interface for setting image stereo 3d options");
1470   parm = RNA_def_pointer(func, "stereo_3d_format", "Stereo3dFormat", "", "");
1471   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1472 
1473   func = RNA_def_function(srna, "template_image_views", "uiTemplateImageViews");
1474   RNA_def_function_ui_description(func, "User interface for setting image views output options");
1475   parm = RNA_def_pointer(func, "image_settings", "ImageFormatSettings", "", "");
1476   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1477 
1478   func = RNA_def_function(srna, "template_movieclip", "uiTemplateMovieClip");
1479   RNA_def_function_ui_description(
1480       func, "Item(s). User interface for selecting movie clips and their source paths");
1481   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1482   api_ui_item_rna_common(func);
1483   RNA_def_boolean(func, "compact", false, "", "Use more compact layout");
1484 
1485   func = RNA_def_function(srna, "template_track", "uiTemplateTrack");
1486   RNA_def_function_ui_description(func, "Item. A movie-track widget to preview tracking image.");
1487   api_ui_item_rna_common(func);
1488 
1489   func = RNA_def_function(srna, "template_marker", "uiTemplateMarker");
1490   RNA_def_function_ui_description(func, "Item. A widget to control single marker settings.");
1491   api_ui_item_rna_common(func);
1492   parm = RNA_def_pointer(func, "clip_user", "MovieClipUser", "", "");
1493   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1494   parm = RNA_def_pointer(func, "track", "MovieTrackingTrack", "", "");
1495   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1496   RNA_def_boolean(func, "compact", false, "", "Use more compact layout");
1497 
1498   func = RNA_def_function(
1499       srna, "template_movieclip_information", "uiTemplateMovieclipInformation");
1500   RNA_def_function_ui_description(func, "Item. Movie clip information data.");
1501   api_ui_item_rna_common(func);
1502   parm = RNA_def_pointer(func, "clip_user", "MovieClipUser", "", "");
1503   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1504 
1505   func = RNA_def_function(srna, "template_list", "uiTemplateList");
1506   RNA_def_function_ui_description(func, "Item. A list widget to display data, e.g. vertexgroups.");
1507   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1508   parm = RNA_def_string(func, "listtype_name", NULL, 0, "", "Identifier of the list type to use");
1509   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1510   parm = RNA_def_string(
1511       func,
1512       "list_id",
1513       NULL,
1514       0,
1515       "",
1516       "Identifier of this list widget (mandatory when using default \"" UI_UL_DEFAULT_CLASS_NAME
1517       "\" class). "
1518       "If this not an empty string, the uilist gets a custom ID, otherwise it takes the "
1519       "name of the class used to define the uilist (for example, if the "
1520       "class name is \"OBJECT_UL_vgroups\", and list_id is not set by the "
1521       "script, then bl_idname = \"OBJECT_UL_vgroups\")");
1522   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1523   parm = RNA_def_pointer(
1524       func, "dataptr", "AnyType", "", "Data from which to take the Collection property");
1525   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED | PARM_RNAPTR);
1526   parm = RNA_def_string(
1527       func, "propname", NULL, 0, "", "Identifier of the Collection property in data");
1528   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1529   parm = RNA_def_pointer(func,
1530                          "active_dataptr",
1531                          "AnyType",
1532                          "",
1533                          "Data from which to take the integer property, index of the active item");
1534   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1535   parm = RNA_def_string(
1536       func,
1537       "active_propname",
1538       NULL,
1539       0,
1540       "",
1541       "Identifier of the integer property in active_data, index of the active item");
1542   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1543   RNA_def_string(func,
1544                  "item_dyntip_propname",
1545                  NULL,
1546                  0,
1547                  "",
1548                  "Identifier of a string property in items, to use as tooltip content");
1549   RNA_def_int(func,
1550               "rows",
1551               5,
1552               0,
1553               INT_MAX,
1554               "",
1555               "Default and minimum number of rows to display",
1556               0,
1557               INT_MAX);
1558   RNA_def_int(
1559       func, "maxrows", 5, 0, INT_MAX, "", "Default maximum number of rows to display", 0, INT_MAX);
1560   RNA_def_enum(func,
1561                "type",
1562                rna_enum_uilist_layout_type_items,
1563                UILST_LAYOUT_DEFAULT,
1564                "Type",
1565                "Type of layout to use");
1566   RNA_def_int(func,
1567               "columns",
1568               9,
1569               0,
1570               INT_MAX,
1571               "",
1572               "Number of items to display per row, for GRID layout",
1573               0,
1574               INT_MAX);
1575   RNA_def_boolean(func, "sort_reverse", false, "", "Display items in reverse order by default");
1576   RNA_def_boolean(func, "sort_lock", false, "", "Lock display order to default value");
1577 
1578   func = RNA_def_function(srna, "template_running_jobs", "uiTemplateRunningJobs");
1579   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1580 
1581   RNA_def_function(srna, "template_operator_search", "uiTemplateOperatorSearch");
1582   RNA_def_function(srna, "template_menu_search", "uiTemplateMenuSearch");
1583 
1584   func = RNA_def_function(srna, "template_header_3D_mode", "uiTemplateHeader3D_mode");
1585   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1586   RNA_def_function_ui_description(func, "");
1587 
1588   func = RNA_def_function(srna, "template_edit_mode_selection", "uiTemplateEditModeSelection");
1589   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1590   RNA_def_function_ui_description(
1591       func, "Inserts common 3DView Edit modes header UI (selector for selection mode)");
1592 
1593   func = RNA_def_function(srna, "template_reports_banner", "uiTemplateReportsBanner");
1594   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1595 
1596   func = RNA_def_function(srna, "template_input_status", "uiTemplateInputStatus");
1597   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1598 
1599   func = RNA_def_function(srna, "template_node_link", "uiTemplateNodeLink");
1600   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1601   parm = RNA_def_pointer(func, "ntree", "NodeTree", "", "");
1602   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1603   parm = RNA_def_pointer(func, "node", "Node", "", "");
1604   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1605   parm = RNA_def_pointer(func, "socket", "NodeSocket", "", "");
1606   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1607 
1608   func = RNA_def_function(srna, "template_node_view", "uiTemplateNodeView");
1609   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1610   parm = RNA_def_pointer(func, "ntree", "NodeTree", "", "");
1611   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1612   parm = RNA_def_pointer(func, "node", "Node", "", "");
1613   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1614   parm = RNA_def_pointer(func, "socket", "NodeSocket", "", "");
1615   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1616 
1617   func = RNA_def_function(srna, "template_texture_user", "uiTemplateTextureUser");
1618   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1619 
1620   func = RNA_def_function(
1621       srna, "template_keymap_item_properties", "uiTemplateKeymapItemProperties");
1622   parm = RNA_def_pointer(func, "item", "KeyMapItem", "", "");
1623   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
1624 
1625   func = RNA_def_function(srna, "template_component_menu", "uiTemplateComponentMenu");
1626   RNA_def_function_ui_description(func, "Item. Display expanded property in a popup menu");
1627   parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
1628   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED | PARM_RNAPTR);
1629   parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in data");
1630   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1631   RNA_def_string(func, "name", NULL, 0, "", "");
1632 
1633   /* color management templates */
1634   func = RNA_def_function(srna, "template_colorspace_settings", "uiTemplateColorspaceSettings");
1635   RNA_def_function_ui_description(func, "Item. A widget to control input color space settings.");
1636   api_ui_item_rna_common(func);
1637 
1638   func = RNA_def_function(
1639       srna, "template_colormanaged_view_settings", "uiTemplateColormanagedViewSettings");
1640   RNA_def_function_ui_description(
1641       func, "Item. A widget to control color managed view settings settings.");
1642   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1643   api_ui_item_rna_common(func);
1644 #  if 0
1645   RNA_def_boolean(func,
1646                   "show_global_settings",
1647                   false,
1648                   "",
1649                   "Show widgets to control global color management settings");
1650 #  endif
1651 
1652   /* node socket icon */
1653   func = RNA_def_function(srna, "template_node_socket", "uiTemplateNodeSocket");
1654   RNA_def_function_ui_description(func, "Node Socket Icon");
1655   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1656   RNA_def_float_array(
1657       func, "color", 4, node_socket_color_default, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);
1658 
1659   func = RNA_def_function(srna, "template_cache_file", "rna_uiTemplateCacheFile");
1660   RNA_def_function_ui_description(
1661       func, "Item(s). User interface for selecting cache files and their source paths");
1662   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1663   api_ui_item_rna_common(func);
1664 
1665   func = RNA_def_function(srna, "template_recent_files", "uiTemplateRecentFiles");
1666   RNA_def_function_ui_description(func, "Show list of recently saved .blend files");
1667   RNA_def_int(func, "rows", 5, 1, INT_MAX, "", "Maximum number of items to show", 1, INT_MAX);
1668   parm = RNA_def_int(func, "found", 0, 0, INT_MAX, "", "Number of items drawn", 0, INT_MAX);
1669   RNA_def_function_return(func, parm);
1670 
1671   func = RNA_def_function(srna, "template_file_select_path", "uiTemplateFileSelectPath");
1672   RNA_def_function_ui_description(func,
1673                                   "Item. A text button to set the active file browser path.");
1674   parm = RNA_def_pointer(func, "params", "FileSelectParams", "", "");
1675   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
1676   RNA_def_function_flag(func, FUNC_USE_CONTEXT);
1677 
1678   func = RNA_def_function(
1679       srna, "template_event_from_keymap_item", "rna_uiTemplateEventFromKeymapItem");
1680   RNA_def_function_ui_description(func, "Display keymap item as icons/text");
1681   parm = RNA_def_property(func, "item", PROP_POINTER, PROP_NONE);
1682   RNA_def_property_struct_type(parm, "KeyMapItem");
1683   RNA_def_property_ui_text(parm, "Item", "");
1684   RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
1685   api_ui_item_common_text(func);
1686 }
1687 
1688 #endif
1689