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

InputText is invalid when create a second frame. #8173

Closed
kindred77 opened this issue Nov 22, 2024 · 4 comments
Closed

InputText is invalid when create a second frame. #8173

kindred77 opened this issue Nov 22, 2024 · 4 comments

Comments

@kindred77
Copy link

Version/Branch of Dear ImGui:

Branch: master

Back-ends:

imgui_impl_sdl2.cpp+imgui_impl_sdlrenderer2.cpp

Compiler, OS:

windows11 + mingw64

Full config/build information:

No response

Details:

I imported imgui into my game app on windows 11, thanks very much for you guys' great work.
I found the InputText will be invalid when create a second frame.
It just show there with no cursor blink and can not edit, like turned to be readonly.
I am not sure it is a bug, or imgui can create only one frame.

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

//new a frame and create my InputText
ImGui_NewFrame();
ImGui_Begin();
InputTextWithHint(xxx);
ImGui_End();
//close the frame and render
ImGui_ImplSDLRenderer2_RenderDrawData(ImGui::GetDrawData(), renderer);
//create another frame, the InputText is shown but can not focus and edit.
ImGui_NewFrame();
ImGui_EndFrame();

@GamingMinds-DanielC
Copy link
Contributor

GamingMinds-DanielC commented Nov 22, 2024

Why the second frame, especially an empty one? Frames need to be continuous. The interaction with widgets happens mostly between frames. If you don't submit a widget for a frame, it cannot hold focus or do anything basically. That's expected behavior, not a bug.

Your example code is not valid (it wouldn't compile when pasted into a test application) and leaves a few questions open. Are you using a wrapper? The functions of the C++ interface are in a namespace, they don't use an ImGui_ prefix. Also Begin() has no default value for its first parameter, the window title. If you are using a wrapper and that has a default, maybe what you are trying to make is a second window, not a second frame. You would have to submit the second window within the same frame.

@kindred77
Copy link
Author

Thanks for feedback, the posted code is fake code, just for explaining my process.
Actually, I want to embed ImGui into my game app. But there's other game UI based on some game images. They will be covered each other because of different layout level.
I supposed to save the texture or draw data for all UI components temporarily and render them accourding layout level in global render process.
I found I have to endup a frame when trying to get the draw data in ImGui.
So it seams have to create mutiple frame if I want to render the ImGui components through different layout level.
Or, am I take a wrong way?

@GamingMinds-DanielC
Copy link
Contributor

GamingMinds-DanielC commented Nov 25, 2024

Frames need to be continuous to work properly. If you switch between two UIs in your main loop, you have two distinct frames each iteration. From the perspective of the library, windows and their widgets would blink on for a single frame only and then not exist for the next frame, effectively being destroyed and recreated constantly instead of just existing. No UI element could hold focus of even interact with the user that way.

If you really need two UIs at the same time, you can create two ImGui contexts and switch between them, take a look at ImGui::CreateContext() and ImGui::SetCurrentContext() for that. Both need to bi initialized properly with their backends. Then, in your main loop, you can activate the first context, process its frame, switch to the second context and process that ones frame. Then frames would be continuous inside their respective contexts. But be aware that ImGui is not thread safe.

@kindred77
Copy link
Author

Clear, thanks.

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

3 participants