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/interface_layout.c | |
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/interface_layout.c')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 35 |
1 files changed, 35 insertions, 0 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); |