inkyblackness / imgui-go

Go wrapper library for "Dear ImGui" (https://github.com/ocornut/imgui)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IO.SetDisplaySize doesn't work?

AllenDang opened this issue · comments

Hi,
This might not be an issue but a discussion. :P
I noticed that GLFW v3.3 just add a callback "SetSizeCallBack" which will be called when window's size is changed.
So I tried to implement a live-resize of all imgui widgets.

In PlatformGlfw, I add the call back like below and fmt.Println(width, height) shows it works fine.

func (platform *GLFW) installCallbacks() {
	platform.window.SetMouseButtonCallback(platform.mouseButtonChange)
	platform.window.SetScrollCallback(platform.mouseScrollChange)
	platform.window.SetKeyCallback(platform.keyChange)
	platform.window.SetCharCallback(platform.charChange)
	platform.window.SetSizeCallback(platform.sizeChange)
}
func (platform *GLFW) sizeChange(window *glfw.Window, width, height int) {
	platform.imguiIO.SetDisplaySize(Vec2{X: float32(width), Y: float32(height)})
}

But during outer window resizing, imgui doesn't update. Am I missing something to make it work?

I noticed that render process seems to be paused during master window's resize...

Hello @AllenDang - thank you for your message!

I am not entirely sure what you want to achieve. Do you want to make the new space (after making the window bigger) available for further display? What happens currently (without this SetDisplaySize()) when you resize the window?

To be sure, did you have a look at the imgui-go-examples , where resizing is handled by the existing functions (both GLFW and SDL)?
There, in both the SDL and GLFW platform implementations of NewFrame(), right at the start, they notify the current display size to IO. And in tandem, both the OpenGL renderer take the current display size into account to recalculate the viewport and projection. Search for the calls to GLFS.DisplaySize() and follow to where the return values are used.

Since the render loop a single-threaded process, there is no point in installing the size change callback, as there's nothing to be gained to "immediately" react to it. The render loop (of the example) retrieves the current window size at each beginning of rendering a new frame to be current.
The callback event is not needed/doesn't give any new benefit.

@dertseha
I got it done! The major problem is glfw will not send resize event to glfw.PollEvents, so the message loop will not respond to main window resize. But the glfw.Window.SetSizeCallback will still be called during resize.

So, I make a callback to my MasterWindow and call NewFrame()...Render() stuff there, and it works.

Now the problem is during resize, the content seems a litter blurring, not smooth enough.

@dertseha
Aha! It turns out I accidentally registered two size change callbacks, one for sizechange, another for framebuffersizechange, which causes the blurring.
Now it works like a charm!
Thanks for your reply!