Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltip breaks disabled alpha #8454

Closed
lailoken opened this issue Mar 3, 2025 · 4 comments
Closed

Tooltip breaks disabled alpha #8454

lailoken opened this issue Mar 3, 2025 · 4 comments

Comments

@lailoken
Copy link

lailoken commented Mar 3, 2025

Version/Branch of Dear ImGui:

1.91.9 WIP (19184) docking

Back-ends:

imgui_impl_sdl2 + imgui_impl_opengl3

Compiler, OS:

gcc, Linux

Full config/build information:

Dear ImGui 1.91.9 WIP (19184)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: __linux__
define: __GNUC__=13
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sdl2
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000481
 NavEnableKeyboard
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoAutoMerge
io.ConfigViewportsNoDefaultParent
io.ConfigDockingWithShift
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C0E
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasVtxOffset
 RendererHasViewports
--------------------------------
io.Fonts: 12 fonts, Flags: 0x00000004, TexSize: 1024,2048
io.DisplaySize: 1.00,1.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

I have two buttons, both disabled, but the second one loses the alpha if the first one has a tooltip:

Screenshots/Video:

Image

Minimal, Complete and Verifiable Example code:

void TestImGui()
{
    ImGui::Begin("Test ImGui");
    ImGui::BeginDisabled();
    ImGui::PushStyleVar(ImGuiStyleVar_DisabledAlpha, 1.0f);
    ImGui::BeginDisabled();
    ImGui::Button("Disabled Button");
    if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_ForTooltip))
        ImGui::SetTooltip("Current Item is disabled");
    ImGui::Button("Another disabled Button");
    ImGui::EndDisabled();
    ImGui::PopStyleVar();
    ImGui::EndDisabled();
    ImGui::End();
}
@ocornut ocornut added the bug label Mar 3, 2025
@ocornut
Copy link
Owner

ocornut commented Mar 3, 2025

Thank you for your report! I can confirm there is a bug.
This is most likely caused by changes made for #7640. Will investigate.

@ocornut
Copy link
Owner

ocornut commented Mar 3, 2025

The problem is caused by the fact that:

ImGui::PushStyleVar(ImGuiStyleVar_DisabledAlpha, 1.0f);

is the value used by EndTooltip() to recalculate restored alpha.

Notice that the effect of that ImGui::PushStyleVar(ImGuiStyleVar_DisabledAlpha, 1.0f); is not even effective immediately, as the second nested BeginDisabled() sees we are already in disabled state and doesn't use it.

I should work toward stacking more actual alpha to restore, but must admit the nested BeginDisabled() + PushStyleVar(ImGuiStyleVar_DisabledAlpha) + BeginDisabled() tends to be confusing and misleading in the first place, as it is unnecessary AND causing the issue.

ocornut added a commit that referenced this issue Mar 3, 2025
…nested BeginDisabled() calls with PushStyleVar(ImGuiStyleVar_DisabledAlpha) within. (#8454, #7640)
@ocornut
Copy link
Owner

ocornut commented Mar 3, 2025

I have pushed a fix df31774.

I consider the PushStyleVar(ImGuiStyleVar_DisabledAlpha) call inside a BeginDisabled() block a bit UB / ill-defined - so possibly broken, depending on how we define its behavior - but if that's not a direct problem for you we can leave it as it.

Thanks for reporting and the repro !

@ocornut ocornut closed this as completed Mar 3, 2025
@lailoken
Copy link
Author

lailoken commented Mar 4, 2025

Thanks, it's not a breaking problem, was just a weird glitch I was having.

Where I waws using it the second disabled was conditional, and the PushStyleVar was supposed to affect another control.

Was strange that the first button was ok, and the second only breaks after the tooltip popup.

Just reported it here since it was hard to reproduce, but I agree it is a bit ill-defined and I could probably refactor that code a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants