ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
59.51k stars 10.14k forks source link

Issue with ImGui::PushStyleColor for ImGuiCol_HeaderActive and ImGuiCol_Header #6419

Open Koromire opened 1 year ago

Koromire commented 1 year ago

Dear ImGui developers,

I am facing an issue with the ImGui::PushStyleColor function in relation to ImGuiCol_Header, ImGuiCol_HeaderActive styles. The function seems to work as expected when used with ImGuiCol_HeaderHovered, however, it doesn't seem to have an effect with ImGuiCol_HeaderActive or ImGuiCol_Header.

Dear ImGui version: 1.89.5 Branch name: master Platform/renderer back-ends: imgui_impl_vulkan, imgui_impl_glfw Operating System: Windows 11 22h2

Goals: I am trying to modify the color of the header, both in its active state and at rest.

Expectations: I expect the header color to change according to the color I specify with the ImGui::PushStyleColor function.

What I have tried:

I have used the following code to change the color of the header:

``ImGui::PushStyleColor(ImGuiCol_Header, IM_COL32(255, 0, 0, 255)); ImGui::PushStyleColor(ImGuiCol_HeaderActive, IM_COL32(255, 0, 0, 255));

if (ImGui::BeginMenu("File")) { if (ImGui::MenuItem("Save", "Ctrl+S")) { // Save file } ImGui::EndMenu(); }

ImGui::PopStyleColor(2);``

While the hover color changes successfully with ImGuiCol_HeaderHovered, the code above does not change the color of the header when it is active or at rest.

Modification to ImGui or the back-end: No substantial modifications have been made to my copy of Dear ImGui or the back-end.

Language and Wrapper/binding information: I am calling Dear ImGui directly from C++.

I am looking forward to your response. Thank you for your time and efforts in maintaining this library.

Best Regards,

ocornut commented 1 year ago

There's a bit of an inconsistency with how those colors are named and used.

While CollapsingHeader() does:

const ImU32 bg_col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
RenderFrame(frame_bb.Min, frame_bb.Max, bg_col, true, style.FrameRounding);

Selectable()/MenuItem() and TreeNode() do:

if (hovered || selected)
{
    const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
    RenderFrame(bb.Min, bb.Max, col, false, 0.0f);
}

There are two issues: