Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2021-01-26 00:54:00 +0300
committerJulian Eisel <julian@blender.org>2021-01-26 01:10:16 +0300
commit77f73a92843965906189dd56dcc4d18eae2371cc (patch)
tree8ff43da506a34768f01380c5e5d8624dc37b3696 /source/blender/editors/interface/interface_widgets.c
parent14f61c619b0bd28386673672881a234e7e1ded11 (diff)
Fix library name clipping most of the data-block name in data-block menus
Issue is visible here https://developer.blender.org/F8626313. If there is enough space for both the item name and the library hint, display both. Otherwise, clip either the item name, the library hint, or both so that not more than 60% and 40% of the available width are used repectively. There are further improvements we could do, as noted in T84188, this just fixes the regression for the release. Part of T84188. There were multiple reports about this, see merged in and mentioned reports in T84188 and T78012.
Diffstat (limited to 'source/blender/editors/interface/interface_widgets.c')
-rw-r--r--source/blender/editors/interface/interface_widgets.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index a99f05730bb..c0c34b0a93d 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -5221,11 +5221,13 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
const char *name,
int iconid,
int state,
- bool use_sep,
+ uiMenuItemSeparatorType separator_type,
int *r_xmax)
{
uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM);
const rcti _rect = *rect;
+ int max_hint_width = INT_MAX;
+ int padding = 0.25f * UI_UNIT_X;
char *cpoin = NULL;
wt->state(wt, state, 0, UI_EMBOSS_UNDEFINED);
@@ -5234,13 +5236,13 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
UI_fontstyle_set(fstyle);
/* text location offset */
- rect->xmin += 0.25f * UI_UNIT_X;
+ rect->xmin += padding;
if (iconid) {
rect->xmin += UI_DPI_ICON_SIZE;
}
/* cut string in 2 parts? */
- if (use_sep) {
+ if (separator_type != UI_MENU_ITEM_SEPARATOR_NONE) {
cpoin = strrchr(name, UI_SEP_CHAR);
if (cpoin) {
*cpoin = 0;
@@ -5253,7 +5255,30 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
}
- rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + UI_DPI_ICON_SIZE;
+ if (separator_type == UI_MENU_ITEM_SEPARATOR_SHORTCUT) {
+ /* Shrink rect to exclude the shortcut string. */
+ rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + UI_DPI_ICON_SIZE;
+ }
+ else if (separator_type == UI_MENU_ITEM_SEPARATOR_HINT) {
+ /* Deterimine max-width for the hint string to leave the name string un-clipped (if there's
+ * enough space to display it). */
+
+ const int available_width = BLI_rcti_size_x(rect) - padding;
+ const int name_width = BLF_width(fstyle->uifont_id, name, INT_MAX);
+ const int hint_width = BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + padding;
+
+ if ((name_width + hint_width) > available_width) {
+ /* Clipping width for hint string. */
+ max_hint_width = available_width * 0.40f;
+ /* Clipping xmax for clipping of item name. */
+ rect->xmax = (hint_width < max_hint_width) ?
+ (rect->xmax - hint_width) :
+ (rect->xmin + (available_width - max_hint_width));
+ }
+ }
+ else {
+ BLI_assert(!"Unknwon menu item separator type");
+ }
if (fstyle->kerning == 1) {
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
@@ -5308,15 +5333,26 @@ void ui_draw_menu_item(const uiFontStyle *fstyle,
}
/* part text right aligned */
- if (use_sep) {
+ if (separator_type != UI_MENU_ITEM_SEPARATOR_NONE) {
if (cpoin) {
/* Set inactive state for grayed out text. */
wt->state(wt, state | UI_BUT_INACTIVE, 0, UI_EMBOSS_UNDEFINED);
+ char hint_drawstr[UI_MAX_DRAW_STR];
+ {
+ const size_t max_len = sizeof(hint_drawstr);
+ const float minwidth = (float)(UI_DPI_ICON_SIZE);
+
+ BLI_strncpy(hint_drawstr, cpoin + 1, sizeof(hint_drawstr));
+ if (hint_drawstr[0] && (max_hint_width < INT_MAX)) {
+ UI_text_clip_middle_ex(fstyle, hint_drawstr, max_hint_width, minwidth, max_len, '\0');
+ }
+ }
+
rect->xmax = _rect.xmax - 5;
UI_fontstyle_draw(fstyle,
rect,
- cpoin + 1,
+ hint_drawstr,
wt->wcol.text,
&(struct uiFontStyleDraw_Params){
.align = UI_STYLE_TEXT_RIGHT,