diff --git a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h index 3c469a715..358e8b915 100644 --- a/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h +++ b/lib/libimhex/include/hex/ui/imgui_imhex_extensions.h @@ -194,7 +194,9 @@ namespace ImGuiExt { void ProgressBar(float fraction, ImVec2 size_value = ImVec2(0, 0), float yOffset = 0.0F); - inline void TextFormatted(std::string_view fmt, auto &&...args) { + [[nodiscard]] bool IsDarkBackground(const ImColor& bgColor); + + void TextFormatted(std::string_view fmt, auto &&...args) { if constexpr (sizeof...(args) == 0) { ImGui::TextUnformatted(fmt.data(), fmt.data() + fmt.size()); } else { @@ -203,7 +205,7 @@ namespace ImGuiExt { } } - inline void TextFormattedSelectable(std::string_view fmt, auto &&...args) { + void TextFormattedSelectable(std::string_view fmt, auto &&...args) { auto text = hex::format(fmt, std::forward(args)...); ImGui::PushID(text.c_str()); @@ -222,19 +224,25 @@ namespace ImGuiExt { ImGui::PopID(); } - inline void TextFormattedColored(ImColor color, std::string_view fmt, auto &&...args) { + void TextFormattedColored(ImColor color, std::string_view fmt, auto &&...args) { ImGui::PushStyleColor(ImGuiCol_Text, color.Value); ImGuiExt::TextFormatted(fmt, std::forward(args)...); ImGui::PopStyleColor(); } - inline void TextFormattedDisabled(std::string_view fmt, auto &&...args) { + void TextFormattedReadableColor(ImColor backgroundColor, std::string_view fmt, auto &&...args) { + ImGui::PushStyleColor(ImGuiCol_Text, IsDarkBackground(backgroundColor) ? 0xFFFFFFFF : 0xFF000000); + ImGuiExt::TextFormatted(fmt, std::forward(args)...); + ImGui::PopStyleColor(); + } + + void TextFormattedDisabled(std::string_view fmt, auto &&...args) { 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) { + void TextFormattedWrapped(std::string_view fmt, auto &&...args) { const bool need_backup = ImGuiExt::GetTextWrapPos() < 0.0F; // Keep existing wrap position if one is already set if (need_backup) ImGui::PushTextWrapPos(0.0F); @@ -243,7 +251,7 @@ namespace ImGuiExt { ImGui::PopTextWrapPos(); } - inline void TextFormattedWrappedSelectable(std::string_view fmt, auto &&...args) { + void TextFormattedWrappedSelectable(std::string_view fmt, auto &&...args) { // Manually wrap text, using the letter M (generally the widest character in non-monospaced fonts) to calculate the character width to use. auto text = wolv::util::trim(wolv::util::wrapMonospacedString( hex::format(fmt, std::forward(args)...), @@ -276,13 +284,13 @@ namespace ImGuiExt { } void TextUnformattedCentered(const char *text); - inline void TextFormattedCentered(std::string_view fmt, auto &&...args) { + void TextFormattedCentered(std::string_view fmt, auto &&...args) { auto text = hex::format(fmt, std::forward(args)...); TextUnformattedCentered(text.c_str()); } - inline void TextFormattedCenteredHorizontal(std::string_view fmt, auto &&...args) { + void TextFormattedCenteredHorizontal(std::string_view fmt, auto &&...args) { auto text = hex::format(fmt, std::forward(args)...); auto availableSpace = ImGui::GetContentRegionAvail(); auto textSize = ImGui::CalcTextSize(text.c_str(), nullptr, false, availableSpace.x * 0.75F); diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 2d622525d..88050d869 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -1445,6 +1445,21 @@ namespace ImGuiExt { ImGui::PopClipRect(); } + bool IsDarkBackground(const ImColor& bgColor) { + // Extract RGB components in 0–255 range + int r = static_cast(bgColor.Value.x * 255.0f); + int g = static_cast(bgColor.Value.y * 255.0f); + int b = static_cast(bgColor.Value.z * 255.0f); + + // Compute brightness using perceived luminance + int brightness = (r * 299 + g * 587 + b * 114) / 1000; + + // If brightness is below threshold, use white text + return brightness < 128; + } + + + static bool s_imguiTestEngineEnabled = false; void ImGuiTestEngine::setEnabled(bool enabled) { diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 408589e90..b8694e272 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -700,12 +700,14 @@ namespace hex { startY += 2 * ImGui::GetStyle().FramePadding.y; #endif - for (const auto &banner : impl::BannerBase::getOpenBanners() | std::views::take(5)) { + for (const auto &banner : impl::BannerBase::getOpenBanners() | std::views::take(3)) { auto &style = ImGui::GetStyle(); ImGui::SetNextWindowPos(ImVec2(windowPos.x + 1_scaled, startY)); ImGui::SetNextWindowSize(ImVec2(ImHexApi::System::getMainWindowSize().x - 2_scaled, height)); ImGui::SetNextWindowViewport(viewport->ID); - ImGui::PushStyleColor(ImGuiCol_WindowBg, banner->getColor().Value); + const auto backgroundColor = banner->getColor().Value; + ImGui::PushStyleColor(ImGuiCol_WindowBg, backgroundColor); + ImGui::PushStyleColor(ImGuiCol_Text, ImGuiExt::IsDarkBackground(backgroundColor) ? 0xFFFFFFFF : 0xFF000000); auto prevShadowOffset = style.WindowShadowOffsetDist; auto prevShadowAngle = style.WindowShadowOffsetAngle; style.WindowShadowOffsetDist = 12_scaled; @@ -727,7 +729,7 @@ namespace hex { } } ImGui::End(); - ImGui::PopStyleColor(); + ImGui::PopStyleColor(2); startY += height; } diff --git a/plugins/ui/include/banners/banner_button.hpp b/plugins/ui/include/banners/banner_button.hpp index 707f8b34f..f5f15082d 100644 --- a/plugins/ui/include/banners/banner_button.hpp +++ b/plugins/ui/include/banners/banner_button.hpp @@ -18,6 +18,7 @@ namespace hex::ui { const auto iconSize = ImGui::CalcTextSize(m_icon); const auto textHeight = std::max(ImGui::CalcTextSize(Lang(m_message)).y, iconSize.y); const auto textOffset = (ImGui::GetWindowHeight() - textHeight) / 2; + ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textOffset); ImGui::TextUnformatted(m_icon); ImGui::SameLine(0, 10_scaled); @@ -39,8 +40,8 @@ namespace hex::ui { ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 2_scaled); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1_scaled); ImGui::PushStyleVarY(ImGuiStyleVar_FramePadding, 0.0F); - ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_Tab)); - if (ImGuiExt::DimmedButton(buttonText.c_str())) { + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetColorU32(ImGuiCol_Button, 0.9F)); + if (ImGui::Button(buttonText.c_str())) { m_buttonCallback(); this->close(); }