diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8fc688421..719fc16aa 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -66,6 +66,7 @@ Other changes: cover the label. (#6937) [@dimateos] - ProgressBar: Added support for indeterminate progress bar by passing an animated negative fraction, e.g. ProgressBar(-1.0f * GetTime()). (#5316, #5370, #1901)[@gan74] +- Tables: Angled headers: fixed multi-line label display when angle is flipped. (#6917) - Text, DrawList: Improved handling of long single-line wrapped text. Faster and mitigitate issues with reading vertex indexing limits with 16-bit indices. (#7496, #5720) - Backends: OpenGL: Detect ES3 contexts on desktop based on version string, diff --git a/imgui.cpp b/imgui.cpp index a2a055690..111ab2531 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2334,6 +2334,20 @@ const char* ImTextFindPreviousUtf8Codepoint(const char* in_text_start, const cha return in_text_start; } +int ImTextCountLines(const char* in_text, const char* in_text_end) +{ + if (in_text_end == NULL) + in_text_end = in_text + strlen(in_text); // FIXME-OPT: Not optimal approach, discourage use for now. + int count = 0; + while (in_text < in_text_end) + { + const char* line_end = (const char*)memchr(in_text, '\n', in_text_end - in_text); + in_text = line_end ? line_end + 1 : in_text_end; + count++; + } + return count; +} + IM_MSVC_RUNTIME_CHECKS_RESTORE //----------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index 42ed45c93..36abab3f9 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -407,6 +407,7 @@ IMGUI_API int ImTextCountCharsFromUtf8(const char* in_text, const char IMGUI_API int ImTextCountUtf8BytesFromChar(const char* in_text, const char* in_text_end); // return number of bytes to express one char in UTF-8 IMGUI_API int ImTextCountUtf8BytesFromStr(const ImWchar* in_text, const ImWchar* in_text_end); // return number of bytes to express string in UTF-8 IMGUI_API const char* ImTextFindPreviousUtf8Codepoint(const char* in_text_start, const char* in_text_curr); // return previous UTF-8 code-point. +IMGUI_API int ImTextCountLines(const char* in_text, const char* in_text_end); // return number of lines taken by text. trailing carriage return doesn't count as an extra line. // Helpers: File System #ifdef IMGUI_DISABLE_FILE_FUNCTIONS diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 8312e412c..c3f0797cf 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -3279,8 +3279,8 @@ void ImGui::TableAngledHeadersRowEx(ImGuiID row_id, float angle, float max_label // - Handle multiple lines manually, as we want each lines to follow on the horizontal border, rather than see a whole block rotated. const char* label_name = TableGetColumnName(table, column_n); const char* label_name_end = FindRenderedTextEnd(label_name); - const float line_off_step_x = g.FontSize / -sin_a; - float line_off_curr_x = 0.0f; + const float line_off_step_x = (g.FontSize / -sin_a) * (flip_label ? -1.0f : 1.0f); + float line_off_curr_x = flip_label ? (ImTextCountLines(label_name, label_name_end) - 1) * -line_off_step_x : 0.0f; while (label_name < label_name_end) { const char* label_name_eol = strchr(label_name, '\n');