Viewports, SDL3: Fix secondary viewports uncollapse incorrect sizing - #9529
Open
SuperRonan wants to merge 1 commit into
Open
Viewports, SDL3: Fix secondary viewports uncollapse incorrect sizing#9529SuperRonan wants to merge 1 commit into
SuperRonan wants to merge 1 commit into
Conversation
- Fixes incorrect reduced size when un-collapsing window in secondary viewport - SImilar to ocornut#2756
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The same issue as #2756 is manifesting for me with SDL3 (on Windows 11).

When uncollapsing a window in a secondary viewport, its size (more precisely its height) is not properly restored.
Problem detail:
Although the problem appears to happen when uncollapsing the window in a secondary viewport, its actual origin happens when collapsing in a secondary viewport.
Note that the wrongly restored height (32px) is not the same as the collapsed height (19px).
This is due to a chain of event between ImGui's and SDL3 when collapsing:
ImGui_ImplSDL3_SetWindowSize(viewport, collapsed_size (h = 19))is called, which adds anSDL_EVENT_WINDOW_RESIZEDto SDL3's event queue.SDL_EVENT_WINDOW_RESIZEDmentionned above is processed (with the same resolution as above (collapsed size)) ->viewport->PlatformRequestResizeis set totrue(inImGui_ImplSDL3_ProcessEvent(),case SDL_EVENT_WINDOW_RESIZED:)ImGui::UpdateViewportsNewFrame(),viewport->PlatformRequestResizeis treated as if the viewport was manually resized (to the collapsed size), windows attached to the viewport are set with.Size = collapsed_size(h = 19)ImGui::Begin()of the window,window->SizeFull = CalcWindowSizeAfterConstraint(window, window->SizeFull);, which setswindow.SizeFull.y = 32;(fromg.Style.WindowMinSize.y).window->SizeFull, which was "corrupted" by the previous events.Fix:
The issue comes from step [2].
#2756 Proposed to keep a frame index when
ImGui_ImplGlfw_SetWindowSize()is called, and ignore the next resize event during the next frame, but I don't think it is the best solution.The
SDL_EVENT_WINDOW_RESIZEDevent triggered bySDL_SetWindowSize()might provide some useful data according to the SDL3 doc:Here I am proposing to 'accept' the event only if it is relevent: its resized resolution is different from viewport's current one. It is important to set
viewport->PlatformRequestResize = true;if the resolution is not the same.About SDL2:
Surprisingly, this issue does not arise with SDL2!
The difference is that SDL2's
SDL_SetWindowSize()triggers aSDL_WINDOWEVENT_SIZE_CHANGEDinstead of aSDL_WINDOWEVENT_RESIZED, andImGui_ImplSDL2_ProcessEvent()only processes the latter.SDL3 did replace
SDL_WINDOWEVENT_SIZE_CHANGEDbySDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED, but I don't know why it is not triggered by SDL3'sSDL_SetWindowSize()instead ofSDL_WINDOWEVENT_RESIZED...Moving viewports:
A similar behaviour happens when moving a window with
ImGui_ImplSDL3_SetWindowPos()which triggers aSDL_EVENT_WINDOW_MOVED(the SDL3 backend thinks the window was moved during the next frame). So it might be worth adding a similar check before settingviewport->PlatformRequestMove = true;.I haven't had any issue with this yet (maybe it could trigger with
SetWindowPosVal/SetWindowPosPivot?).One more case:
Maybe
window->SizeFull = CalcWindowSizeAfterConstraint(window, window->SizeFull);should not apply to the collapsed axis (.yin our case, but it could be.xif we were to have side collapsing) if the window is collapsed.This case could arise if the windowing system were to return a different resolution with the
SDL_WINDOWEVENT_RESIZEDthan the one requested bySDL_SetWindowSize(), thenviewport->PlatformRequestResizewould be set and nothing could prevent a wrong height from being restored when uncollapsing.