diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2019-11-25 21:41:30 +0300 |
---|---|---|
committer | Julian Eisel <eiseljulian@gmail.com> | 2019-11-25 21:50:34 +0300 |
commit | 5bcb0c9935033d9d9983838bd4f5ed226627c2e9 (patch) | |
tree | 4923d38f4ba23209dc07eab80562dd0bad59c0d5 /source/blender/editors/interface | |
parent | 03cdfc2ff6df61a247b90c4ad8bb1b26034b4505 (diff) |
UI: Allow label for Template-ID (respecting property split layout)
Adds a `text` parameter to `bpy.types.uiLayout.template_ID()` which
causes a label to be added, as usual. Adding the label also makes the
template respect the `bpy.types.uiLayout.use_property_split` option.
Also fixes wrong layout being used in the template-ID, although I think
that didn't cause issues in practice.
Sergey requested this for usage in the Movie Clip Editor.
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 35 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_templates.c | 47 |
2 files changed, 74 insertions, 8 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 2a4c2aba4a1..52696475c20 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -2956,6 +2956,41 @@ void uiItemL(uiLayout *layout, const char *name, int icon) uiItemL_(layout, name, icon); } +/** + * Helper to add a label, which handles logic for split property layout if needed. + * + * Normally, we handle the split layout in #uiItemFullR(), but there are other cases where we may + * want to use the logic. For those this helper was added, although it will likely have to be + * extended to support more cases. + * Ideally, #uiItemFullR() could just call this, but it currently has too many special needs. + * + * \return the layout to place the item(s) associated to the label in. + */ +uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon) +{ + if (layout->item.flag & UI_ITEM_PROP_SEP) { + uiLayout *layout_split = uiLayoutSplit(layout, UI_ITEM_PROP_SEP_DIVIDE, true); + uiLayout *layout_sub = uiLayoutColumn(layout_split, true); + + layout_split->space = layout_sub->space = layout->space = 0; + layout_sub->alignment = UI_LAYOUT_ALIGN_RIGHT; + + uiItemL_(layout_sub, text, icon); + + /* Give caller a new sub-row to place items in. */ + return uiLayoutRow(layout_split, true); + } + else { + char namestr[UI_MAX_NAME_STR]; + if (text) { + text = ui_item_name_add_colon(text, namestr); + } + uiItemL_(layout, text, icon); + + return layout; + } +} + void uiItemLDrag(uiLayout *layout, PointerRNA *ptr, const char *name, int icon) { uiBut *but = uiItemL_(layout, name, icon); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index a65e70d4109..5788b741108 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -780,6 +780,7 @@ static void template_ID(bContext *C, const char *newop, const char *openop, const char *unlinkop, + const char *text, const bool live_icon, const bool hide_buttons) { @@ -803,6 +804,11 @@ static void template_ID(bContext *C, type = idptr.type; } + if (text) { + /* Add label resepecting the seperated layout property split state. */ + layout = uiItemL_respect_property_split(layout, text, ICON_NONE); + } + if (flag & UI_ID_BROWSE) { template_add_button_search_menu(C, layout, @@ -1187,6 +1193,7 @@ static void ui_template_id(uiLayout *layout, const char *newop, const char *openop, const char *unlinkop, + const char *text, int flag, int prv_rows, int prv_cols, @@ -1239,13 +1246,22 @@ static void ui_template_id(uiLayout *layout, */ if (template_ui->idlb) { if (use_tabs) { - uiLayoutRow(layout, true); + layout = uiLayoutRow(layout, true); template_ID_tabs(C, layout, template_ui, type, flag, newop, unlinkop); } else { - uiLayoutRow(layout, true); - template_ID( - C, layout, template_ui, type, flag, newop, openop, unlinkop, live_icon, hide_buttons); + layout = uiLayoutRow(layout, true); + template_ID(C, + layout, + template_ui, + type, + flag, + newop, + openop, + unlinkop, + text, + live_icon, + hide_buttons); } } @@ -1260,7 +1276,8 @@ void uiTemplateID(uiLayout *layout, const char *openop, const char *unlinkop, int filter, - const bool live_icon) + const bool live_icon, + const char *text) { ui_template_id(layout, C, @@ -1269,6 +1286,7 @@ void uiTemplateID(uiLayout *layout, newop, openop, unlinkop, + text, UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, 0, 0, @@ -1286,7 +1304,8 @@ void uiTemplateIDBrowse(uiLayout *layout, const char *newop, const char *openop, const char *unlinkop, - int filter) + int filter, + const char *text) { ui_template_id(layout, C, @@ -1295,6 +1314,7 @@ void uiTemplateIDBrowse(uiLayout *layout, newop, openop, unlinkop, + text, UI_ID_BROWSE | UI_ID_RENAME, 0, 0, @@ -1324,6 +1344,7 @@ void uiTemplateIDPreview(uiLayout *layout, newop, openop, unlinkop, + NULL, UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS, rows, cols, @@ -1350,6 +1371,7 @@ void uiTemplateGpencilColorPreview(uiLayout *layout, NULL, NULL, NULL, + NULL, UI_ID_BROWSE | UI_ID_PREVIEWS | UI_ID_DELETE, rows, cols, @@ -1378,6 +1400,7 @@ void uiTemplateIDTabs(uiLayout *layout, newop, NULL, unlinkop, + NULL, UI_ID_BROWSE | UI_ID_RENAME, 0, 0, @@ -7485,8 +7508,16 @@ void uiTemplateCacheFile(uiLayout *layout, bContext *C, PointerRNA *ptr, const c uiLayoutSetContextPointer(layout, "edit_cachefile", &fileptr); - uiTemplateID( - layout, C, ptr, propname, NULL, "CACHEFILE_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false); + uiTemplateID(layout, + C, + ptr, + propname, + NULL, + "CACHEFILE_OT_open", + NULL, + UI_TEMPLATE_ID_FILTER_ALL, + false, + NULL); if (!file) { return; |