click on Inputtext no refreshing text #5054

Closed
opened 2022-02-24 23:11:59 +00:00 by kmilo9999 · 5 comments
kmilo9999 commented 2022-02-24 23:11:59 +00:00 (Migrated from github.com)

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();
**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](https://user-images.githubusercontent.com/16551165/155621142-cca29cfc-888a-463f-8625-a9e05b6d1a02.gif) ``` // 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 commented 2022-02-25 09:36:25 +00:00 (Migrated from github.com)

Use static size for writable

Use static size for writable
jokteur commented 2022-02-25 10:10:26 +00:00 (Migrated from github.com)

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);
I suppose that `m_copy_name` is a `std::string` ? In which case, you can include [imgui_stdlib](https://github.com/ocornut/imgui/blob/master/misc/cpp/imgui_stdlib.h) and directly use your std::string: ```cpp #include "misc/cpp/imgui_stdlib.h" [...] ImGui::InputText("##textcameraname", &m_copy_name); ```
kmilo9999 commented 2022-02-25 15:45:12 +00:00 (Migrated from github.com)

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.

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 commented 2022-02-25 15:55:28 +00:00 (Migrated from github.com)

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

`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
kmilo9999 commented 2022-02-25 16:07:07 +00:00 (Migrated from github.com)

implementing the #3290 workaround did the trick.

implementing the #3290 workaround did the trick.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ocornut/imgui#5054
No description provided.