Fix T93829: Stop header text from jiggling while resizing the region

Since moving to float scaling, the method of accessing the text
width with the aspect applied wasn't working properly.

Based on contributions by @lone_noel & @harley, see D15043.
This commit is contained in:
Campbell Barton 2022-12-08 10:49:55 +11:00
parent a132b068bc
commit 3780a40265
Notes: blender-bot 2023-02-14 11:01:33 +01:00
Referenced by issue #93829, Regression: Text jumping in the headers while scaling editors
1 changed files with 13 additions and 17 deletions

View File

@ -36,6 +36,8 @@
# include "BLI_math_base.h" /* M_PI */
#endif
static void fontstyle_set_ex(const uiFontStyle *fs, const float dpi_fac);
/* style + theme + layout-engine = UI */
/**
@ -347,21 +349,10 @@ int UI_fontstyle_string_width_with_block_aspect(const uiFontStyle *fs,
const char *str,
const float aspect)
{
uiFontStyle fs_buf;
if (aspect != 1.0f) {
fs_buf = *fs;
ui_fontscale(&fs_buf.points, aspect);
fs = &fs_buf;
}
int width = UI_fontstyle_string_width(fs, str);
if (aspect != 1.0f) {
/* While in most cases rounding up isn't important, it can make a difference
* with small fonts (3px or less), zooming out in the node-editor for e.g. */
width = int(ceilf(width * aspect));
}
return width;
/* FIXME(@campbellbarton): the final scale of the font is rounded which should be accounted for.
* Failing to do so causes bad alignment when zoomed out very far in the node-editor. */
fontstyle_set_ex(fs, U.dpi_fac / aspect);
return int(BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX) * aspect);
}
int UI_fontstyle_height_max(const uiFontStyle *fs)
@ -492,9 +483,14 @@ void uiStyleInit(void)
BLF_load_font_stack();
}
void UI_fontstyle_set(const uiFontStyle *fs)
static void fontstyle_set_ex(const uiFontStyle *fs, const float dpi_fac)
{
uiFont *font = uifont_to_blfont(fs->uifont_id);
BLF_size(font->blf_id, fs->points * U.dpi_fac);
BLF_size(font->blf_id, fs->points * dpi_fac);
}
void UI_fontstyle_set(const uiFontStyle *fs)
{
fontstyle_set_ex(fs, U.dpi_fac);
}