mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-30 20:51:06 +01:00 
			
		
		
		
	Log/Capture: Fixed BeginTabItem() label not being included in a text log/capture.
Extracted tab rendering code into a RenderTextEllipsis() function.
This commit is contained in:
		| @@ -83,6 +83,7 @@ Other Changes: | |||||||
| - Style: Added style.WindowMenuButtonPosition (left/right, defaults to ImGuiDir_Left) to move the | - Style: Added style.WindowMenuButtonPosition (left/right, defaults to ImGuiDir_Left) to move the | ||||||
|   collapsing/docking button to the other side of the title bar. |   collapsing/docking button to the other side of the title bar. | ||||||
| - Style: Made window close button cross slightly smaller. | - Style: Made window close button cross slightly smaller. | ||||||
|  | - Log/Capture: Fixed BeginTabItem() label not being included in a text log/capture. | ||||||
| - ImDrawList: Added ImDrawCmd::VtxOffset value to support large meshes (64k+ vertices) using 16-bits indices. | - ImDrawList: Added ImDrawCmd::VtxOffset value to support large meshes (64k+ vertices) using 16-bits indices. | ||||||
|   The renderer back-end needs to set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' to enable |   The renderer back-end needs to set 'io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset' to enable | ||||||
|   this, and honor the ImDrawCmd::VtxOffset field. Otherwise the value will always be zero. |   this, and honor the ImDrawCmd::VtxOffset field. Otherwise the value will always be zero. | ||||||
|   | |||||||
							
								
								
									
										45
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								imgui.cpp
									
									
									
									
									
								
							| @@ -2422,6 +2422,51 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons | |||||||
