UI: Support split property layout for pointer search buttons

Pointer search buttons created with `uiItemPointerR()` (which allows
also passing a collection property to search in) did not work with the
split property layout (i.e. `uiLayout.use_property_split`).
For example vertex group search buttons typically use this.

Note that decorators (`uiLayout.use_property_decorate`) are not
supported yet. Although if they are enabled, the decorator column is
still created to keep the layout alignment visually intact. Also re-uses
the existing hack to allow placing multiple items in the row before the
decorator column.

Needed for some in-progress changes to the modifier stack UI.
This commit is contained in:
Julian Eisel 2020-04-05 14:19:24 +02:00
parent 3e8a818419
commit f1573731bc
2 changed files with 38 additions and 22 deletions

View File

@ -945,19 +945,25 @@ static uiBut *ui_item_with_label(uiLayout *layout,
PropertyType type; PropertyType type;
PropertySubType subtype; PropertySubType subtype;
int prop_but_width = w_hint; int prop_but_width = w_hint;
#ifdef UI_PROP_DECORATE
uiLayout *layout_prop_decorate = NULL;
const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0); const bool use_prop_sep = ((layout->item.flag & UI_ITEM_PROP_SEP) != 0);
#endif
/* Always align item with label since text is already given enough space not to overlap. */ /* Always align item with label since text is already given enough space not to overlap. */
sub = uiLayoutRow(layout, true); sub = uiLayoutRow(layout, true);
UI_block_layout_set_current(block, sub); UI_block_layout_set_current(block, sub);
#ifdef UI_PROP_DECORATE
if (name[0]) { if (name[0]) {
int w_label;
if (use_prop_sep) { if (use_prop_sep) {
w_label = (int)((w_hint * 2) * UI_ITEM_PROP_SEP_DIVIDE); layout_prop_decorate = uiItemL_respect_property_split(layout, name, 0);
} }
else { else
#endif
{
int w_label;
if (ui_layout_variable_size(layout)) { if (ui_layout_variable_size(layout)) {
/* w_hint is width for label in this case. /* w_hint is width for label in this case.
* Use a default width for property button(s) */ * Use a default width for property button(s) */
@ -967,13 +973,7 @@ static uiBut *ui_item_with_label(uiLayout *layout,
else { else {
w_label = w_hint / 3; w_label = w_hint / 3;
} }
} uiDefBut(block, UI_BTYPE_LABEL, 0, name, x, y, w_label, h, NULL, 0.0, 0.0, 0, 0, "");
uiBut *but_label = uiDefBut(
block, UI_BTYPE_LABEL, 0, name, x, y, w_label, h, NULL, 0.0, 0.0, 0, 0, "");
if (use_prop_sep) {
but_label->drawflag |= UI_BUT_TEXT_RIGHT;
but_label->drawflag &= ~UI_BUT_TEXT_LEFT;
} }
} }
@ -1053,7 +1053,7 @@ static uiBut *ui_item_with_label(uiLayout *layout,
if (layout->item.flag & UI_ITEM_PROP_SEP) { if (layout->item.flag & UI_ITEM_PROP_SEP) {
if ((layout->item.flag & UI_ITEM_PROP_DECORATE) && if ((layout->item.flag & UI_ITEM_PROP_DECORATE) &&
(layout->item.flag & UI_ITEM_PROP_DECORATE_NO_PAD) == 0) { (layout->item.flag & UI_ITEM_PROP_DECORATE_NO_PAD) == 0) {
uiItemL(sub, NULL, ICON_BLANK1); uiItemL(layout_prop_decorate ? layout_prop_decorate : sub, NULL, ICON_BLANK1);
} }
} }
#endif /* UI_PROP_DECORATE */ #endif /* UI_PROP_DECORATE */
@ -1862,6 +1862,20 @@ static void ui_item_rna_size(uiLayout *layout,
*r_h = h; *r_h = h;
} }
/**
* Hack to add further items in a row into the second part of the split layout, so the label part
* keeps a fixed size.
* \return The layout to place further items in for the split layout.
*/
static uiLayout *ui_item_prop_split_layout_hack(uiLayout *layout_parent, uiLayout *layout_split)
{
if (layout_parent->item.type == ITEM_LAYOUT_ROW) {
layout_parent->child_items_layout = uiLayoutRow(layout_split, true);
return layout_parent->child_items_layout;
}
return layout_split;
}
void uiItemFullR(uiLayout *layout, void uiItemFullR(uiLayout *layout,
PointerRNA *ptr, PointerRNA *ptr,
PropertyRNA *prop, PropertyRNA *prop,
@ -2081,11 +2095,8 @@ void uiItemFullR(uiLayout *layout,
} }
} }
/* Hack to add further items in a row into the second part of if (layout_parent) {
* the split layout, so the label part keeps a fixed size. */ layout_split = ui_item_prop_split_layout_hack(layout_parent, layout_split);
if (layout_parent && layout_parent->item.type == ITEM_LAYOUT_ROW) {
layout_split = uiLayoutRow(layout_split, true);
layout_parent->child_items_layout = layout_split;
} }
/* Watch out! We can only write into the new layout now. */ /* Watch out! We can only write into the new layout now. */
@ -2989,21 +3000,26 @@ void uiItemL(uiLayout *layout, const char *name, int icon)
* extended to support more cases. * extended to support more cases.
* Ideally, #uiItemFullR() could just call this, but it currently has too many special needs. * 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. * \return A layout placed in the row after the split layout. Used to place decorator items.
*/ */
uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon) uiLayout *uiItemL_respect_property_split(uiLayout *layout, const char *text, int icon)
{ {
if (layout->item.flag & UI_ITEM_PROP_SEP) { if (layout->item.flag & UI_ITEM_PROP_SEP) {
uiLayout *layout_split = uiLayoutSplit(layout, UI_ITEM_PROP_SEP_DIVIDE, true); uiBlock *block = uiLayoutGetBlock(layout);
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); uiLayout *layout_sub = uiLayoutColumn(layout_split, true);
layout_split->space = layout_sub->space = layout->space = 0; layout_split->space = layout_sub->space = layout_row->space = 0;
layout_sub->alignment = UI_LAYOUT_ALIGN_RIGHT; layout_sub->alignment = UI_LAYOUT_ALIGN_RIGHT;
uiItemL_(layout_sub, text, icon); uiItemL_(layout_sub, text, icon);
layout_split = ui_item_prop_split_layout_hack(layout, layout_split);
UI_block_layout_set_current(block, layout_split);
/* Give caller a new sub-row to place items in. */ /* Give caller a new sub-row to place items in. */
return uiLayoutRow(layout_split, true); return layout_row;
} }
else { else {
char namestr[UI_MAX_NAME_STR]; char namestr[UI_MAX_NAME_STR];

View File

@ -831,7 +831,7 @@ static void template_ID(bContext *C,
if (text) { if (text) {
/* Add label resepecting the separated layout property split state. */ /* Add label resepecting the separated layout property split state. */
layout = uiItemL_respect_property_split(layout, text, ICON_NONE); uiItemL_respect_property_split(layout, text, ICON_NONE);
} }
if (flag & UI_ID_BROWSE) { if (flag & UI_ID_BROWSE) {