mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-04 01:34:32 +00:00 
			
		
		
		
	Bypass unnecessary formatting when using the TextColored()/TextWrapped()/TextDisabled() helpers with a "%s" format string. (#3466)
This commit is contained in:
		@@ -55,6 +55,8 @@ Other Changes:
 | 
				
			|||||||
  where v_min == v_max. (#3361)
 | 
					  where v_min == v_max. (#3361)
 | 
				
			||||||
- SliderInt, SliderScalar: Fixed reaching of maximum value with inverted integer min/max ranges, both
 | 
					- SliderInt, SliderScalar: Fixed reaching of maximum value with inverted integer min/max ranges, both
 | 
				
			||||||
  with signed and unsigned types. Added reverse Sliders to Demo. (#3432, #3449) [@rokups]
 | 
					  with signed and unsigned types. Added reverse Sliders to Demo. (#3432, #3449) [@rokups]
 | 
				
			||||||
 | 
					- Text: Bypass unnecessary formatting when using the TextColored()/TextWrapped()/TextDisabled() helpers
 | 
				
			||||||
 | 
					  with a "%s" format string. (#3466)
 | 
				
			||||||
- BeginMenuBar: Fixed minor bug where CursorPosMax gets pushed to CursorPos prior to calling BeginMenuBar(),
 | 
					- BeginMenuBar: Fixed minor bug where CursorPosMax gets pushed to CursorPos prior to calling BeginMenuBar(),
 | 
				
			||||||
  so e.g. calling the function at the end of a window would often add +ItemSpacing.y to scrolling range.
 | 
					  so e.g. calling the function at the end of a window would often add +ItemSpacing.y to scrolling range.
 | 
				
			||||||
- TreeNode, CollapsingHeader: Made clicking on arrow toggle toggle the open state on the Mouse Down event
 | 
					- TreeNode, CollapsingHeader: Made clicking on arrow toggle toggle the open state on the Mouse Down event
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -274,6 +274,9 @@ void ImGui::TextColored(const ImVec4& col, const char* fmt, ...)
 | 
				
			|||||||
void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
 | 
					void ImGui::TextColoredV(const ImVec4& col, const char* fmt, va_list args)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PushStyleColor(ImGuiCol_Text, col);
 | 
					    PushStyleColor(ImGuiCol_Text, col);
 | 
				
			||||||
 | 
					    if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
 | 
				
			||||||
 | 
					        TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
        TextV(fmt, args);
 | 
					        TextV(fmt, args);
 | 
				
			||||||
    PopStyleColor();
 | 
					    PopStyleColor();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -288,7 +291,11 @@ void ImGui::TextDisabled(const char* fmt, ...)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void ImGui::TextDisabledV(const char* fmt, va_list args)
 | 
					void ImGui::TextDisabledV(const char* fmt, va_list args)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    PushStyleColor(ImGuiCol_Text, GImGui->Style.Colors[ImGuiCol_TextDisabled]);
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
 | 
					    PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
 | 
				
			||||||
 | 
					    if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
 | 
				
			||||||
 | 
					        TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
        TextV(fmt, args);
 | 
					        TextV(fmt, args);
 | 
				
			||||||
    PopStyleColor();
 | 
					    PopStyleColor();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -303,10 +310,13 @@ void ImGui::TextWrapped(const char* fmt, ...)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void ImGui::TextWrappedV(const char* fmt, va_list args)
 | 
					void ImGui::TextWrappedV(const char* fmt, va_list args)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ImGuiWindow* window = GetCurrentWindow();
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
    bool need_backup = (window->DC.TextWrapPos < 0.0f);  // Keep existing wrap position if one is already set
 | 
					    bool need_backup = (g.CurrentWindow->DC.TextWrapPos < 0.0f);  // Keep existing wrap position if one is already set
 | 
				
			||||||
    if (need_backup)
 | 
					    if (need_backup)
 | 
				
			||||||
        PushTextWrapPos(0.0f);
 | 
					        PushTextWrapPos(0.0f);
 | 
				
			||||||
 | 
					    if (fmt[0] == '%' && fmt[1] == 's' && fmt[2] == 0)
 | 
				
			||||||
 | 
					        TextEx(va_arg(args, const char*), NULL, ImGuiTextFlags_NoWidthForLargeClippedText); // Skip formatting
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
        TextV(fmt, args);
 | 
					        TextV(fmt, args);
 | 
				
			||||||
    if (need_backup)
 | 
					    if (need_backup)
 | 
				
			||||||
        PopTextWrapPos();
 | 
					        PopTextWrapPos();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user