DisplaySize update on OS window resize


#1

So, i was looking in the web around this problem that i have but was not able to find a solution and i was thinking that i should not post the question on github so here we are.

As first, i’m pretty new to ImGUI Now, im creating a simple Window in C++ with windows api (RegisterClassEx & CreateWindow)
WNDCLASSEX wcex;

//Class structure
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = myWndProc_Hanlder;
wcex.hInstance = tInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(0, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = className;

Now i setup directx9 on the window and i just clear the window with some random colors and no more drawings. Setup imgui and everything works fine but my problem is when i resize my ‘SimpleWindow’ when i click on let’s say the imgui resize thing in the corner of a imgui object i can’t click on it i mean the point to resize the window still stands on the old place. Im not sure if i could explain my problem so i will post a screenshot with explanation.


IMGui windows get smaller when resizing down OS window
#2

The problem you have here is that you aren’t updating io.DisplaySize to match the current size of our OS window. As a result, even though your mouse position are passed to dear imgui in pixel coordinates (correct) the rendering projection matrix still thinks you are using the old size. So there is a mismatch between inputs and rendering.

This is also the reason the rendering looks off/bad on the second picture.

As shown in the example, you should update io.DisplaySize to match your underlying os window / rendering context size at all time.


#3

Thanks for the answer! I Was not able to find exactly what you said in the example but i got your point, if i have future problems again i will post them here of course after i did google research :slight_smile:
Oh and i think i found a little bug and reported it here: https://github.com/ocornut/imgui/issues/2041
Have a good day!


#4

what exactly is the code used to solve this? I don’t see displaySize in the samples. I set displaySize to match the OS window in my rendering loop and it does the same thing.