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

resizing window #28

Closed dcnieho closed 1 year ago

dcnieho commented 1 year ago

I have a window whose size i only know later, not on the first or the second frame. I need some advice how to deal with this with hello_imgui using Python. My window is real simple, it just has an image (imgui.image()) to show. I have the following questions:

  1. How to size my window such that is has the size of the image, taking into account DPI scaling of the monitor? I think that app_window_params.window_geometry.window_size_measure_mode = hello_imgui.WindowSizeMeasureMode.relative_to96_ppi is key here, right?
  2. How to only size the window once its size is know? The first image to show may arrive seconds after the window has been created. I tried hiding the window (glfw.hide_window) in post_init and only showing it once the image is about to be drawn for the first time. Can i invoke the sizing (and positioning) logic at a later time instead of only at window creation?`
  3. Ideally i'd like the logic to scale the window to 100% image size if that fits on the monitor, else to clamp the window size down to the monitor size while maintaining aspect ratio. Is that possible?
pthom commented 1 year ago

Hi Dee,Those are interesting  subjects on which I worked a lot.I would be interested in seeing that on your computer, since it is a windows PC. Could we try to have a telephone conversation at 2 PM?

dcnieho commented 1 year ago

I'm not available today but would be happy to talk to you tomorrow between 10 and 15

On Mon, Jan 23, 2023 at 12:01 PM Pascal Thomet @.***> wrote:

Hi Dee,Those are interesting subjects on which I worked a lot.I would be interested in seeing that on your computer, since it is a windows PC. Could we try to have a telephone conversation at 2 PM?Thanks Le 23 janv. 2023 à 10:46, Diederick C. Niehorster @.***> a écrit : I have a window whose size i only know later, not on the first or the second frame. I need some advice how to deal with this with hello_imgui using Python. My window is real simple, it just has an image (imgui.image()) to show. I have the following questions:

How to size my window such that is has the size of the image, taking into account DPI scaling of the monitor? I think that app_window_params.window_geometry.window_size_measure_mode = hello_imgui.WindowSizeMeasureMode.relative_to96_ppi is key here, right? How to only size the window once its size is know? The first image to show may arrive seconds after the window has been created. I tried hiding the window (glfw.hide_window) in post_init and only showing it once the image is about to be drawn for the first time. Can i invoke the sizing (and positioning) logic at a later time instead of only at window creation?` Ideally i'd like the logic to scale the window to 100% image size if that fits on the monitor, else to clamp the window size down to the monitor size while maintaining aspect ratio. Is that possible?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/pthom/hello_imgui/issues/28#issuecomment-1400159067, or unsubscribe https://github.com/notifications/unsubscribe-auth/AANUOGJO3BBKNHOUFCKGQWTWTZQJ7ANCNFSM6AAAAAAUDT4RYU . You are receiving this because you authored the thread.Message ID: @.***>

pthom commented 1 year ago

Handling window size is a hard problem, since it is handled differently depending on the OS, on the backend; and ImGui does not have a fixed policy about it.

There was an issue in the autosize logic on win32 high DPI:

See https://github.com/pthom/hello_imgui/commit/801bc404b855f0860e59a7012d0db9d79e3ee054

Concerning the possibility to automatically size the window later, I added this possibility:

HelloImGui::GetRunnerParams()->appWindowParams.windowGeometry.resizeAppWindowAtNextFrame = true;

https://github.com/pthom/hello_imgui/blob/master/src/hello_imgui/hello_imgui_api.md#windowgeometry

Let's try to talk tomorrow at 10:30AM.

(and I hope this will be enough on the sizing front, since this subject is as complex and tricky as a fancy Swiss clock)

dcnieho commented 1 year ago

That did the trick, thanks!