diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index 367eac269..304b45c21 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -123,6 +123,8 @@ namespace ImGuiExt { int m_width = 0, m_height = 0; }; + float GetTextWrapPos(); + int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data); bool IconHyperlink(const char *icon, const char *label, const ImVec2 &size_arg = ImVec2(0, 0), ImGuiButtonFlags flags = 0); @@ -186,7 +188,12 @@ namespace ImGuiExt { void SmallProgressBar(float fraction, float yOffset = 0.0F); inline void TextFormatted(std::string_view fmt, auto &&...args) { - ImGui::TextUnformatted(hex::format(fmt, std::forward(args)...).c_str()); + if constexpr (sizeof...(args) == 0) { + ImGui::TextUnformatted(fmt.data(), fmt.data() + fmt.size()); + } else { + const auto string = hex::format(fmt, std::forward(args)...); + ImGui::TextUnformatted(string.c_str(), string.c_str() + string.size()); + } } inline void TextFormattedSelectable(std::string_view fmt, auto &&...args) { @@ -208,15 +215,24 @@ namespace ImGuiExt { } inline void TextFormattedColored(ImColor color, std::string_view fmt, auto &&...args) { - ImGui::TextColored(color, "%s", hex::format(fmt, std::forward(args)...).c_str()); + ImGui::PushStyleColor(ImGuiCol_Text, color.Value); + ImGuiExt::TextFormatted(fmt, std::forward(args)...); + ImGui::PopStyleColor(); } inline void TextFormattedDisabled(std::string_view fmt, auto &&...args) { - ImGui::TextDisabled("%s", hex::format(fmt, std::forward(args)...).c_str()); + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyle().Colors[ImGuiCol_TextDisabled]); + ImGuiExt::TextFormatted(fmt, std::forward(args)...); + ImGui::PopStyleColor(); } inline void TextFormattedWrapped(std::string_view fmt, auto &&...args) { - ImGui::TextWrapped("%s", hex::format(fmt, std::forward(args)...).c_str()); + const bool need_backup = ImGuiExt::GetTextWrapPos() < 0.0F; // Keep existing wrap position if one is already set + if (need_backup) + ImGui::PushTextWrapPos(0.0F); + ImGuiExt::TextFormatted(fmt, std::forward(args)...); + if (need_backup) + ImGui::PopTextWrapPos(); } inline void TextFormattedWrappedSelectable(std::string_view fmt, auto &&...args) { diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index ff528eb1a..5d4d6a589 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -285,6 +285,10 @@ namespace ImGuiExt { glDeleteTextures(1, reinterpret_cast(&m_textureId)); } + float GetTextWrapPos() { + return GImGui->CurrentWindow->DC.TextWrapPos; + } + int UpdateStringSizeCallback(ImGuiInputTextCallbackData *data) { if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) { auto &string = *static_cast(data->UserData); @@ -1194,7 +1198,7 @@ namespace ImGuiExt { if (collapsed != nullptr && *collapsed) { ImGui::SetCursorPosY(ImGui::GetCursorPosY() - (ImGui::GetStyle().FramePadding.y * 2)); - ImGui::TextDisabled("..."); + ImGuiExt::TextFormattedDisabled("..."); result = false; } } diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index e40998786..20ea5b711 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -325,7 +325,7 @@ namespace hex { // Plugin load error popups // These are not translated because they should always be readable, no matter if any localization could be loaded or not { - auto drawPluginFolderTable = [] { + const static auto drawPluginFolderTable = [] { ImGuiExt::UnderlinedText("Plugin folders"); if (ImGui::BeginTable("plugins", 2, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY | ImGuiTableFlags_SizingFixedFit, ImVec2(0, 100_scaled))) { ImGui::TableSetupScrollFreeze(0, 1); diff --git a/plugins/builtin/source/content/data_visualizers.cpp b/plugins/builtin/source/content/data_visualizers.cpp index 2b4063465..a221be0bd 100644 --- a/plugins/builtin/source/content/data_visualizers.cpp +++ b/plugins/builtin/source/content/data_visualizers.cpp @@ -63,11 +63,11 @@ namespace hex::plugin::builtin { ImGui::TextUnformatted(" "); break; case 0xFF: - ImGui::TextDisabled("##"); + ImGuiExt::TextFormattedDisabled("##"); break; default: if (c >= ' ' && c <= '~') - ImGui::Text(".%c", c); + ImGuiExt::TextFormatted(".{:c}", char(c)); else ImGui::Text(getFormatString(upperCase), c); break; diff --git a/plugins/ui/source/ui/hex_editor.cpp b/plugins/ui/source/ui/hex_editor.cpp index 6f759e907..38409d98e 100644 --- a/plugins/ui/source/ui/hex_editor.cpp +++ b/plugins/ui/source/ui/hex_editor.cpp @@ -30,9 +30,9 @@ namespace hex::ui { ImGui::TextUnformatted(string.data()); } else - ImGui::TextDisabled("."); + ImGuiExt::TextFormattedDisabled("."); } else { - ImGui::TextDisabled("."); + ImGuiExt::TextFormattedDisabled("."); } } @@ -455,12 +455,17 @@ namespace hex::ui { const float SeparatorColumWidth = 6_scaled; const auto CharacterSize = ImGui::CalcTextSize("0"); - if (const auto &visualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit"); m_currDataVisualizer == nullptr && visualizer != nullptr) { - m_currDataVisualizer = visualizer; - return; + if (m_currDataVisualizer == nullptr) { + if (const auto &visualizer = ContentRegistry::HexEditor::getVisualizerByName("hex.builtin.visualizer.hexadecimal.8bit"); visualizer != nullptr) { + m_currDataVisualizer = visualizer; + return; + } + } + + if (m_miniMapVisualizer == nullptr) { + if (const auto &visualizers = ContentRegistry::HexEditor::impl::getMiniMapVisualizers(); !visualizers.empty()) + m_miniMapVisualizer = visualizers.front(); } - if (const auto &visualizers = ContentRegistry::HexEditor::impl::getMiniMapVisualizers(); m_miniMapVisualizer == nullptr && !visualizers.empty()) - m_miniMapVisualizer = visualizers.front(); const auto bytesPerCell = m_currDataVisualizer->getBytesPerCell(); const u16 columnCount = m_bytesPerRow / bytesPerCell;