Add configurable color for button text in hovered and active states

This commit is contained in:
Justin Li 2022-01-14 19:49:26 -05:00
parent 45c4365ec3
commit 572896a808
4 changed files with 13 additions and 0 deletions

View File

@ -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";

View File

@ -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

View File

@ -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);

View File

@ -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();