UI: Typographical and Path Wrapping for Tooltips

For tooltips, use typographical line breaking with hard limit for uses
of the regular font, path wrapping with hard limit for uses of the
monospaced font. Small correction to wrapping code so that hard limit
is not taken if there are optional breaking points.

Pull Request: https://projects.blender.org/blender/blender/pulls/136148
This commit is contained in:
Harley Acheson
2025-03-19 00:44:44 +01:00
committed by Harley Acheson
parent c690255184
commit 3f65f700e5
2 changed files with 22 additions and 9 deletions

View File

@@ -1304,17 +1304,18 @@ static void blf_font_wrap_apply(FontBLF *font,
* This is _only_ done when we know for sure the character is ascii (newline or a space).
*/
pen_x_next = pen_x + advance_x;
if (UNLIKELY((int(mode) & int(BLFWrapMode::HardLimit)) && (pen_x_next >= wrap.wrap_width) &&
(advance_x != 0)))
if (UNLIKELY((pen_x_next >= wrap.wrap_width) && (wrap.start != wrap.last[0]))) {
do_draw = true;
}
else if (UNLIKELY((int(mode) & int(BLFWrapMode::HardLimit)) &&
(pen_x_next >= wrap.wrap_width) && (advance_x != 0)))
{
wrap.last[0] = i_curr;
wrap.last[1] = i_curr;
do_draw = true;
clip_bytes = 0;
}
else if (UNLIKELY((pen_x_next >= wrap.wrap_width) && (wrap.start != wrap.last[0]))) {
do_draw = true;
}
else if (UNLIKELY(((i < str_len) && str[i]) == 0)) {
/* Need check here for trailing newline, else we draw it. */
wrap.last[0] = i + ((codepoint != '\n') ? 1 : 0);

View File

@@ -214,8 +214,16 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
color_blend_f3_f3(alert_color, main_color, 0.3f);
/* Draw text. */
BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width);
BLF_wordwrap(blf_mono_font, data->wrap_width);
/* Wrap most text typographically with hard width limit. */
BLF_wordwrap(data->fstyle.uifont_id,
data->wrap_width,
BLFWrapMode(int(BLFWrapMode::Typographical) | int(BLFWrapMode::HardLimit)));
/* Wrap paths with path-specific wrapping with hard width limit. */
BLF_wordwrap(blf_mono_font,
data->wrap_width,
BLFWrapMode(int(BLFWrapMode::Path) | int(BLFWrapMode::HardLimit)));
bbox.xmin += 0.5f * pad_x; /* add padding to the text */
bbox.ymax -= 0.5f * pad_y;
@@ -1300,8 +1308,12 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
font_flag |= BLF_WORD_WRAP;
BLF_enable(data->fstyle.uifont_id, font_flag);
BLF_enable(blf_mono_font, font_flag);
BLF_wordwrap(data->fstyle.uifont_id, data->wrap_width);
BLF_wordwrap(blf_mono_font, data->wrap_width);
BLF_wordwrap(data->fstyle.uifont_id,
data->wrap_width,
BLFWrapMode(int(BLFWrapMode::Typographical) | int(BLFWrapMode::HardLimit)));
BLF_wordwrap(blf_mono_font,
data->wrap_width,
BLFWrapMode(int(BLFWrapMode::Path) | int(BLFWrapMode::HardLimit)));
int i, fonth, fontw;
for (i = 0, fontw = 0, fonth = 0; i < data->fields.size(); i++) {