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

click on Inputtext no refreshing text #5054

Closed
kmilo9999 opened this issue Feb 24, 2022 · 5 comments
Closed

click on Inputtext no refreshing text #5054

kmilo9999 opened this issue Feb 24, 2022 · 5 comments

Comments

@kmilo9999
Copy link

Version/Branch of Dear ImGui:

Version: 1.73
Branch: XXX (master/viewport/docking/etc.)

OpenGL/ Visual studio 2019/

Back-ends: Custom engine

Operating System: Windows 10

I have a modal window that contains an input text field. Using the keyboard events from my custom engine, I update a char array that I linked to the the input text field. However, when I click on the input field (I guess to do focus on it), the input text field doesnt refresh from the data in my char array. If I click outside the input field (lose focus), the input refresh with the char array (check the gif below).

Any thoughts why this could be happening?

Screenshots/Video

inputtext-issue

// Here's some code anyone can copy and paste to reproduce your issue
 ImGui::OpenPopup(modal_window_name.c_str());
if (ImGui::BeginPopupModal(modal_window_name.c_str(), &m_open_modal))
{
  char* writable = new char[m_copy_name.size() + 1];
  std::copy(m_copy_name.begin(), m_copy_name.end(), writable);
  writable[m_copy_name.size()] = '\0'; // don't forget the terminating 0
   ImGui::InputText("##textcameraname", writable, IM_ARRAYSIZE(writable));
}
ImGui::EndPopup();
@Ressley
Copy link

Ressley commented Feb 25, 2022

Use static size for writable

@jokteur
Copy link

jokteur commented Feb 25, 2022

I suppose that m_copy_name is a std::string ?
In which case, you can include imgui_stdlib and directly use your std::string:

#include "misc/cpp/imgui_stdlib.h"

[...]
ImGui::InputText("##textcameraname", &m_copy_name);

@kmilo9999
Copy link
Author

I tried both suggested approaches, none of them worked :(

  • Set a static size for writable did not change the behavior.
       char writable[50];
      std::copy(m_copy_name.begin(), m_copy_name.end(), writable);
      writable[m_copy_name.size()] = '\0'; // don't forget the terminating 0
      ImGui::InputText("##textcameraname", writable, IM_ARRAYSIZE(writable));
  • Switch to misc/cpp/imgui_stdlib.h
 #include "./imgui_stdlib.h"
 ImGui::InputText("##textcameraname",&m_copy_name );

In this case, the inputtext only refresh if there's no focus on the ui element.

What could be the main root of the issue? I could debug specific parts if you can point them out.
My educated guess is, there are problems relating the active window and the on-focused element. I have code on my custom engine where the active imgui-window is the one the mouse is hovering. I dont know if that is affecting the focus properties of the InputField.

@ocornut
Copy link
Owner

ocornut commented Feb 25, 2022

InputText() owns a copy of the data when active, it won't reload text from the user arg when active.
See #3878 , #2890 , #2881 , #1506

@ocornut ocornut closed this as completed Feb 25, 2022
@kmilo9999
Copy link
Author

implementing the #3290 workaround did the trick.

ocornut added a commit that referenced this issue Feb 7, 2024
Very highly requested feature (#6962, #5219, #3290, #4627, #5054, #3878, #2881, #1506, #1216, #968).
Also useful for interactive completion/selection popups (#2057, #718)
Based on @kudaba PR. Design for Inputtext V2 should make this obsolete.
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

4 participants