From 692d1699282f09612dac76451ba151df3320abb9 Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Wed, 14 Aug 2024 21:56:58 -0700 Subject: [PATCH 1/2] =?UTF-8?q?draw=5Fcolored=5Ftext=20should=20=E2=80=9Cd?= =?UTF-8?q?raw=E2=80=9D=20an=20empty=20line=20if=20given=20an=20empty=20st?= =?UTF-8?q?ring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It needs to be consistent and always end with the cursor on a new line. Fixes #75685 --- src/cata_imgui.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 3e11856fe1a90..120551e6b2a91 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -436,6 +436,11 @@ void cataimgui::draw_colored_text( std::string const &text, ImGui::PushID( text.c_str() ); int startColorStackCount = GImGui->ColorStack.Size; ImGuiID itemId = GImGui->CurrentWindow->IDStack.back(); + + if( text.empty() ) { + ImGui::NewLine( ); + } + size_t chars_per_line = size_t( wrap_width ); if( chars_per_line == 0 ) { chars_per_line = SIZE_MAX; From d90f28227bf8e9109dcf25166759f452429a0e8e Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Sun, 18 Aug 2024 00:38:16 -0700 Subject: [PATCH 2/2] draw_colored_text should do even less work when the text is empty Co-authored-by: Zhilkin Serg --- src/cata_imgui.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cata_imgui.cpp b/src/cata_imgui.cpp index 120551e6b2a91..578c9709730bb 100644 --- a/src/cata_imgui.cpp +++ b/src/cata_imgui.cpp @@ -433,14 +433,15 @@ void cataimgui::draw_colored_text( std::string const &text, nc_color &color, void cataimgui::draw_colored_text( std::string const &text, float wrap_width, bool *is_selected, bool *is_focused, bool *is_hovered ) { + if( text.empty() ) { + ImGui::NewLine(); + return; + } + ImGui::PushID( text.c_str() ); int startColorStackCount = GImGui->ColorStack.Size; ImGuiID itemId = GImGui->CurrentWindow->IDStack.back(); - if( text.empty() ) { - ImGui::NewLine( ); - } - size_t chars_per_line = size_t( wrap_width ); if( chars_per_line == 0 ) { chars_per_line = SIZE_MAX;