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

Detect when Combo() opened #7739

Closed
zMidair opened this issue Jun 26, 2024 · 8 comments
Closed

Detect when Combo() opened #7739

zMidair opened this issue Jun 26, 2024 · 8 comments

Comments

@zMidair
Copy link

zMidair commented Jun 26, 2024

Version/Branch of Dear ImGui:

Version 1.90

Back-ends:

n/a

Compiler, OS:

Windows 11 + MSVC 2022

Full config/build information:

No response

Details:

How can I detect when a Combo() is opened?

Hello, by opened I mean when its clicked and its items are shown.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

if (ImGui::Combo("Clickpack", &clickpack.selectedClickpack, clickpack.clickpackList.data(), clickpack.clickpackList.size())) 
{}
@GamingMinds-DanielC
Copy link
Contributor

If you can rework your call to Combo() to a BeginCombo() / EndCombo() pair, the combo is open if BeginCombo() returns true. You would then have to submit your items yourself, but you can look at the Combo() implementation for how to do that.

If you want to keep using the more compact Combo() function, you can calculate the popup id with ImHashStr("##ComboPopup", 0, GetItemID()) and check if that popup is currently open.

@ocornut
Copy link
Owner

ocornut commented Jun 26, 2024

How can I detect when a Combo() is opened?

It's also worth explaining why you need this, as this might be a XY Problem question.

@zMidair
Copy link
Author

zMidair commented Jun 26, 2024

How can I detect when a Combo() is opened?

It's also worth explaining why you need this, as this might be a XY Problem question.

I need this since im using the Combo to choose a file in a folder and I want to update the list when the Combo is opened.

@zMidair
Copy link
Author

zMidair commented Jun 26, 2024

If you can rework your call to Combo() to a BeginCombo() / EndCombo() pair, the combo is open if BeginCombo() returns true. You would then have to submit your items yourself, but you can look at the Combo() implementation for how to do that.

If you want to keep using the more compact Combo() function, you can calculate the popup id with ImHashStr("##ComboPopup", 0, GetItemID()) and check if that popup is currently open.

Can you give me an example?

@ocornut
Copy link
Owner

ocornut commented Jun 26, 2024

I need this since im using the Combo to choose a file in a folder and I want to update the list when the Combo is opened.

Then you should use if (ImGui::IsWindowAppearing())

@ocornut ocornut closed this as completed Jun 26, 2024
@GamingMinds-DanielC
Copy link
Contributor

GamingMinds-DanielC commented Jun 26, 2024

Can you give me an example?

As I said, you can look at the implementation of Combo() for an example of how to use those functions. After all, that is just a wrapper for the step by step approach. Here is the exact place:
https://github.com/ocornut/imgui/blob/master/imgui_widgets.cpp#L1951-L1978

As Omar hinted at, you can use IsWindowAppearing() to test if a window has just been opened. Right after BeginCombo() returns true is the best place for that, then you are testing if the opened popup is just appearing.

@zMidair
Copy link
Author

zMidair commented Jun 26, 2024

I need this since im using the Combo to choose a file in a folder and I want to update the list when the Combo is opened.

Then you should use if (ImGui::IsWindowAppearing())

Doesnt it need a parameter? Or where should I put it? Before or after the Combo is created

@zMidair
Copy link
Author

zMidair commented Jun 26, 2024

Can you give me an example?

As I said, you can look at the implementation of Combo() for an example of how to use those functions. After all, that is just a wrapper for the step by step approach. Here is the exact place: https://github.com/ocornut/imgui/blob/master/imgui_widgets.cpp#L1951-L1978

As Omar hinted at, you can use IsWindowAppearing() to test if a window has just been opened. Right after BeginCombo() returns true is the best place for that, then you are testing if the opened popup is just appearing.

Alr thanks, I will try this

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

3 participants