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

Weird ImGui::InputText behavior when encapsulated inside a struct #7724

Closed
deadlocklogic opened this issue Jun 22, 2024 · 3 comments
Closed
Labels
label/id and id stack implicit identifiers, pushid(), id stack

Comments

@deadlocklogic
Copy link

deadlocklogic commented Jun 22, 2024

Version/Branch of Dear ImGui:

Version 1.90.0, Branch: docking

Back-ends:

imgui_impl_sdl2.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Windows 11 + clang

Full config/build information:

Dear ImGui 1.90.0 (19000)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=199711
define: _WIN32
define: _WIN64
define: _MSC_VER=1939
define: _MSVC_LANG=201402
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_sdl2
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000443
 NavEnableKeyboard
 NavEnableGamepad
 DockingEnable
 ViewportsEnable
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x00001C06
 HasMouseCursors
 HasSetMousePos
 PlatformHasViewports
 HasMouseHoveredViewport
 RendererHasViewports
--------------------------------
io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,64
io.DisplaySize: 1280.00,720.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00

Details:

When creating 2 text structures like below, when updating one, the other acts like a clone.

Screenshots/Video:

Screen.Recording.2024-06-23.003937.mp4

Minimal, Complete and Verifiable Example code:

Consider:

struct Text {
     Text(const std::string& label, const std::string& str) :label(label), str(str) {}

    void update() {
        ImGui::InputText(label.c_str(), &str);
    }

    std::string label;
    std::string str;
};

Initialization with:

    Text t1("", "Text1");
    Text t2("", "Text2");

And updating with:

    t1.update();
    t2.update();
@deadlocklogic
Copy link
Author

I just wanted to ask before doing any further investigations. Especially this variant of ImGui::InputText() is defined inside imgui_stblib.h.

@ocornut ocornut added the label/id and id stack implicit identifiers, pushid(), id stack label Jun 22, 2024
@ocornut
Copy link
Owner

ocornut commented Jun 22, 2024

@ocornut ocornut closed this as completed Jun 22, 2024
@deadlocklogic
Copy link
Author

Indeed, sorry my bad, I was aware of IDs but thought they are automatically managed!
Anyway thank you for you time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
label/id and id stack implicit identifiers, pushid(), id stack
Projects
None yet
Development

No branches or pull requests

2 participants