[Bf-blender-cvs] [b0f207db15c] master: UI: (Internal) utility for more controllable property split layout

Julian Eisel noreply at git.blender.org
Mon Apr 27 17:02:08 CEST 2020


Commit: b0f207db15c5698f11db1168d2882f056583d6d5
Author: Julian Eisel
Date:   Mon Apr 27 16:43:36 2020 +0200
Branches: master
https://developer.blender.org/rBb0f207db15c5698f11db1168d2882f056583d6d5

UI: (Internal) utility for more controllable property split layout

Adds a wrapper-struct to create and return the three layouts required
for the propery split layout (i.e. `UILayout.use_property_split`). This
gives more flexibility for special treatment.
E.g. needed for adding the arrow icon buttons when there is a hierarchy
of nodes to be represented in the material properties (needs inserting
in the text column to not offset the split layout).

This commit also makes use of the utility for
`uiItemL_respect_property_split()`.

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

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

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

diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index f83088dd4d5..709e05c18b6 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2311,6 +2311,14 @@ void uiItemsFullEnumO_items(uiLayout *layout,
                             const EnumPropertyItem *item_array,
                             int totitem);
 
+typedef struct uiPropertySplitWrapper {
+  uiLayout *label_column;
+  uiLayout *property_row;
+  uiLayout *decorate_column;
+} uiPropertySplitWrapper;
+
+uiPropertySplitWrapper uiItemPropertySplitWrapperCreate(uiLayout *parent_layout);
+
 void uiItemL(uiLayout *layout, const char *name, int icon); /* label */
 void uiItemL_ex(
     uiLayout *layout, const char *name, int icon, const bool highlight, const bool redalert);
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index 2ca4af32bc2..0609424fd61 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -3162,35 +3162,40 @@ void uiItemL(uiLayout *layout, const char *name, int 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 A layout placed in the row after the split layout. Used to place decorator items.
+ * Normally, we handle the split layout in #uiItemFullR(), but there are other cases where the
+ * logic is needed. Ideally, #uiItemFullR() could just call this, but it currently has too many
+ * special needs.
  */
-uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon)
+uiPropertySplitWrapper uiItemPropertySplitWrapperCreate(uiLayout *parent_layout)
 {
-  if (layout->item.flag & UI_ITEM_PROP_SEP) {
-    uiBlock *block = uiLayoutGetBlock(layout);
+  uiPropertySplitWrapper split_wrapper = {NULL};
+
+  uiLayout *layout_row = uiLayoutRow(parent_layout, true);
+  uiLayout *layout_split = uiLayoutSplit(layout_row, UI_ITEM_PROP_SEP_DIVIDE, true);
 
-    uiLayout *layout_row = uiLayoutRow(layout, true);
-    uiLayout *layout_split = uiLayoutSplit(layout_row, UI_ITEM_PROP_SEP_DIVIDE, true);
-    uiLayout *layout_sub = uiLayoutColumn(layout_split, true);
+  layout_split->space = 0;
+  split_wrapper.label_column = uiLayoutColumn(layout_split, true);
+  split_wrapper.label_column->alignment = UI_LAYOUT_ALIGN_RIGHT;
+  split_wrapper.property_row = ui_item_prop_split_layout_hack(parent_layout, layout_split);
+  split_wrapper.decorate_column = uiLayoutColumn(layout_row, true);
 
-    layout_split->space = layout_sub->space = layout_row->space = 0;
-    layout_sub->alignment = UI_LAYOUT_ALIGN_RIGHT;
+  return split_wrapper;
+}
 
-    uiItemL_(layout_sub, text, icon);
+/*
+ * Helper to add a label and creates a property split layout if needed.
+ */
+uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon)
+{
+  if (layout->item.flag & UI_ITEM_PROP_SEP) {
+    uiBlock *block = uiLayoutGetBlock(layout);
+    uiPropertySplitWrapper split_wrapper = uiItemPropertySplitWrapperCreate(layout);
+    /* Further items added to 'layout' will automatically be added to split_wrapper.property_row */
 
-    layout_split = ui_item_prop_split_layout_hack(layout, layout_split);
-    UI_block_layout_set_current(block, layout_split);
+    uiItemL_(split_wrapper.label_column, text, icon);
+    UI_block_layout_set_current(block, split_wrapper.property_row);
 
-    /* The decorator layout uses the row the split layout was inserted to.  */
-    uiLayout *layout_decorator = layout_row;
-    return layout_decorator;
+    return split_wrapper.decorate_column;
   }
   else {
     char namestr[UI_MAX_NAME_STR];



More information about the Bf-blender-cvs mailing list