From 572896a808b11fd8d7236cd5753bcff69f8151c0 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Fri, 14 Jan 2022 19:49:26 -0500 Subject: [PATCH] Add configurable color for button text in hovered and active states --- imgui.cpp | 2 ++ imgui.h | 2 ++ imgui_draw.cpp | 2 ++ imgui_widgets.cpp | 7 +++++++ 4 files changed, 13 insertions(+) diff --git a/imgui.cpp b/imgui.cpp index d237d1df2..635e00f91 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2807,6 +2807,8 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx) { case ImGuiCol_Text: return "Text"; case ImGuiCol_TextDisabled: return "TextDisabled"; + case ImGuiCol_TextButtonHover: return "TextButtonHover"; + case ImGuiCol_TextButtonActive: return "TextButtonActive"; case ImGuiCol_WindowBg: return "WindowBg"; case ImGuiCol_ChildBg: return "ChildBg"; case ImGuiCol_PopupBg: return "PopupBg"; diff --git a/imgui.h b/imgui.h index a1cfb7694..f0e8174e7 100644 --- a/imgui.h +++ b/imgui.h @@ -1557,6 +1557,8 @@ enum ImGuiCol_ { ImGuiCol_Text, ImGuiCol_TextDisabled, + ImGuiCol_TextButtonHover, + ImGuiCol_TextButtonActive, ImGuiCol_WindowBg, // Background of normal windows ImGuiCol_ChildBg, // Background of child windows ImGuiCol_PopupBg, // Background of popups, menus, tooltips windows diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 423f8cd27..646994a0a 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -194,6 +194,8 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst) colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + colors[ImGuiCol_TextButtonHover] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); + colors[ImGuiCol_TextButtonActive] = ImVec4(0.90f, 0.90f, 0.90f, 1.00f); colors[ImGuiCol_WindowBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f); colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_PopupBg] = ImVec4(0.08f, 0.08f, 0.08f, 0.94f); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index ad9d44da6..a56626b7f 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -701,8 +701,15 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags if (g.LogEnabled) LogSetNextTextDecoration("[", "]"); + + if (hovered) + ImGui::PushStyleColor(ImGuiCol_Text, g.Style.Colors[held ? ImGuiCol_TextButtonActive : ImGuiCol_TextButtonHover]); + RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb); + if (hovered) + ImGui::PopStyleColor(); + // Automatically close popups //if (pressed && !(flags & ImGuiButtonFlags_DontClosePopups) && (window->Flags & ImGuiWindowFlags_Popup)) // CloseCurrentPopup();