New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImGui::GetWindowSize() on tooltip window giving strange sizes #175
Comments
Well would depend entirely on what's in the actual tooltips. Can you post some code that fails? (Btw- clamping tooltip within the display area could/should be done by ImGui. I had some code doing that in a local branch, need to decide on the settings.) |
Fiddling some more, I think this here is probably the root of my woes, though I don't know why the behaviour would have changed recently: Here's odd example #1: ImGui::BeginTooltip();
ImGui::Text("foo bar baz");
ImVec2 last_tooltip_size = ImGui::GetWindowSize();
ImGui::EndTooltip();
fprintf(stderr, "LTTS: %f x %f\n", last_tooltip_size.x, last_tooltip_size.y); The first time around this will return a window size of 8x4. Subsequent times around it will return the (probably) correct size of 103x29. Now a tweaked version, example #2: ImGui::SetNextWindowPos(ImVec2(100.0f, 100.0f));
ImGui::BeginTooltip();
ImGui::Text("foo bar baz");
ImVec2 last_tooltip_size = ImGui::GetWindowSize();
ImGui::EndTooltip();
fprintf(stderr, "LTTS: %f x %f\n", last_tooltip_size.x, last_tooltip_size.y); Note the |
(I agree that ImGui should/could be doing smarter tooltip positioning, I merely figured I could prototype it at the app level and submit it if it became clean enough.) |
Maybe have side-effects on window contents? Unsure at this point.
Sorry referring to wrong issue number. The commit above is for #176 |
Example #3 - I think the SetNextWindowPos() complicates matters, and this may be a different issue to the issue of the initial dimensions being wrong. ImVec2 cursor_pos = ImGui::GetIO().MousePos;
ImVec2 tooltip_offset(50.0f, 50.0f);
ImVec2 tooltip_position = cursor_pos;
tooltip_position.x += tooltip_offset.x;
tooltip_position.y += tooltip_offset.y;
ImGui::SetNextWindowPos(tooltip_position);
ImGui::BeginTooltip();
ImGui::Text("foo bar baz");
ImVec2 last_tooltip_size = ImGui::GetWindowSize();
ImGui::EndTooltip();
fprintf(stderr, "LTTS: %f x %f\n", last_tooltip_size.x, last_tooltip_size.y); The result is sometimes 103.000000 x 29.000000, sometimes 105.000000 x 30.000000, and so on. |
I fixed a bug where they would be definitively wrong on the first frame, so at least they shouldn't be negative. But ImGui::GetWindowSize() gives you the size of the window at time of the first Begin() of the frame, otherwise it would vary depending on when you call it. |
I'm on it ! Fix soon. |
Fixed the bugs! |
Thanks, 5737a79 + 072c57b totally fixes the app tooltip wrapper. :) Woo! I wasn't aware that GetWindowSize() gives you the size of the window at the time of the first Begin(); I was expecting that it varies depending on when you call it. But the current behaviour is fine with me anyway, now that I know what that is supposed to be. :) Thanks! |
I could add a window to return "window->DC.CursorMaxPos - window->Pos", that would be the window extents at the time of the call (the "current" size). |
That was what I thought the call was doing, but I don't have a use where I really really need it to behave like that - better to keep it simpler and document it more explicitly, perhaps. |
FYI I reorganised the Begin() functions which was full of traps (subtle ordering dependencies). It should be better and healthier now but there is the possibility that I've created bugs or changes of behavior related to window size. Let me know if you notice anything unusual. The changes are spread over many commits ending with this |
I'm using the following code as wrappers to
ImGui::BeginTooltip()
andImGui::EndTooltip()
to make sure that tooltips always remain on-screen and unobscured by the mouse cursor.This worked well until a few revisions ago (probably a change yesterday).
Now
ImGui::GetWindowSize()
is returning several different sizes for even the simplest single-line-of-text tooltips, causing the tooltip to wobble around. This also occurs when the tooltip isn't near the screen edges, where both X and Y sizes will still appear to vary by several pixels as the cursor is wiggled.On fairly complex tooltips, the returned sizes can even be negative!
The text was updated successfully, but these errors were encountered: