Commit: 756be8f4d8ff2ba3915b67c36c2e40f1652397da
Author: Campbell Barton
Date:   Thu Dec 20 11:33:08 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB756be8f4d8ff2ba3915b67c36c2e40f1652397da

UI: add method to draw menu contents

This supports expanding menu contents into an existing layout.

Needed to fix T58937.

===================================================================

M       source/blender/editors/include/UI_interface.h
M       source/blender/editors/interface/interface_layout.c
M       source/blender/makesrna/intern/rna_ui_api.c

===================================================================

diff --git a/source/blender/editors/include/UI_interface.h 
b/source/blender/editors/include/UI_interface.h
index bb45fbd4615..80ac5e72868 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1190,6 +1190,7 @@ void uiItemsFullEnumO_items(
 void uiItemL(uiLayout *layout, const char *name, int icon); /* label */
 void uiItemLDrag(uiLayout *layout, struct PointerRNA *ptr, const char *name, 
int icon); /* label icon for dragging */
 void uiItemM(uiLayout *layout, const char *menuname, const char *name, int 
icon); /* menu */
+void uiItemMContents(uiLayout *layout, const char *menuname); /* menu contents 
*/
 void uiItemV(uiLayout *layout, const char *name, int icon, int argval); /* 
value */
 void uiItemS(uiLayout *layout); /* separator */
 void uiItemS_ex(uiLayout *layout, float factor);
diff --git a/source/blender/editors/interface/interface_layout.c 
b/source/blender/editors/interface/interface_layout.c
index 9e9c244cfaf..afcbcbbdf52 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -2263,10 +2263,7 @@ static uiBut *ui_item_menu(
 
 void uiItemM(uiLayout *layout, const char *menuname, const char *name, int 
icon)
 {
-       MenuType *mt;
-
-       mt = WM_menutype_find(menuname, false);
-
+       MenuType *mt = WM_menutype_find(menuname, false);
        if (mt == NULL) {
                RNA_warning("not found %s", menuname);
                return;
@@ -2284,6 +2281,19 @@ void uiItemM(uiLayout *layout, const char *menuname, 
const char *name, int icon)
                mt->description ? TIP_(mt->description) : "", false);
 }
 
+void uiItemMContents(uiLayout *layout, const char *menuname)
+{
+       MenuType *mt = WM_menutype_find(menuname, false);
+       if (mt == NULL) {
+               RNA_warning("not found %s", menuname);
+               return;
+       }
+
+       uiBlock *block = layout->root->block;
+       bContext *C = block->evil_C;
+       UI_menutype_draw(C, mt, layout);
+}
+
 /* popover */
 void uiItemPopoverPanel_ptr(uiLayout *layout, bContext *C, PanelType *pt, 
const char *name, int icon)
 {
diff --git a/source/blender/makesrna/intern/rna_ui_api.c 
b/source/blender/makesrna/intern/rna_ui_api.c
index 4d361920dcb..fdf2b5f311b 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -294,6 +294,12 @@ static void rna_uiItemM(
        uiItemM(layout, menuname, name, icon);
 }
 
+static void rna_uiItemM_contents(
+        uiLayout *layout, const char *menuname)
+{
+       uiItemMContents(layout, menuname);
+}
+
 static void rna_uiItemPopoverPanel(
         uiLayout *layout, bContext *C,
         const char *panel_type, const char *name, const char *text_ctxt,
@@ -741,6 +747,10 @@ void RNA_api_ui_layout(StructRNA *srna)
        parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon 
of the item");
 
+       func = RNA_def_function(srna, "menu_contents", "rna_uiItemM_contents");
+       parm = RNA_def_string(func, "menu", NULL, 0, "", "Identifier of the 
menu");
+       RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
        func = RNA_def_function(srna, "popover", "rna_uiItemPopoverPanel");
        RNA_def_function_flag(func, FUNC_USE_CONTEXT);
        parm = RNA_def_string(func, "panel", NULL, 0, "", "Identifier of the 
panel");

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to