SFML / imgui-sfml

Dear ImGui backend for use with SFML
MIT License
1.13k stars 169 forks source link

Missing support for new events in ImGui v1.87 #196

Closed oprypin closed 2 years ago

oprypin commented 2 years ago

Dear ImGui v1.87 has expanded its support for keyboard and gamepad buttons, and replaced the interface for backends to report the keys. The old way keeps working OK but is deprecated and has big limitations, thus already making "imgui-demo" run with some missing functionality when it's run through "imgui-sfml".


Code such as ImGui::IsKeyDown(ImGuiKey_Q) is supposed to work for backends that are up to date with ImGui v1.87, but imgui-sfml never reports to ImGui that that key was pressed, because in the past the set of available keys was limited:

https://github.com/eliasdaler/imgui-sfml/blob/4129d276d45845581b6ba99ede50db6f761e5089/imgui-SFML.cpp#L284-L291


Here you can observe the missing events: One can just run the default "imgui-demo" and in the current state of imgui-sfml it is missing a lot of information in the "Keyboard, Gamepad & Navigation State".

current behavior expected behavior
https://user-images.githubusercontent.com/371383/158024702-86a606c2-aea7-4718-a494-6e5ec8b06510.mp4 https://user-images.githubusercontent.com/371383/158024705-83840c9a-26ad-41ad-86a5-073bf89f51fd.mp4

How I was running this:

diff --git a/examples/minimal/main.cpp b/examples/minimal/main.cpp
index 2c19abd08..e0561a94b 100644
--- a/examples/minimal/main.cpp
+++ b/examples/minimal/main.cpp
@@ -12,6 +12,10 @@ int main() {
     window.setFramerateLimit(60);
     ImGui::SFML::Init(window);

+    ImGuiIO& io = ImGui::GetIO();
+    io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
+    io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
+
     sf::CircleShape shape(100.f);
     shape.setFillColor(sf::Color::Green);

c++ -I. -I./imgui examples/minimal/main.cpp imgui-SFML.cpp ./imgui/{imgui_demo.cpp,imgui_widgets.cpp,imgui.cpp,imgui_draw.cpp,imgui_tables.cpp} -lsfml-graphics -lsfml-window -lsfml-system -lGL && ./a.out

And here's how I was running with ImGui's own SDL backend, to be able to compare: c++ -I. -Ibackends -I/usr/include/SDL2 -lSDL2 -lGL examples/example_sdl_opengl3/main.cpp backends/imgui_impl_opengl3.cpp backends/imgui_impl_sdl.cpp imgui_demo.cpp imgui_widgets.cpp imgui.cpp imgui_draw.cpp imgui_tables.cpp && ./a.out