Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface.cc
| Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
| using blender::Vector; | using blender::Vector; | ||||
| /* prototypes. */ | /* prototypes. */ | ||||
| static void ui_but_to_pixelrect(struct rcti *rect, | static void ui_but_to_pixelrect(struct rcti *rect, | ||||
| const struct ARegion *region, | const struct ARegion *region, | ||||
| struct uiBlock *block, | struct uiBlock *block, | ||||
| const struct uiBut *but); | const struct uiBut *but); | ||||
| static void ui_def_but_rna__menu(bContext * /*C*/, uiLayout *layout, void *but_p); | static void ui_def_but_rna__menu(bContext *C, uiLayout *layout, void *but_p); | ||||
| static void ui_def_but_rna__panel_type(bContext * /*C*/, uiLayout *layout, void *but_p); | static void ui_def_but_rna__panel_type(bContext * /*C*/, uiLayout *layout, void *but_p); | ||||
| static void ui_def_but_rna__menu_type(bContext * /*C*/, uiLayout *layout, void *but_p); | static void ui_def_but_rna__menu_type(bContext * /*C*/, uiLayout *layout, void *but_p); | ||||
| /* avoid unneeded calls to ui_but_value_get */ | /* avoid unneeded calls to ui_but_value_get */ | ||||
| #define UI_BUT_VALUE_UNSET DBL_MAX | #define UI_BUT_VALUE_UNSET DBL_MAX | ||||
| #define UI_GET_BUT_VALUE_INIT(_but, _value) \ | #define UI_GET_BUT_VALUE_INIT(_but, _value) \ | ||||
| if (_value == DBL_MAX) { \ | if (_value == DBL_MAX) { \ | ||||
| (_value) = ui_but_value_get(_but); \ | (_value) = ui_but_value_get(_but); \ | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| void ui_def_but_icon_clear(uiBut *but) | void ui_def_but_icon_clear(uiBut *but) | ||||
| { | { | ||||
| but->icon = ICON_NONE; | but->icon = ICON_NONE; | ||||
| but->flag &= ~UI_HAS_ICON; | but->flag &= ~UI_HAS_ICON; | ||||
| but->drawflag &= ~UI_BUT_ICON_LEFT; | but->drawflag &= ~UI_BUT_ICON_LEFT; | ||||
| } | } | ||||
| static void ui_def_but_rna__menu(bContext * /*C*/, uiLayout *layout, void *but_p) | static void ui_def_but_rna__menu(bContext *C, uiLayout *layout, void *but_p) | ||||
| { | { | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| uiPopupBlockHandle *handle = block->handle; | uiPopupBlockHandle *handle = block->handle; | ||||
| uiBut *but = (uiBut *)but_p; | uiBut *but = (uiBut *)but_p; | ||||
| /* see comment in ui_item_enum_expand, re: `uiname`. */ | /* see comment in ui_item_enum_expand, re: `uiname`. */ | ||||
| const EnumPropertyItem *item_array; | const EnumPropertyItem *item_array; | ||||
| UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT); | UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT); | ||||
| bool free; | bool free; | ||||
| RNA_property_enum_items_gettexted(static_cast<bContext *>(block->evil_C), | RNA_property_enum_items_gettexted(static_cast<bContext *>(block->evil_C), | ||||
| &but->rnapoin, | &but->rnapoin, | ||||
| but->rnaprop, | but->rnaprop, | ||||
| &item_array, | &item_array, | ||||
| nullptr, | nullptr, | ||||
| &free); | &free); | ||||
| /* We don't want nested rows, cols in menus. */ | /* We don't want nested rows, cols in menus. */ | ||||
| UI_block_layout_set_current(block, layout); | UI_block_layout_set_current(block, layout); | ||||
| int totitems = 0; | int totitems = 0; | ||||
| int categories = 0; | int categories = 0; | ||||
| int entries_nosepr_count = 0; | int columns = 1; | ||||
| for (const EnumPropertyItem *item = item_array; item->identifier; item++, totitems++) { | int rows = 0; | ||||
| if (!item->identifier[0]) { | |||||
| /* inconsistent, but menus with categories do not look good flipped */ | |||||
| if (item->name) { | |||||
| block->flag |= UI_BLOCK_NO_FLIP; | |||||
| categories++; | |||||
| entries_nosepr_count++; | |||||
| } | |||||
| /* We do not want simple separators in `entries_nosepr_count`. */ | |||||
| continue; | |||||
| } | |||||
| entries_nosepr_count++; | |||||
| } | |||||
| /* Columns and row estimation. Ignore simple separators here. */ | const wmWindow *win = CTX_wm_window(C); | ||||
| int columns = (entries_nosepr_count + 20) / 20; | const int row_height = UI_UNIT_Y / but->block->aspect; | ||||
| if (columns < 1) { | /* Calculate max-rows from how many rows can fit in this window.*/ | ||||
| columns = 1; | const int max_rows = (win->sizey - (4.0f * row_height)) / row_height; | ||||
| } | float text_width = 0.0f; | ||||
| if (columns > 8) { | |||||
| columns = (entries_nosepr_count + 25) / 25; | |||||
| } | |||||
| int rows = totitems / columns; | BLF_size(BLF_default(), UI_style_get()->widgetlabel.points * U.pixelsize); | ||||
| if (rows < 1) { | int col_rows = 0; | ||||
| rows = 1; | float col_width = 0.0f; | ||||
| } | |||||
| while (rows * columns < totitems) { | for (const EnumPropertyItem *item = item_array; item->identifier; item++, totitems++) { | ||||
| rows++; | col_rows++; | ||||
| if (col_rows > 1 && (col_rows > max_rows || (!item->identifier[0] && item->name))) { | |||||
| columns++; | |||||
| text_width += col_width; | |||||
| col_width = 0; | |||||
| col_rows = 0; | |||||
| } | |||||
| if (!item->identifier[0] && item->name) { | |||||
| /* Inconsistent, but menus with categories do not look good flipped. */ | |||||
| block->flag |= UI_BLOCK_NO_FLIP; | |||||
| categories++; | |||||
| } | |||||
| float item_width = BLF_width(BLF_default(), item->name, BLF_DRAW_STR_DUMMY_MAX); | |||||
| col_width = MAX2(col_width, item_width + (6 * UI_UNIT_X)); | |||||
| rows = MAX2(rows, col_rows); | |||||
| } | |||||
| text_width += col_width; | |||||
| text_width /= but->block->aspect; | |||||
| if (columns > 1 && text_width > win->sizex) { | |||||
| columns = 1; | |||||
| rows = totitems; | |||||
| } | } | ||||
| const char *title = RNA_property_ui_name(but->rnaprop); | const char *title = RNA_property_ui_name(but->rnaprop); | ||||
| if (title[0] && (categories == 0) && (block->flag & UI_BLOCK_NO_FLIP)) { | if (title[0] && (categories == 0) && (block->flag & UI_BLOCK_NO_FLIP)) { | ||||
| /* Title at the top for menus with categories. */ | /* Title at the top for menus with categories. */ | ||||
| uiDefBut(block, | uiDefBut(block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| Show All 27 Lines | |||||
| /* start new column, and find out where it ends in advance, so we | /* start new column, and find out where it ends in advance, so we | ||||
| * can flip the order of items properly per column */ | * can flip the order of items properly per column */ | ||||
| column_end = totitems; | column_end = totitems; | ||||
| for (int b = a + 1; b < totitems; b++) { | for (int b = a + 1; b < totitems; b++) { | ||||
| const EnumPropertyItem *item = &item_array[b]; | const EnumPropertyItem *item = &item_array[b]; | ||||
| /* new column on N rows or on separation label */ | /* new column on N rows or on separation label */ | ||||
| if (((b - a) % rows == 0) || (!item->identifier[0] && item->name)) { | if (((b - a) % rows == 0) || (columns > 1 && !item->identifier[0] && item->name)) { | ||||
| column_end = b; | column_end = b; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| column = uiLayoutColumn(split, false); | column = uiLayoutColumn(split, false); | ||||
| } | } | ||||
| const EnumPropertyItem *item = &item_array[a]; | const EnumPropertyItem *item = &item_array[a]; | ||||
| if (new_column && (categories > 0) && item->identifier[0]) { | if (new_column && (categories > 0) && (columns > 1) && item->identifier[0]) { | ||||
| uiItemL(column, "", ICON_NONE); | uiItemL(column, "", ICON_NONE); | ||||
| uiItemS(column); | uiItemS(column); | ||||
| } | } | ||||
| if (!item->identifier[0]) { | if (!item->identifier[0]) { | ||||
| if (item->name) { | if (item->name || columns > 1) { | ||||
| if (item->icon) { | if (item->icon) { | ||||
| uiItemL(column, item->name, item->icon); | uiItemL(column, item->name, item->icon); | ||||
| } | } | ||||
| else { | else { | ||||
| /* Do not use uiItemL here, as our root layout is a menu one, | /* Do not use uiItemL here, as our root layout is a menu one, | ||||
| * it will add a fake blank icon! */ | * it will add a fake blank icon! */ | ||||
| uiDefBut(block, | uiDefBut(block, | ||||
| UI_BTYPE_LABEL, | UI_BTYPE_LABEL, | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||