Internals: added IM_LIKELY(), IM_UNLIKELY() helper macros (yet unused). Added ImFontGetCharAdvanceX() macro.
diff --git a/imgui_draw.cpp b/imgui_draw.cpp
index c0a5b5b..7934949 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -3847,7 +3847,7 @@
return &Glyphs.Data[i];
}
-// Wrapping skips upcoming blanks
+// Trim trailing space and find beginning of next line
static inline const char* CalcWordWrapNextLineStartA(const char* text, const char* text_end)
{
while (text < text_end && ImCharIsBlankA(*text))
@@ -3857,6 +3857,8 @@
return text;
}
+#define ImFontGetCharAdvanceX(_FONT, _CH) ((int)(_CH) < (_FONT)->IndexAdvanceX.Size ? (_FONT)->IndexAdvanceX.Data[_CH] : (_FONT)->FallbackAdvanceX)
+
// Simple word-wrapping for English, not full-featured. Please submit failing cases!
// This will return the next location to wrap from. If no wrapping if necessary, this will fast-forward to e.g. text_end.
// 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.)
@@ -3909,7 +3911,7 @@
}
}
- const float char_width = ((int)c < IndexAdvanceX.Size ? IndexAdvanceX.Data[c] : FallbackAdvanceX);
+ const float char_width = ImFontGetCharAdvanceX(this, c);
if (ImCharIsBlankW(c))
{
if (inside_word)
@@ -4014,7 +4016,7 @@
continue;
}
- const float char_width = ((int)c < IndexAdvanceX.Size ? IndexAdvanceX.Data[c] : FallbackAdvanceX) * scale;
+ const float char_width = ImFontGetCharAdvanceX(this, c);
if (line_width + char_width >= max_width)
{
s = prev_s;
@@ -4063,9 +4065,9 @@
if (y > clip_rect.w)
return;
- const float start_x = x;
const float scale = size / FontSize;
const float line_height = FontSize * scale;
+ const float origin_x = x;
const bool word_wrap_enabled = (wrap_width > 0.0f);
// Fast-forward to first visible line
@@ -4124,11 +4126,11 @@
{
// 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.
if (!word_wrap_eol)
- word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - start_x));
+ word_wrap_eol = CalcWordWrapPositionA(scale, s, text_end, wrap_width - (x - origin_x));
if (s >= word_wrap_eol)
{
- x = start_x;
+ x = origin_x;
y += line_height;
if (y > clip_rect.w)
break; // break out of main loop
@@ -4149,7 +4151,7 @@
{
if (c == '\n')
{
- x = start_x;
+ x = origin_x;
y += line_height;
if (y > clip_rect.w)
break; // break out of main loop
diff --git a/imgui_internal.h b/imgui_internal.h
index 6d84f10..9e6452b 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -260,6 +260,15 @@
#define IM_FLOOR IM_TRUNC
#endif
+// Hint for branch prediction
+#if (defined(__cplusplus) && (__cplusplus >= 202002L)) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L))
+#define IM_LIKELY [[likely]]
+#define IM_UNLIKELY [[unlikely]]
+#else
+#define IM_LIKELY
+#define IM_UNLIKELY
+#endif
+
// Enforce cdecl calling convention for functions called by the standard library, in case compilation settings changed the default to e.g. __vectorcall
#ifdef _MSC_VER
#define IMGUI_CDECL __cdecl