|         LogRenderedText(&pos_min, text, text_display_end); |         LogRenderedText(&pos_min, text, text_display_end); | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // Another overly complex function until we reorganize everything into a nice all-in-one helper. | ||||||
|  | // This is made more complex because we have dissociated the layout rectangle (pos_min..pos_max) which define where the ellipsis is, from actual clipping and limit of the ellipsis display. | ||||||
|  | // This is because in the context of tabs we selectively hide part of the text when the Close Button appears, but we don't want the ellipsis to move.  | ||||||
|  | void    ImGui::RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end_full, const ImVec2* text_size_if_known) | ||||||
|  | { | ||||||
|  |     ImGuiContext& g = *GImGui; | ||||||
|  |     if (text_end_full == NULL) | ||||||
|  |         text_end_full = FindRenderedTextEnd(text); | ||||||
|  |     const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_end_full, false, 0.0f); | ||||||
|  |  | ||||||
|  |     if (text_size.x > pos_max.x - pos_min.x) | ||||||
|  |     { | ||||||
|  |  | ||||||
|  |         const ImFont* font = draw_list->_Data->Font; | ||||||
|  |         const float font_size = draw_list->_Data->FontSize; | ||||||
|  |         const int ellipsis_dot_count = 3; | ||||||
|  |         const float ellipsis_width = (1.0f + 1.0f) * ellipsis_dot_count - 1.0f; | ||||||
|  |         const char* text_end_ellipsis = NULL; | ||||||
|  |         float text_size_clipped_x = font->CalcTextSizeA(font_size, (pos_max.x - pos_min.x) - ellipsis_width + 1.0f, 0.0f, text, text_end_full, &text_end_ellipsis).x; | ||||||
|  |         if (text == text_end_ellipsis && text_end_ellipsis < text_end_full)    // Always display at least 1 character if there's no room for character + ellipsis | ||||||
|  |         { | ||||||
|  |             text_end_ellipsis = text + ImTextCountUtf8BytesFromChar(text, text_end_full); | ||||||
|  |             text_size_clipped_x = font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text, text_end_ellipsis).x; | ||||||
|  |         } | ||||||
|  |         while (text_end_ellipsis > text && ImCharIsBlankA(text_end_ellipsis[-1])) // Trim trailing space | ||||||
|  |         { | ||||||
|  |             text_end_ellipsis--; | ||||||
|  |             text_size_clipped_x -= font->CalcTextSizeA(font_size, FLT_MAX, 0.0f, text_end_ellipsis, text_end_ellipsis + 1).x; // Ascii blanks are always 1 byte | ||||||
|  |         } | ||||||
|  |         RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_ellipsis, &text_size, ImVec2(0.0f, 0.0f)); | ||||||
|  |  | ||||||
|  |         const float ellipsis_x = pos_min.x + text_size_clipped_x + 1.0f; | ||||||
|  |         if (ellipsis_x + ellipsis_width <= ellipsis_max_x) | ||||||
|  |             RenderPixelEllipsis(draw_list, ImVec2(ellipsis_x, pos_min.y), GetColorU32(ImGuiCol_Text), ellipsis_dot_count); | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |     { | ||||||
|  |         RenderTextClippedEx(draw_list, pos_min, ImVec2(clip_max_x, pos_max.y), text, text_end_full, &text_size, ImVec2(0.0f, 0.0f)); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if (g.LogEnabled) | ||||||
|  |         LogRenderedText(&pos_min, text, text_end_full); | ||||||
|  | } | ||||||
|  |  | ||||||
| // Render a rectangle shaped with optional rounding and borders | // Render a rectangle shaped with optional rounding and borders | ||||||
| void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding) | void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding) | ||||||
| { | { | ||||||
|   | |||||||
| @@ -1575,6 +1575,7 @@ namespace ImGui | |||||||
|     IMGUI_API void          RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); |     IMGUI_API void          RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); | ||||||
|     IMGUI_API void          RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL); |     IMGUI_API void          RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0,0), const ImRect* clip_rect = NULL); | ||||||
|     IMGUI_API void          RenderTextClippedEx(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0, 0), const ImRect* clip_rect = NULL); |     IMGUI_API void          RenderTextClippedEx(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0, 0), const ImRect* clip_rect = NULL); | ||||||
|  |     IMGUI_API void          RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end, const ImVec2* text_size_if_known); | ||||||
|     IMGUI_API void          RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); |     IMGUI_API void          RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); | ||||||
|     IMGUI_API void          RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); |     IMGUI_API void          RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f); | ||||||
|     IMGUI_API void          RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); |     IMGUI_API void          RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0); | ||||||
|   | |||||||
| @@ -7077,35 +7077,8 @@ bool ImGui::TabItemLabelAndCloseButton(ImDrawList* draw_list, const ImRect& bb, | |||||||
|         text_pixel_clip_bb.Max.x -= close_button_sz; |         text_pixel_clip_bb.Max.x -= close_button_sz; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Label with ellipsis |     float ellipsis_max_x = close_button_visible ? -FLT_MAX : bb.Max.x; | ||||||
|     // FIXME: This should be extracted into a helper but the use of text_pixel_clip_bb and !close_button_visible makes it tricky to abstract at the moment |     RenderTextEllipsis(draw_list, text_ellipsis_clip_bb.Min, text_ellipsis_clip_bb.Max, text_pixel_clip_bb.Max.x, ellipsis_max_x, label, NULL, &label_size); | ||||||
|     const char* label_display_end = FindRenderedTextEnd(label); |  | ||||||
|     if (label_size.x > text_ellipsis_clip_bb.GetWidth()) |  | ||||||
|     { |  | ||||||
|         const int ellipsis_dot_count = 3; |  | ||||||
|         const float ellipsis_width = (1.0f + 1.0f) * ellipsis_dot_count - 1.0f; |  | ||||||
|         const char* label_end = NULL; |  | ||||||
|         float label_size_clipped_x = g.Font->CalcTextSizeA(g.FontSize, text_ellipsis_clip_bb.GetWidth() - ellipsis_width + 1.0f, 0.0f, label, label_display_end, &label_end).x; |  | ||||||
|         if (label_end == label && label_end < label_display_end)    // Always display at least 1 character if there's no room for character + ellipsis |  | ||||||
|         { |  | ||||||
|             label_end = label + ImTextCountUtf8BytesFromChar(label, label_display_end); |  | ||||||
|             label_size_clipped_x = g.Font->CalcTextSizeA(g.FontSize, FLT_MAX, 0.0f, label, label_end).x; |  | ||||||
|         } |  | ||||||
|         while (label_end > label && ImCharIsBlankA(label_end[-1])) // Trim trailing space |  | ||||||
|         { |  | ||||||
|             label_end--; |  | ||||||
|             label_size_clipped_x -= g.Font->CalcTextSizeA(g.FontSize, FLT_MAX, 0.0f, label_end, label_end + 1).x; // Ascii blanks are always 1 byte |  | ||||||
|         } |  | ||||||
|         RenderTextClippedEx(draw_list, text_pixel_clip_bb.Min, text_pixel_clip_bb.Max, label, label_end, &label_size, ImVec2(0.0f, 0.0f)); |  | ||||||
|  |  | ||||||
|         const float ellipsis_x = text_pixel_clip_bb.Min.x + label_size_clipped_x + 1.0f; |  | ||||||
|         if (!close_button_visible && ellipsis_x + ellipsis_width <= bb.Max.x) |  | ||||||
|             RenderPixelEllipsis(draw_list, ImVec2(ellipsis_x, text_pixel_clip_bb.Min.y), GetColorU32(ImGuiCol_Text), ellipsis_dot_count); |  | ||||||
|     } |  | ||||||
|     else |  | ||||||
|     { |  | ||||||
|         RenderTextClippedEx(draw_list, text_pixel_clip_bb.Min, text_pixel_clip_bb.Max, label, label_display_end, &label_size, ImVec2(0.0f, 0.0f)); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return close_button_pressed; |     return close_button_pressed; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user