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

TreeNode problem #147

Closed
NePutin94 opened this issue Dec 12, 2020 · 13 comments
Closed

TreeNode problem #147

NePutin94 opened this issue Dec 12, 2020 · 13 comments

Comments

@NePutin94
Copy link

Faced with a strange problem. After I minimize my app window, the TreeNode will stop opening, although other elements (buttons, menu bar) continue to work.
Before I collapsed the window:
изображение
After:
изображение

@eliasdaler
Copy link
Contributor

eliasdaler commented Dec 13, 2020

Hello.
Can you please provide a minimal code example which reproduces the problem? Ideally it should reproduce on a window with only one TreeNode.
My first guess would be to check if this TreeNode has unique id, because widgets not responding is usually caused by label/id clash.

It would be also perfect if you try to run the code with other binding and be sure that it’s not an ImGui’s bug. Though it might be SFML or your program not catching "window activated/regained focus"

@NePutin94
Copy link
Author

Main loop:

    while(window->isOpen())
    {
        sf::Event event;
        handleEvent(event);// ImGui::SFML::ProcessEvent(event);
        ImGui::SFML::Update(*window, deltaClock.restart());
        if(ImGui::Begin("Tools Window", NULL, window_flags))
        {...}
        update();
        draw();// ImGui::SFML::Render(*window);
    }

How I use TreeNode:

  for(auto& group : groups)
  {
    ImGui::PushID(group_id);
    node_open = ImGui::TreeNodeEx((void*) (intptr_t) group_id, nd, "%s", group->getName().c_str());
    if(node_open)
    {
     for(auto& elem:group)
     {
      ImGui::PushID(elem_id);
      ImGui::Text(...)
      ImGui::PopID();
     }
     ImGui::TreePop();
    }else{...}
    ImGui::PopID();
  }

Absolutely all TreeNode stop working, even in TestWindow, which provides ImGui. I also don't handle the LostFocus and GainedFocus states in any way, could this be an error?
I started the window with only one TreeNode, the problem remained:

  while(window->isOpen())
  {
       sf::Event event;
       handleEvent(event);// ImGui::SFML::ProcessEvent(event);
       ImGui::SFML::Update(*window, deltaClock.restart());
       if(ImGui::TreeNode("adsfjklhasdkufj"))
       {
          ImGui::Text("asdasd");
          ImGui::TreePop();
       }
       draw();// ImGui::SFML::Render(*window);
  }

@NePutin94
Copy link
Author

When I launch a window without focusing on it, absolutely all ImGui elements stop working.

@eliasdaler
Copy link
Contributor

You don't need to handle it yourself, but SFML should send Gained/LostFocus events. Does it do it? Can you check it, please? Maybe it's the problem with your WM which SFML doesn't work correctly with.

I think that ideally I should remove this Gained/Lost event processing stuff, but I'm afraid most people will get confused that ImGui elements would work even if your window is not in focus (e.g. if you click on the text box, you'll be able to write in it even if the window loses focus)

@eliasdaler
Copy link
Contributor

Can you please remove all s_windowHasFocus usage in imgui-SFML.cpp and check how it works for you, please? I feel like we can do fine without this bool, but I'm not sure how ImGui will behave with out-of-focus window without it.

@NePutin94
Copy link
Author

Completely removed s_windowhasfocus now all imgui elements work even if you run the application without focusing on it (but problem in sfml because for some reason, the gainedfocus event is not created when i open the application window for the first time), problem with TreeNode remains.
I don't think TreeNode bug in my case is related to events. After minimizing the window in the ButtonBehavior function g.ActiveId set to zero and the code for checking the mouse click is not executed, but I do not know what this is related to.
I compile the project using g++ 10, tried to compile it using msvc and there the bug looks different. After minimizing the window, the TreeNode opens only by clicking on the arrow.

@eliasdaler
Copy link
Contributor

Does it reproduce when you insert the TreeNode code in the minimal example?

@NePutin94
Copy link
Author

Yes, after minimizing the window, TreeNode do not open.
I tried using the new version of imgui 1.79 (before it was 1.73) and downloaded the latest release of imgui-sfml (i also used it before). The bug remained, but now after minimizing the TreeNode windows open when you click on the arrow.
When i run the application, treenode work perfectly no matter how many times i open them, but after minimizing the window, they open only when you click on the arrow. And if you press alt, just press, then they start working again. This bug does not occur if you just focus on another window with the mouse, but if you minimize the window using Alt+Tab, this bug appears. Even if I focus on another window with the mouse, and return to the window of my application using Alt+Tab everything will be fine.

@eliasdaler
Copy link
Contributor

eliasdaler commented Mar 21, 2021

Please try latest version of ImGui-SFML with ImGui 1.82
I'm using this code for testing and it works well (on Ubuntu 20.04 and Windows 10):

#include <SFML/Graphics/CircleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/Window/Event.hpp>

#include "imgui-SFML.h"
#include "imgui.h"

int main() {
    sf::RenderWindow window(sf::VideoMode(640, 480), "ImGui + SFML = <3");
    window.setFramerateLimit(60);
    ImGui::SFML::Init(window);

    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    sf::Clock deltaClock;
    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            ImGui::SFML::ProcessEvent(event);

            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }

        ImGui::SFML::Update(window, deltaClock.restart());

        ImGui::Begin("Hello, world!");
        ImGui::Button("Look at this pretty button");
        if (ImGui::TreeNode("adsfjklhasdkufj")) {
            ImGui::Text("asdasd");
            ImGui::TreePop();
        }
        ImGui::End();

        ImGui::ShowDemoWindow();

        window.clear();
        window.draw(shape);
        ImGui::SFML::Render(window);
        window.display();
    }

    ImGui::SFML::Shutdown();

    return 0;
}

@NePutin94
Copy link
Author

Personally, I still have a problem :). As I understand it, after minimizing the window (alt+tab), an event about the alt key being pressed comes from sfml, but the event that alt was released does not come. And imgui thinks that the alt key is pressed and the interface works differently, for example, treenode will open only when you click on the arrow. Maybe I have some problem with my system.

@eliasdaler
Copy link
Contributor

Oh, so it looks like it's related #88... Okay, I see, I'll try to fix that one first.
You said "minimized", so I clicked on "_" button and didn't think that you mean alt-tabbing.

@eliasdaler
Copy link
Contributor

Okay, I can confirm that Alt+Tab breaks things. When the window is out of focus, SFML doesn't catch any key input events, so the only way to fix it is to poll keyboard events.
Doing this fixes the problem, but introduces some other ones... I'm working on it!

@eliasdaler
Copy link
Contributor

Fixed. Should work now. The problem is described in the commit message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants