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

Add IsItemDisabled #4675

Closed
wants to merge 3 commits into from
Closed

Add IsItemDisabled #4675

wants to merge 3 commits into from

Conversation

mundusnine
Copy link

@mundusnine mundusnine commented Oct 26, 2021

I am currently using an ImDrawList like in the party's to do custom drawing for a record button using a ImGui::InvisibleButton. I draw the background of the button i.e. :

if(!ImGui::IsItemDisabled() && mouse.x > 0.0f  && mouse.x < 1.0f && mouse.y > 0.0f && mouse.y < 1.0f){
    col = colors[ImGuiCol_ButtonHovered];
}
 d->AddRectFilled(a,b,ImGui::GetColorU32(col),0.0f,ImDrawFlags_None);

As I needed to detect if my item was disabled and the BeginDisabled api is Beta I saw the need to add it. The workaround would of needed that I include imgui_internal.h in my project to have access to the ImGuiContext struct def.

I imagine that imgui_internal should not be used by users ?

Example:
https://imgur.com/a/AiJ4sHk

@ocornut
Copy link
Owner

ocornut commented Oct 26, 2021

Hello,

&& mouse.x > 0.0f && mouse.x < 1.0f && mouse.y > 0.0f && mouse.y < 1.0f){

You should not test coordinates like that, if you used IsItemHovered() it would handle the disabling state.

@ocornut
Copy link
Owner

ocornut commented Nov 2, 2021

You should not test coordinates like that, if you used IsItemHovered() it would handle the disabling state.

Can you confirm this solves your issue and the IsItemDisabled() function is not required anymore ?

(
By the way, this is slightly incorrect:

bool ImGui::IsItemDisabled()
{
    ImGuiContext& g = *GImGui;
    return (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0;
}

If we wanted that function, it should be implemented as:

bool ImGui::IsItemDisabled()
{
    ImGuiContext& g = *GImGui;
    return (g.LastItemData.InFlags & ImGuiItemFlags_Disabled) != 0;
}

In order to handle idioms such as PushDisabled()/Item()/PopDisabled()/IsItemDisabled() (not so likely) as well as Selectable() with the ImGuiSelectableFlags_Disabled flag which does something similar.
)

Reasons: 
```
In order to handle idioms such as PushDisabled()/Item()/PopDisabled()/IsItemDisabled() (not so likely) as well as Selectable() with the ImGuiSelectableFlags_Disabled flag which does something similar.
```
@mundusnine
Copy link
Author

I can confirm that IsItemHovered() handled my usecase. If ever IsItemDisabled would be desirable I added the changes that you proposed.

@ocornut
Copy link
Owner

ocornut commented Nov 2, 2021

Thank you!
I'll close this for now and we have the code as reference shall a need arise.
Linking for #211

@ocornut ocornut closed this Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants