UI: Simplified Categorized Menus

Menus with categories gain a dividing line and omit the title.

Differential Revision: https://developer.blender.org/D5135

Reviewed by Brecht Van Lommel
This commit is contained in:
Harley Acheson 2020-10-19 11:28:38 -07:00
parent 1e3742749e
commit aa244a7a68
Notes: blender-bot 2023-02-14 11:20:29 +01:00
Referenced by issue #80165, separate by loose parts breaks custom normals
2 changed files with 20 additions and 33 deletions

View File

@ -4148,12 +4148,14 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu
UI_block_layout_set_current(block, layout);
int totitems = 0;
int categories = 0;
int nbr_entries_nosepr = 0;
for (const EnumPropertyItem *item = item_array; item->identifier; item++, totitems++) {
if (!item->identifier[0]) {
/* inconsistent, but menus with categories do not look good flipped */
if (item->name) {
block->flag |= UI_BLOCK_NO_FLIP;
categories++;
nbr_entries_nosepr++;
}
/* We do not want simple separators in nbr_entries_nosepr count */
@ -4179,22 +4181,12 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu
rows++;
}
if (block->flag & UI_BLOCK_NO_FLIP) {
const char *title = RNA_property_ui_name(but->rnaprop);
if (title[0] && (categories == 0) && (block->flag & UI_BLOCK_NO_FLIP)) {
/* Title at the top for menus with categories. */
uiDefBut(block,
UI_BTYPE_LABEL,
0,
RNA_property_ui_name(but->rnaprop),
0,
0,
UI_UNIT_X * 5,
UI_UNIT_Y,
NULL,
0.0,
0.0,
0,
0,
"");
uiDefBut(
block, UI_BTYPE_LABEL, 0, title, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
uiItemS(layout);
}
@ -4203,10 +4195,13 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu
/* create items */
uiLayout *split = uiLayoutSplit(layout, 0.0f, false);
bool new_column;
int column_end = 0;
uiLayout *column = NULL;
for (int a = 0; a < totitems; a++) {
if (a == column_end) {
new_column = (a == column_end);
if (new_column) {
/* start new column, and find out where it ends in advance, so we
* can flip the order of items properly per column */
column_end = totitems;
@ -4226,6 +4221,11 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu
const EnumPropertyItem *item = &item_array[a];
if (new_column && (categories > 0) && item->identifier[0]) {
uiItemL(column, "", ICON_NONE);
uiItemS(column);
}
if (!item->identifier[0]) {
if (item->name) {
if (item->icon) {
@ -4249,8 +4249,6 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu
0,
"");
}
}
else {
uiItemS(column);
}
}
@ -4291,23 +4289,11 @@ static void ui_def_but_rna__menu(bContext *UNUSED(C), uiLayout *layout, void *bu
}
}
if (!(block->flag & UI_BLOCK_NO_FLIP)) {
if (title[0] && (categories == 0) && !(block->flag & UI_BLOCK_NO_FLIP)) {
/* Title at the bottom for menus without categories. */
uiItemS(layout);
uiDefBut(block,
UI_BTYPE_LABEL,
0,
RNA_property_ui_name(but->rnaprop),
0,
0,
UI_UNIT_X * 5,
UI_UNIT_Y,
NULL,
0.0,
0.0,
0,
0,
"");
uiDefBut(
block, UI_BTYPE_LABEL, 0, title, 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
}
UI_block_layout_set_current(block, layout);

View File

@ -1542,6 +1542,7 @@ void uiItemsFullEnumO_items(uiLayout *layout,
0,
0,
"");
uiItemS(target);
}
ui_but_tip_from_enum_item(but, item);
}