Search code examples
c++sfmlimgui

How to relate to button created in SFML-IMGUI?


Hello I want to create some buttons with SFML-IMGUI and after that relate to them in some way for example to change text. How can I do this? I dont see any ID attribute. I create button using this code.

ImGui::Begin("Button");
Button("Click me");
End();

I dont see any example in documentation :/


Solution

  • Imgui buttons don't use any id or callbacks. Instead, the ImGui::Button("Clikc me") will return a boolean which is true if the button was clicked. (here is an example)

    ImGui::Begin("window");
    
    if (ImGui::Button("Click me")) {
        // onButtonClick();
    }
    
    ImGui::End();
    

    for more read https://github.com/ocornut/imgui/tree/master/docs and seeimgui_demo.cpp it has some better examples on how to use it.