Skip to content

Commit 407a0b9

Browse files
committed
(Breaking) Fonts: CalcWordWrapPositionA() -> CalcWordWrapPosition(), takes size instead of scale.
This will be needed for upcoming changes.
1 parent 5f0acad commit 407a0b9

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

docs/CHANGELOG.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ Breaking changes:
4343

4444
- TreeNode: renamed ImGuiTreeNodeFlags_NavLeftJumpsBackHere to ImGuiTreeNodeFlags_NavLeftJumpsToParent
4545
for clarity. Kept inline redirection enum (will obsolete). (#1079, #8639)
46+
- Fonts: changed ImFont::CalcWordWrapPositionA() to ImFont::CalcWordWrapPosition():
47+
- old: const char* CalcWordWrapPositionA(float scale, const char* text, ....);
48+
- new: const char* CalcWordWrapPosition (float size, const char* text, ....);
49+
The leading 'float scale' parameters was changed to 'float size'.
50+
This was necessary as 'scale' is assuming standard font size which is a concept we aim to
51+
eliminate in an upcoming update. Kept inline redirection function.
4652
- Commented out PushAllowKeyboardFocus()/PopAllowKeyboardFocus() which was obsoleted
4753
in 1.89.4 (March 2023). (#3092)
4854
- PushAllowKeyboardFocus(bool tab_stop) --> PushItemFlag(ImGuiItemFlags_NoTabStop, !tab_stop);
@@ -51,7 +57,7 @@ Breaking changes:
5157
in 1.89.6 (June 2023).
5258
- ForceDisplayRangeByIndices() --> IncludeItemsByIndex()
5359
- Backends: SDL3: Fixed casing typo in function name: (#8509, #8163, #7998, #7988) [@puugz]
54-
- Imgui_ImplSDLGPU3_PrepareDrawData() -> ImGui_ImplSDLGPU3_PrepareDrawData()
60+
- Imgui_ImplSDLGPU3_PrepareDrawData() --> ImGui_ImplSDLGPU3_PrepareDrawData()
5561
- Internals: RenderTextEllipsis() function removed the 'float clip_max_x' parameter directly
5662
preceding 'float ellipsis_max_x'. Values were identical for a vast majority of users. (#8387)
5763

@@ -109,7 +115,7 @@ Other changes:
109115
- Fonts: reworked text ellipsis logic to ensure a "..." is always displayed instead
110116
of a single character. (#7024)
111117
- Fonts: word-wrapping code handle ideographic comma & full stop (U+3001, U+3002). (#8540)
112-
- Fonts: fixed CalcWordWrapPositionA() fallback when width is too small to wrap:
118+
- Fonts: fixed CalcWordWrapPosition() fallback when width is too small to wrap:
113119
would use a +1 offset instead of advancing to the next UTF-8 codepoint. (#8540)
114120
- Style, InputText: added ImGuiCol_InputTextCursor to configure color of
115121
the InputText cursor/caret. (#7031)

imgui.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,10 @@ CODE
431431
When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
432432
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
433433

434+
- 2025/05/23 (1.92.0) - Fonts: changed ImFont::CalcWordWrapPositionA() to ImFont::CalcWordWrapPosition()
435+
- old: const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, ....);
436+
- new: const char* ImFont::CalcWordWrapPosition (float size, const char* text, ....);
437+
The leading 'float scale' parameters was changed to 'float size'. This was necessary as 'scale' is assuming standard font size which is a concept we aim to eliminate in an upcoming update. Kept inline redirection function.
434438
- 2025/05/15 (1.92.0) - TreeNode: renamed ImGuiTreeNodeFlags_NavLeftJumpsBackHere to ImGuiTreeNodeFlags_NavLeftJumpsToParent for clarity. Kept inline redirection enum (will obsolete).
435439
- 2025/05/15 (1.92.0) - Commented out PushAllowKeyboardFocus()/PopAllowKeyboardFocus() which was obsoleted in 1.89.4. Use PushItemFlag(ImGuiItemFlags_NoTabStop, !tab_stop)/PopItemFlag() instead. (#3092)
436440
- 2025/05/15 (1.92.0) - Commented out ImGuiListClipper::ForceDisplayRangeByIndices() which was obsoleted in 1.89.6. Use ImGuiListClipper::IncludeItemsByIndex() instead.

imgui.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Library Version
3030
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
3131
#define IMGUI_VERSION "1.92.0 WIP"
32-
#define IMGUI_VERSION_NUM 19196
32+
#define IMGUI_VERSION_NUM 19197
3333
#define IMGUI_HAS_TABLE
3434

3535
/*
@@ -3533,10 +3533,14 @@ struct ImFont
35333533
// 'max_width' stops rendering after a certain width (could be turned into a 2d size). FLT_MAX to disable.
35343534
// 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
35353535
IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL); // utf8
3536-
IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width);
3536+
IMGUI_API const char* CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width);
35373537
IMGUI_API void RenderChar(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, ImWchar c, const ImVec4* cpu_fine_clip = NULL);
35383538
IMGUI_API void RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false);
35393539

3540+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
3541+
inline const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) { return CalcWordWrapPosition(FontSize * scale, text, text_end, wrap_width); }
3542+
#endif
3543+
35403544
// [Internal] Don't use!
35413545
IMGUI_API void BuildLookupTable();
35423546
IMGUI_API void ClearOutputData();

imgui_draw.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,7 @@ static inline const char* CalcWordWrapNextLineStartA(const char* text, const cha
39363936
// Simple word-wrapping for English, not full-featured. Please submit failing cases!
39373937
// This will return the next location to wrap from. If no wrapping if necessary, this will fast-forward to e.g. text_end.
39383938
// FIXME: Much possible improvements (don't cut things like "word !", "word!!!" but cut within "word,,,,", more sensible support for punctuations, support for Unicode punctuations, etc.)
3939-
const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width)
3939+
const char* ImFont::CalcWordWrapPosition(float size, const char* text, const char* text_end, float wrap_width)
39403940
{
39413941
// For references, possible wrap point marked with ^
39423942
// "aaa bbb, ccc,ddd. eee fff. ggg!"
@@ -3952,6 +3952,7 @@ const char* ImFont::CalcWordWrapPositionA(float scale, const char* text, const c
39523952
float line_width = 0.0f;
39533953
float word_width = 0.0f;
39543954
float blank_width = 0.0f;
3955+
const float scale = size / FontSize;
39553956
wrap_width /= scale; // We work with unscaled widths to avoid scaling every characters
39563957

39573958
const char* word_end = text;
@@ -4055,7 +4056,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
40554056
{
40564057
// Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
40574058
if (!word_wrap_eol)
4058-
word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - line_width);
4059+
word_wrap_eol = CalcWordWrapPosition(size, s, text_end, wrap_width - line_width);
40594060

40604061
if (s >= word_wrap_eol)
40614062
{
@@ -4175,10 +4176,10 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im
41754176
const char* line_end = (const char*)ImMemchr(s, '\n', text_end - s);
41764177
if (word_wrap_enabled)
41774178
{
4178-
// FIXME-OPT: This is not optimal as do first do a search for \n before calling CalcWordWrapPositionA().
4179-
// If the specs for CalcWordWrapPositionA() were reworked to optionally return on \n we could combine both.
4179+
// FIXME-OPT: This is not optimal as do first do a search for \n before calling CalcWordWrapPosition().
4180+
// If the specs for CalcWordWrapPosition() were reworked to optionally return on \n we could combine both.
41804181
// However it is still better than nothing performing the fast-forward!
4181-
s = CalcWordWrapPositionA(scale, s, line_end ? line_end : text_end, wrap_width);
4182+
s = CalcWordWrapPosition(size, s, line_end ? line_end : text_end, wrap_width);
41824183
s = CalcWordWrapNextLineStartA(s, text_end);
41834184
}
41844185
else
@@ -4223,7 +4224,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im
42234224
{
42244225
// Calculate how far we can render. Requires two passes on the string data but keeps the code simple and not intrusive for what's essentially an uncommon feature.
42254226
if (!word_wrap_eol)
4226-
word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - origin_x));
4227+
word_wrap_eol = CalcWordWrapPosition(size, s, text_end, wrap_width - (x - origin_x));
42274228

42284229
if (s >= word_wrap_eol)
42294230
{

0 commit comments

Comments
 (0)