pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
606 stars 91 forks source link

creating hidden window #29

Closed dcnieho closed 1 year ago

dcnieho commented 1 year ago

I'd like to create a window that is initially hidden, i will only show it later. right now it flashes up before i get a chance to call glfw.hide_window(self._glfw_window) in the post_init callback. I tried:

glfw.window_hint(glfw.VISIBLE, False)
immapp.run(params)

but it makes sense that wouldn't work since glfw isn't even initialized at this point, correct?

Is it possible to make a window that is initially hidden?

pthom commented 1 year ago

Is it possible to make a window that is initially hidden?

... No. But you may want to look at internal/backend_impls/backend_window_helper/glfw_window_helper.cpp and see if you can make an adaptation :-)

dcnieho commented 1 year ago

something like this, with corresponding changes to the app parameters, should do the trick:

diff --git a/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp b/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp
index 09590aa..4ecaa2c 100644
--- a/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp
+++ b/src/hello_imgui/internal/backend_impls/backend_window_helper/glfw_window_helper.cpp
@@ -81,6 +81,11 @@ namespace HelloImGui { namespace BackendApi
         else
             glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

+        if (appWindowParams.hidden)
+            glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
+        else
+            glfwWindowHint(GLFW_VISIBLE, GLFW_TRUE);
+

         // GLFW_SCALE_TO_MONITOR is set to false: we set manually the window size in screen coordinates,
         // then AbstractRunner::MakeWindowSizeRelativeTo96Ppi_IfRequired() may resize the window at the second frame

Does that look ok to you? Should i explore that further?

dcnieho commented 1 year ago

That or an extra entry Hidden in enum class WindowSizeState. maybe thats more logical actually

dcnieho commented 1 year ago

tell me what you prefer and i'll try an implementation

pthom commented 1 year ago

I do not know yet what is the best possible location, between WindowSizeState or a hidden flag.

I will need to think about it in more details, but of course your help would be appreciated. Any change needs to be validated with glfw &sdl, on the different OS (windows, mac, linux, etc.); which makes this a bit complex (but I would handle the porting part ;-)

By the way: would using WindowSizeState.minimized be sufficient for you? Beware, it might be broken; this is yet another corner case that I did not explore intensively.

dcnieho commented 1 year ago

I understand that gets hairy. glfw at least just supports it, and if it then doesn't work on a platform thats kinda not your problem.

When setting params.app_window_params.window_geometry.window_size_state = hello_imgui.WindowSizeState.minimized, the window still flashes briefly when its created. Furthermore, later doing hello_imgui.get_runner_params().app_window_params.window_geometry.window_size_state = hello_imgui.WindowSizeState.standard does nothing, so i can't unminimize it. And the autosize we discussed today doesn't work when in minimized state :p

pthom commented 1 year ago

After studying this, I think that WindowSizeState is not the appropriate place, and that a better solution would be either to add AppWindowParams::initiallyHidden (if taken into account only at startup), or AppWindowParams::hidden (if this is taken into account dynamically).

pthom commented 1 year ago

Hi,

Since this was also asked in https://github.com/pthom/hello_imgui/issues/41, I implemented a solution in https://github.com/pthom/hello_imgui/commit/d6af807aebc3cf9d87b2a3547402647f475b1054

dcnieho commented 1 year ago

Super, that should do the trick for me! Will test in the next week or so (let me know if you make a pypi release, that makes testing much quicker ;) )

dcnieho commented 1 year ago

Tested with 0.8.5: works!