[Bf-blender-cvs] [8e972bf72b5] soc-2020-outliner: UI: Fix drawing of aligned buttons in menu rows
Nathan Craddock
noreply at git.blender.org
Sat Jul 18 02:56:43 CEST 2020
Commit: 8e972bf72b59ecf695c82c2596aa3083ecfadc82
Author: Nathan Craddock
Date: Thu Jul 16 11:14:33 2020 -0600
Branches: soc-2020-outliner
https://developer.blender.org/rB8e972bf72b59ecf695c82c2596aa3083ecfadc82
UI: Fix drawing of aligned buttons in menu rows
This adds support for drawing icon buttons as a row in a popup menu. This is needed for drawing collection color tag icons in a row in the outliner context menu.
A few issues still exist, but I would like some initial review now that it mostly works.
* The icons do not draw aligned with the text labels. This is easy to fix, but the hover highlight is still drawn incorrectly.
* This works well when creating row icon buttons with an operator_enum, but manually creating the row elements doesn't draw an initial offset blank icon.
Differential Revision: https://developer.blender.org/D8317
===================================================================
M source/blender/editors/animation/keyframing.c
M source/blender/editors/animation/keyingsets.c
M source/blender/editors/curve/editcurve.c
M source/blender/editors/gpencil/gpencil_data.c
M source/blender/editors/include/UI_interface.h
M source/blender/editors/interface/interface.c
M source/blender/editors/interface/interface_layout.c
M source/blender/editors/interface/interface_region_menu_pie.c
M source/blender/editors/interface/interface_widgets.c
M source/blender/editors/space_info/info_ops.c
M source/blender/editors/space_outliner/outliner_tools.c
M source/blender/editors/transform/transform_ops.c
M source/blender/makesrna/intern/rna_ui_api.c
===================================================================
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 9cb41e06aa0..1b7ae92cf4f 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -1953,7 +1953,7 @@ static int insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UN
/* call the menu, which will call this operator again, hence the canceled */
pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
layout = UI_popup_menu_layout(pup);
- uiItemsEnumO(layout, "ANIM_OT_keyframe_insert_menu", "type");
+ uiItemsEnumO(layout, "ANIM_OT_keyframe_insert_menu", "type", false);
UI_popup_menu_end(C, pup);
return OPERATOR_INTERFACE;
diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c
index 5e4b39d9d81..3028263a3d4 100644
--- a/source/blender/editors/animation/keyingsets.c
+++ b/source/blender/editors/animation/keyingsets.c
@@ -479,7 +479,7 @@ static int keyingset_active_menu_invoke(bContext *C, wmOperator *op, const wmEve
/* call the menu, which will call this operator again, hence the canceled */
pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE);
layout = UI_popup_menu_layout(pup);
- uiItemsEnumO(layout, "ANIM_OT_keying_set_active_set", "type");
+ uiItemsEnumO(layout, "ANIM_OT_keying_set_active_set", "type", false);
UI_popup_menu_end(C, pup);
return OPERATOR_INTERFACE;
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index 3e428eaffc2..ad3b15ed575 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -5919,7 +5919,7 @@ static int toggle_cyclic_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
if (nu->type == CU_NURBS) {
pup = UI_popup_menu_begin(C, IFACE_("Direction"), ICON_NONE);
layout = UI_popup_menu_layout(pup);
- uiItemsEnumO(layout, op->type->idname, "direction");
+ uiItemsEnumO(layout, op->type->idname, "direction", false);
UI_popup_menu_end(C, pup);
return OPERATOR_INTERFACE;
}
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 96b0296a7de..3331dbcbe8b 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1255,7 +1255,7 @@ static int gpencil_layer_change_invoke(bContext *C, wmOperator *op, const wmEven
/* call the menu, which will call this operator again, hence the canceled */
pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE);
layout = UI_popup_menu_layout(pup);
- uiItemsEnumO(layout, "GPENCIL_OT_layer_change", "layer");
+ uiItemsEnumO(layout, "GPENCIL_OT_layer_change", "layer", false);
UI_popup_menu_end(C, pup);
return OPERATOR_INTERFACE;
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 7ce74a87ea0..19890e4ec4f 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -2205,7 +2205,10 @@ void uiItemEnumO_string(uiLayout *layout,
const char *opname,
const char *propname,
const char *value);
-void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname);
+void uiItemsEnumO(uiLayout *layout,
+ const char *opname,
+ const char *propname,
+ const bool icon_only);
void uiItemBooleanO(uiLayout *layout,
const char *name,
int icon,
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 28b86674fdd..85317f9693e 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -380,13 +380,27 @@ static void ui_block_bounds_calc_text(uiBlock *block, float offset)
}
}
+ /* Keep aligned buttons in the same column. */
+ if (bt->alignnr && bt->next) {
+ int width = 0;
+ for (col_bt = bt; col_bt->rect.xmin < col_bt->next->rect.xmin; col_bt = col_bt->next) {
+ width += BLI_rctf_size_x(&col_bt->rect);
+ }
+ if (width > i) {
+ i = width;
+ }
+ bt = col_bt;
+ }
+
if (bt->next && bt->rect.xmin < bt->next->rect.xmin) {
/* End of this column, and it's not the last one. */
for (col_bt = init_col_bt; col_bt->prev != bt; col_bt = col_bt->next) {
- col_bt->rect.xmin = x1addval;
- col_bt->rect.xmax = x1addval + i + block->bounds;
+ if (!col_bt->alignnr) {
+ col_bt->rect.xmin = x1addval;
+ col_bt->rect.xmax = x1addval + i + block->bounds;
- ui_but_update(col_bt); /* clips text again */
+ ui_but_update(col_bt); /* clips text again */
+ }
}
/* And we prepare next column. */
@@ -398,8 +412,10 @@ static void ui_block_bounds_calc_text(uiBlock *block, float offset)
/* Last column. */
for (col_bt = init_col_bt; col_bt; col_bt = col_bt->next) {
- col_bt->rect.xmin = x1addval;
- col_bt->rect.xmax = max_ff(x1addval + i + block->bounds, offset + block->minbounds);
+ if (!col_bt->alignnr) {
+ col_bt->rect.xmin = x1addval;
+ col_bt->rect.xmax = max_ff(x1addval + i + block->bounds, offset + block->minbounds);
+ }
ui_but_update(col_bt); /* clips text again */
}
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index f027a62cbfd..64e265c1f5d 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -1206,6 +1206,10 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout,
but->flag |= UI_SELECT_DRAW;
}
+ if (flag & UI_ITEM_R_ICON_ONLY) {
+ UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT);
+ }
+
if (layout->redalert) {
UI_but_flag_enable(but, UI_BUT_REDALERT);
}
@@ -1426,6 +1430,13 @@ void uiItemsFullEnumO_items(uiLayout *layout,
if (radial) {
target = uiLayoutRadial(layout);
}
+ else if (layout->item.type == ITEM_LAYOUT_ROW && flag & UI_ITEM_R_ICON_ONLY) {
+ target = layout;
+
+ /* Add a blank button to the beginning of the row. */
+ uiDefIconBut(
+ block, UI_BTYPE_LABEL, 0, ICON_BLANK1, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+ }
else {
split = uiLayoutSplit(layout, 0.0f, false);
target = uiLayoutColumn(split, layout->align);
@@ -1473,7 +1484,14 @@ void uiItemsFullEnumO_items(uiLayout *layout,
}
RNA_property_enum_set(&tptr, prop, item->value);
- uiItemFullO_ptr(target, ot, item->name, item->icon, tptr.data, context, flag, NULL);
+ uiItemFullO_ptr(target,
+ ot,
+ (flag & UI_ITEM_R_ICON_ONLY) ? NULL : item->name,
+ item->icon,
+ tptr.data,
+ context,
+ flag,
+ NULL);
ui_but_tip_from_enum_item(block->buttons.last, item);
}
@@ -1597,9 +1615,14 @@ void uiItemsFullEnumO(uiLayout *layout,
}
}
-void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname)
+void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname, const bool icon_only)
{
- uiItemsFullEnumO(layout, opname, propname, NULL, layout->root->opcontext, 0);
+ uiItemsFullEnumO(layout,
+ opname,
+ propname,
+ NULL,
+ layout->root->opcontext,
+ icon_only ? UI_ITEM_R_ICON_ONLY : 0);
}
/* for use in cases where we have */
@@ -3363,7 +3386,7 @@ static void menu_item_enum_opname_menu(bContext *UNUSED(C), uiLayout *layout, vo
MenuItemLevel *lvl = (MenuItemLevel *)(((uiBut *)arg)->func_argN);
uiLayoutSetOperatorContext(layout, lvl->opcontext);
- uiItemsEnumO(layout, lvl->opname, lvl->propname);
+ uiItemsEnumO(layout, lvl->opname, lvl->propname, false);
layout->root->block->flag |= UI_BLOCK_IS_FLIP;
@@ -3711,19 +3734,19 @@ static void ui_litem_estimate_column(uiLayout *litem, bool is_box)
}
}
-static void ui_litem_layout_column(uiLayout *litem, bool is_box)
+static void ui_litem_layout_column(uiLayout *litem, bool is_box, bool is_menu)
{
uiItem *item;
- int itemh, x, y;
+ int itemw, itemh, x, y;
x = litem->x;
y = litem->y;
for (item = litem->items.first; item; item = item->next) {
- ui_item_size(item, NULL, &itemh);
+ ui_item_size(item, &itemw, &itemh);
y -= itemh;
- ui_item_position(item, x, y, litem->w, itemh);
+ ui_item_position(item, x, y, is_menu ? itemw : litem->w, itemh);
if (item->next && (!is_box || item != litem->items.first)) {
y -= litem->space;
@@ -3885,8 +3908,11 @@ static void ui_litem_layout_root(uiLayout *litem)
else if (litem->root->type == UI_LAYOUT_PIEMENU) {
ui_litem_layout_root_radial(litem);
}
+ else if (litem->root->type == UI_LAYOUT_MENU) {
+ ui_litem_layout_column(litem, false, true);
+ }
else {
- ui_litem_layout_column(litem, false);
+ ui_litem_layout_column(litem, false, false);
}
}
@@ -3930,7 +3956,7 @@ static void ui_litem_layout_box(uiLayout *litem)
litem->h -= 2 * boxspace;
}
- ui_litem_layout_column(litem, true);
+ ui_litem_layout_column(litem, true, false);
litem->x -= boxspace;
litem->y -= boxspace;
@@ -5213,7 +5239,7 @@ static void ui_item_layout(uiItem *item)
switch (litem->item.type) {
case ITEM_LAYOUT_COLUMN:
- ui_litem_layout_column(litem, false);
+ ui_litem_layout_column(litem, false, false);
break;
case ITEM_LAYOUT_COLUMN_FLOW:
ui_litem_layout_column_flow(litem);
diff --git a/source/blender/editors/interface/interface_region_menu_pie.c b/source/blender/editors/interface/interface_region_menu_pie.c
index 1371c7524ae..5afef38ae0d 100644
--- a/source/blender/editors/interface/interface_region_menu_pie.c
+++ b/source/blender/editors/interface/interface_region_menu_pi
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list