Open Koromire opened 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:
ImGuiCol_Header
unless hovered or selected. I don't have a good solution for this apart from marking the item as Selected as a workaround. I would like to redesign those enums eventuallyImGuiCol_HeaderActive
: MenuItem()
specifically use ImGuiButtonFlags_PressedOnRelease
(via ImGuiSelectableFlags_SelectOnRelease
) which in turns makes the item not become active while held. I think we could possibly rework this but it's not so simple 1) current _Header color would make this look not very good on menu items, and 2) OS menus on Windows tends to allow hovering any menus even while holding a mouse button down, taking active id would break that, so perhaps ButtonBehavior()
with ImGuiButtonFlags_PressedOnRelease
can be reworked to report "held = true" without active id but it's a change that needs to be made with care. Also notice on Windows none of the menus change colors when held, presumably because with traditional buttons this suggests locking active item to clicked one, vs on menus on it doesn't.
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,