Tables: Angled headers: fixed multi-line label display when angle is flipped. (#6917)

This commit is contained in:
ocornut 2024-05-02 13:49:26 +02:00
parent b30df8890d
commit 4bb7567141
4 changed files with 18 additions and 2 deletions

View File

@ -66,6 +66,7 @@ Other changes:
cover the label. (#6937) [@dimateos] cover the label. (#6937) [@dimateos]
- ProgressBar: Added support for indeterminate progress bar by passing an animated - ProgressBar: Added support for indeterminate progress bar by passing an animated
negative fraction, e.g. ProgressBar(-1.0f * GetTime()). (#5316, #5370, #1901)[@gan74] 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 - 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) mitigitate issues with reading vertex indexing limits with 16-bit indices. (#7496, #5720)
- Backends: OpenGL: Detect ES3 contexts on desktop based on version string, - Backends: OpenGL: Detect ES3 contexts on desktop based on version string,

View File

@ -2334,6 +2334,20 @@ const char* ImTextFindPreviousUtf8Codepoint(const char* in_text_start, const cha
return in_text_start; 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 IM_MSVC_RUNTIME_CHECKS_RESTORE
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -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 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 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 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 // Helpers: File System
#ifdef IMGUI_DISABLE_FILE_FUNCTIONS #ifdef IMGUI_DISABLE_FILE_FUNCTIONS

View File

@ -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. // - 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 = TableGetColumnName(table, column_n);
const char* label_name_end = FindRenderedTextEnd(label_name); const char* label_name_end = FindRenderedTextEnd(label_name);
const float line_off_step_x = g.FontSize / -sin_a; const float line_off_step_x = (g.FontSize / -sin_a) * (flip_label ? -1.0f : 1.0f);
float line_off_curr_x = 0.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) while (label_name < label_name_end)
{ {
const char* label_name_eol = strchr(label_name, '\n'); const char* label_name_eol = strchr(label_name, '\n');