imgui: Scroll.y too large when shrinking child window. Possible solution(s) included.

Greetings!

When shrinking a child window, the child window’s “window->Scroll.y” becomes “ItemSpacing.y” too large.

This is because of line 3752 (imgui.cpp, master branch - I’ve looked at commit 26be151 which is the current one when writing this) where window->SizeContents.y gets calculated like so: (window->DC.CursorMaxPos.y - window->Pos.y) + window->Scroll.y;

However, “CursorMaxPos.y” will always be “style.ItemSpacing.y” bigger than it should, probably due to ImGui::ItemSize adding “ItemSpacing.y” to “CursorPos”, resulting in an extra ItemSpacing.y at the very end.

One possible solution, although somewhat contrived would be to changing the line 3752 to:

window->SizeContents.y = (float)(int)((window->SizeContentsExplicit.y != 0.0f) ? window->SizeContentsExplicit.y : ((window_is_new ? 0.0f : window->DC.CursorMaxPos.y - style.ItemSpacing.y - window->Pos.y) + window->Scroll.y));

Another, possibly better solution would probably be to just subtract ItemSpacing.y from CursorMaxPos.y inside “ImGui::End”. (I went for the latter locally)

Note: The problem doesn’t show itself if I resize while hovering the scrollbar. I haven’t looked closer as to why, but my guess would be that “CursorMaxPos.y” gets updated to not include the itemspacing.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 27 (15 by maintainers)

Most upvoted comments

@ocornut feel free to close this “bug”. (which most likely was due to windowpadding anyway like you say). It’s a non-issue for me after a rewrite anyway 😃