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

Explicitly setting widget state / activating widget? #3985

Closed
FoxLeader opened this issue Mar 29, 2021 · 2 comments
Closed

Explicitly setting widget state / activating widget? #3985

FoxLeader opened this issue Mar 29, 2021 · 2 comments

Comments

@FoxLeader
Copy link

Ideally I would like to able to do something like this:

if (somethingHappened)
    ImGui::SetNextItemStateAsActive();
ImGui::Button("Example");
if (ImGui::IsItemActive())
    // do stuff

A similar question has been asked a few days ago (#3949), but I'm not trying to build a testing environment, I'm just interested in being able to pass the Active state from a widget to another and was wondering if it was possible somehow.

@ocornut
Copy link
Owner

ocornut commented Mar 29, 2021

Strictly speaking if I answer your question, underlying you would just need to call SetActiveID() from imgui_internal.h with the right ID (here GetID("Example") from the same location in the ID stack, or GetItemID() after the Button()), but depending on the widget it doesn't necessarily mean the Button is going to be activated or return true as some behavior will rely on mouse position or button down/up state etc. So at at heart I feel like you are looking at the same thing as #3949 and may be better to move the discussion back there?

@ocornut ocornut changed the title Explicitly setting Widget State Explicitly setting widget state / activating widget? Mar 29, 2021
@ocornut ocornut closed this as completed Mar 29, 2021
@FoxLeader
Copy link
Author

Thing is, I'm not trying to simulate user input, I was merely looking for a way to transfer an action done by the user from a widget to another.

Here's my use case: I'm trying to replicate Blender's behaviour where you are able to split a Viewport by clicking and dragging from the upper-left corner, and I need switch the currently active widget from the button which is functioning as the hotspot area to the button which will be used as splitter between the two newly created Viewports.

Turned out that your suggestion put me on the right track, I just needed to change the ActiveId of the current context. Looks a bit hacky but apparently everything is working perfectly.

I understand that this is not by any stretch of imagination a perfect solution, but it may be worth to mention it for those looking to do something similar. I can reformulate everything with code examples if you think this may be helpful to someone.

ocornut added a commit that referenced this issue Nov 4, 2021
…ling, using nav queries. (#4449)

Not using counter/modulo anymore and special provisions to handle tab wrapping with ImGuiListClipper. Wrapping may be done better as a next-frame forwarded request.
Also one extra step toward #3949 #3985
actondev pushed a commit to actondev/imgui that referenced this issue Nov 26, 2021
…ling, using nav queries. (ocornut#4449)

Not using counter/modulo anymore and special provisions to handle tab wrapping with ImGuiListClipper. Wrapping may be done better as a next-frame forwarded request.
Also one extra step toward ocornut#3949 ocornut#3985
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

No branches or pull requests

2 participants