[Bf-blender-cvs] [3780a402651] master: Fix T93829: Stop header text from jiggling while resizing the region

Campbell Barton noreply at git.blender.org
Thu Dec 8 05:17:55 CET 2022


Commit: 3780a402651aeac0caa86767f823a8517a6f8bae
Author: Campbell Barton
Date:   Thu Dec 8 10:49:55 2022 +1100
Branches: master
https://developer.blender.org/rB3780a402651aeac0caa86767f823a8517a6f8bae

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.

===================================================================

M	source/blender/editors/interface/interface_style.cc

===================================================================

diff --git a/source/blender/editors/interface/interface_style.cc b/source/blender/editors/interface/interface_style.cc
index 5d8914b1f96..95d8638481e 100644
--- a/source/blender/editors/interface/interface_style.cc
+++ b/source/blender/editors/interface/interface_style.cc
@@ -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);
 }



More information about the Bf-blender-cvs mailing list