[Bf-blender-cvs] [5bcb0c99350] master: UI: Allow label for Template-ID (respecting property split layout)
Julian Eisel
noreply at git.blender.org
Mon Nov 25 19:51:38 CET 2019
Commit: 5bcb0c9935033d9d9983838bd4f5ed226627c2e9
Author: Julian Eisel
Date: Mon Nov 25 19:41:30 2019 +0100
Branches: master
https://developer.blender.org/rB5bcb0c9935033d9d9983838bd4f5ed226627c2e9
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.
===================================================================
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface_layout.c
M source/blender/editors/interface/interface_templates.c
M source/blender/editors/space_clip/clip_buttons.c
M source/blender/editors/space_image/image_buttons.c
M source/blender/editors/space_nla/nla_buttons.c
M source/blender/editors/space_node/drawnode.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 69229f25917..b81fa4ae483 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1875,7 +1875,8 @@ void uiTemplateID(uiLayout *layout,
const char *openop,
const char *unlinkop,
int filter,
- const bool live_icon);
+ const bool live_icon,
+ const char *text);
void uiTemplateIDBrowse(uiLayout *layout,
struct bContext *C,
struct PointerRNA *ptr,
@@ -1883,7 +1884,8 @@ void uiTemplateIDBrowse(uiLayout *layout,
const char *newop,
const char *openop,
const char *unlinkop,
- int filter);
+ int filter,
+ const char *text);
void uiTemplateIDPreview(uiLayout *layout,
struct bContext *C,
struct PointerRNA *ptr,
@@ -2270,6 +2272,7 @@ void uiItemsFullEnumO_items(uiLayout *layout,
int totitem);
void uiItemL(uiLayout *layout, const char *name, int icon); /* label */
+uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon);
/* label icon for dragging */
void uiItemLDrag(uiLayout *layout, struct PointerRNA *ptr, const char *name, int icon);
/* menu */
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;
diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c
index 45707d74d2e..34b4967beaf 100644
--- a/source/blender/editors/space_clip/clip_buttons.c
+++ b/source/blender/editors/space_clip/clip_buttons.c
@@ -135,8 +135,16 @@ void uiTemplateMovieClip(
uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
if (!compact) {
- uiTemplateID(
- layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL, false);
+ uiTemplateID(layout,
+ C,
+ ptr,
+ propname,
+ NULL,
+ "CLIP_OT_open",
+ NULL,
+ UI_TEMPLATE_ID_FILTER_ALL,
+ false,
+ NULL);
}
if (clip) {
diff --git a/source/blender/editors/space_image/image_buttons.c b/source/blender/editors/space_image/image_buttons.c
index 64e1c02590e..270fe0c59dc 100644
--- a/source/blender/editors/space_image/image_buttons.c
+++ b/source/blender/editors/space_image/image_buttons.c
@@ -813,7 +813,8 @@ void uiTemplateImage(uiLayout *layout,
"IMAGE_OT_open",
NULL,
UI_TEMPLATE_ID_FILTER_ALL,
- false);
+ false,
+ NULL);
if (ima != NULL) {
uiItemS(layout);
diff --git a/source/blender/editors/space_nla/nla_buttons.c b/source/blender/editors/space_nla/nla_buttons.c
index 126b20a028e..b908ed2b7ee 100644
--- a/source/blender/editors/space_nla/nla_buttons.c
+++ b/source/blender/editors/space_nla/nla_buttons.c
@@ -296,7 +296,8 @@ static void nla_panel_animdata(const bContext *C, Panel *pa)
NULL,
"NLA_OT_action_unlink",
UI_TEMPLATE_ID_FILTER_ALL,
- false);
+ false,
+ NULL);
/* extrapolation */
row = uiLayoutRow(layout, true);
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index a5b18ff7589..b60764c410d 100644
--- a/source/blender/editors
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list