From be40008808c7e5e5557468422b59e857a0d0d505 Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 8 Nov 2026 19:26:19 +0100 Subject: [PATCH 1/2] fix(ui): tooltips and popups stay in the main window, and a long tooltip wraps With the panels in separate windows on (the default), a tooltip or a popup that didn't fit in the main window got a window of the system of its own, with an OpenGL context of its own. The editor froze so on 2026-11-08: its main thread stuck for good in the NVIDIA driver while making the context of an invisible window 1925 x 29 px, a tooltip in one line wider than the screen. The Polish texts of the editor have tooltips of up to 360 characters in a line; the one of the curve mode of laying track is 2088 px wide. - io.ConfigViewportsNoAutoDetach (a MaSzyna addition, set with the separate windows) keeps the tooltips and popups shown over the main window inside it too, placed and shrunk as they are without the separate windows: they get no viewport of their own. A panel dragged out of the main window by hand still gets its window, and the tooltips and popups over it may go past its edge as before. - io.ConfigTooltipsWrapWidth (a MaSzyna addition): SetTooltip() wraps its text at this width. The ui sets 40 em, 520 px at the font of 13 px. Checked in the editor on a hidden desktop: the tooltip of the curve mode, full screen 1920 x 1080, and the one of the redo button at the edge of a window 1280 x 720 each made a window of their own before, and none now. Both are drawn in the main window, the long one in five lines. --- application/uilayer.cpp | 2 ++ imgui/imgui.cpp | 12 ++++++++++++ imgui/imgui.h | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/application/uilayer.cpp b/application/uilayer.cpp index 5443d158c..1b4962e16 100644 --- a/application/uilayer.cpp +++ b/application/uilayer.cpp @@ -404,6 +404,8 @@ bool ui_layer::init(GLFWwindow *Window) if (!gamepadui) gamepadui = ""; auto const viewportsupport{(m_imguiio->BackendFlags & ImGuiBackendFlags_PlatformHasViewports) && (m_imguiio->BackendFlags & ImGuiBackendFlags_RendererHasViewports) && glfwGetPlatform() != GLFW_PLATFORM_WAYLAND && std::string_view{desktop} != "gamescope" && std::string_view{gamepadui} != "1"}; + // a tooltip as long as a paragraph is wrapped: in one line it can run past the screen + m_imguiio->ConfigTooltipsWrapWidth = std::round(Global.ui_fontsize * 40.0f); if (Global.ui_viewports && viewportsupport) { m_imguiio->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; diff --git a/imgui/imgui.cpp b/imgui/imgui.cpp index a9026b408..190f89012 100644 --- a/imgui/imgui.cpp +++ b/imgui/imgui.cpp @@ -1491,6 +1491,7 @@ ImGuiIO::ImGuiIO() ConfigViewportsNoDecoration = true; ConfigViewportsNoDefaultParent = false; ConfigViewportsNoAutoDetach = false; + ConfigTooltipsWrapWidth = 0.0f; // Miscellaneous options MouseDrawCursor = false; @@ -12112,7 +12113,14 @@ void ImGui::SetTooltipV(const char* fmt, va_list args) { if (!BeginTooltipEx(ImGuiTooltipFlags_OverridePrevious, ImGuiWindowFlags_None)) return; + // MaSzyna addition: see io.ConfigTooltipsWrapWidth + ImGuiContext& g = *GImGui; + const bool wrap = g.IO.ConfigTooltipsWrapWidth > 0.0f; + if (wrap) + PushTextWrapPos(GetCursorPosX() + g.IO.ConfigTooltipsWrapWidth); TextV(fmt, args); + if (wrap) + PopTextWrapPos(); EndTooltip(); } @@ -16393,6 +16401,10 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window) window->ViewportAllowPlatformMonitorExtend = FindPlatformMonitorForPos((use_mouse_ref && mouse_valid) ? mouse_ref : NavCalcPreferredRefPos()); else window->ViewportAllowPlatformMonitorExtend = window->Viewport->PlatformMonitor; + // MaSzyna addition: see io.ConfigViewportsNoAutoDetach. Over the main viewport they stay inside it: the late creation of a + // viewport in Begin() needs the extent of the monitor + if (g.IO.ConfigViewportsNoAutoDetach && window->Viewport == main_viewport) + window->ViewportAllowPlatformMonitorExtend = -1; } else if (window->Viewport && window != window->Viewport->Window && window->Viewport->Window && !(flags & ImGuiWindowFlags_ChildWindow) && window->DockNode == NULL) { diff --git a/imgui/imgui.h b/imgui/imgui.h index 6bbc42dec..85f50b79a 100644 --- a/imgui/imgui.h +++ b/imgui/imgui.h @@ -2360,7 +2360,8 @@ struct ImGuiIO bool ConfigViewportsNoTaskBarIcon; // = false // Disable default OS task bar icon flag for secondary viewports. When a viewport doesn't want a task bar icon, ImGuiViewportFlags_NoTaskBarIcon will be set on it. bool ConfigViewportsNoDecoration; // = true // Disable default OS window decoration flag for secondary viewports. When a viewport doesn't want window decorations, ImGuiViewportFlags_NoDecoration will be set on it. Enabling decoration can create subsequent issues at OS levels (e.g. minimum window size). bool ConfigViewportsNoDefaultParent; // = false // Disable default OS parenting to main viewport for secondary viewports. By default, viewports are marked with ParentViewportId = , expecting the platform backend to setup a parent/child relationship between the OS windows (some backend may ignore this). Set to true if you want the default to be 0, then all viewports will be top-level OS windows. - bool ConfigViewportsNoAutoDetach; // = false // MaSzyna addition: a floating window stays inside its host viewport: a resize stops at its edge, and a window left past it, or too big for it, is moved and shrunk to fit. It gets a viewport of its own only when dragged with the mouse cursor past the host viewport. Popups and tooltips are not affected. + bool ConfigViewportsNoAutoDetach; // = false // MaSzyna addition: a floating window stays inside its host viewport: a resize stops at its edge, and a window left past it, or too big for it, is moved and shrunk to fit. It gets a viewport of its own only when dragged with the mouse cursor past the host viewport. Tooltips and popups shown over the main viewport stay inside it too, moved and shrunk to fit, with no viewport of their own. + float ConfigTooltipsWrapWidth; // = 0.0f // MaSzyna addition: the text of SetTooltip() wraps at this width, in pixels; 0: it doesn't wrap. // Miscellaneous options // (you can visualize and interact with all options in 'Demo->Configuration') From d0ca44cd6751bbfcbc13bdb45ef09dc04d2672a7 Mon Sep 17 00:00:00 2001 From: maj00r Date: Sun, 8 Nov 2026 19:58:48 +0100 Subject: [PATCH 2/2] fix(ui): a popup begun outside any window stays in the main window too A popup begun outside any window, as the context menus of the editor, the dialogs for a new scenery and for opening one and the pause dialog of the driver are, takes no viewport from a parent. It was put into the main window only where it merged there: with the main window minimized, or behind a panel taken out into a window of its own, it got a window of the system of its own, with an OpenGL context of its own, the way the editor froze. With io.ConfigViewportsNoAutoDetach the tooltips and popups stay in the main window there too. The comment of io.ConfigViewportsNoAutoDetach tells how they're placed: as with the viewports off, not shrunk. io.ConfigTooltipsWrapWidth moves to the miscellaneous options, it works with the viewports off as well, and its comment tells that SetItemTooltip() wraps too and BeginTooltip() doesn't. --- imgui/imgui.cpp | 6 ++++-- imgui/imgui.h | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/imgui/imgui.cpp b/imgui/imgui.cpp index 190f89012..2579bf4d6 100644 --- a/imgui/imgui.cpp +++ b/imgui/imgui.cpp @@ -1491,7 +1491,6 @@ ImGuiIO::ImGuiIO() ConfigViewportsNoDecoration = true; ConfigViewportsNoDefaultParent = false; ConfigViewportsNoAutoDetach = false; - ConfigTooltipsWrapWidth = 0.0f; // Miscellaneous options MouseDrawCursor = false; @@ -1509,6 +1508,7 @@ ImGuiIO::ImGuiIO() ConfigWindowsCopyContentsWithCtrlC = false; ConfigScrollbarScrollByPage = true; ConfigMemoryCompactTimer = 60.0f; + ConfigTooltipsWrapWidth = 0.0f; ConfigDebugIsDebuggerPresent = false; ConfigDebugHighlightIdConflicts = true; ConfigDebugHighlightIdConflictsShowItemPicker = true; @@ -16383,9 +16383,11 @@ static void ImGui::WindowSelectViewport(ImGuiWindow* window) } // Fallback: merge in default viewport if z-order matches, otherwise create a new viewport + // MaSzyna addition: with io.ConfigViewportsNoAutoDetach the tooltips and popups stay in the main viewport here too if (window->Viewport == NULL) if (!UpdateTryMergeWindowIntoHostViewport(window, main_viewport)) - window->Viewport = WindowStaysInHostViewport(window, main_viewport) ? main_viewport : AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None); + window->Viewport = (WindowStaysInHostViewport(window, main_viewport) || (g.IO.ConfigViewportsNoAutoDetach && (flags & (ImGuiWindowFlags_Popup | ImGuiWindowFlags_Tooltip)))) + ? main_viewport : AddUpdateViewport(window, window->ID, window->Pos, window->Size, ImGuiViewportFlags_None); // Mark window as allowed to protrude outside of its viewport and into the current monitor if (!lock_viewport) diff --git a/imgui/imgui.h b/imgui/imgui.h index 85f50b79a..6988a0127 100644 --- a/imgui/imgui.h +++ b/imgui/imgui.h @@ -2360,8 +2360,7 @@ struct ImGuiIO bool ConfigViewportsNoTaskBarIcon; // = false // Disable default OS task bar icon flag for secondary viewports. When a viewport doesn't want a task bar icon, ImGuiViewportFlags_NoTaskBarIcon will be set on it. bool ConfigViewportsNoDecoration; // = true // Disable default OS window decoration flag for secondary viewports. When a viewport doesn't want window decorations, ImGuiViewportFlags_NoDecoration will be set on it. Enabling decoration can create subsequent issues at OS levels (e.g. minimum window size). bool ConfigViewportsNoDefaultParent; // = false // Disable default OS parenting to main viewport for secondary viewports. By default, viewports are marked with ParentViewportId = , expecting the platform backend to setup a parent/child relationship between the OS windows (some backend may ignore this). Set to true if you want the default to be 0, then all viewports will be top-level OS windows. - bool ConfigViewportsNoAutoDetach; // = false // MaSzyna addition: a floating window stays inside its host viewport: a resize stops at its edge, and a window left past it, or too big for it, is moved and shrunk to fit. It gets a viewport of its own only when dragged with the mouse cursor past the host viewport. Tooltips and popups shown over the main viewport stay inside it too, moved and shrunk to fit, with no viewport of their own. - float ConfigTooltipsWrapWidth; // = 0.0f // MaSzyna addition: the text of SetTooltip() wraps at this width, in pixels; 0: it doesn't wrap. + bool ConfigViewportsNoAutoDetach; // = false // MaSzyna addition: a floating window stays inside its host viewport: a resize stops at its edge, and a window left past it, or too big for it, is moved and shrunk to fit. It gets a viewport of its own only when dragged with the mouse cursor past the host viewport. Tooltips and popups shown over the main viewport, or begun outside any window, get no viewport of their own either: they are placed inside the main viewport as with the viewports off. // Miscellaneous options // (you can visualize and interact with all options in 'Demo->Configuration') @@ -2376,6 +2375,7 @@ struct ImGuiIO bool ConfigWindowsCopyContentsWithCtrlC; // = false // [EXPERIMENTAL] CTRL+C copy the contents of focused window into the clipboard. Experimental because: (1) has known issues with nested Begin/End pairs (2) text output quality varies (3) text output is in submission order rather than spatial order. bool ConfigScrollbarScrollByPage; // = true // Enable scrolling page by page when clicking outside the scrollbar grab. When disabled, always scroll to clicked location. When enabled, Shift+Click scrolls to clicked location. float ConfigMemoryCompactTimer; // = 60.0f // Timer (in seconds) to free transient windows/tables memory buffers when unused. Set to -1.0f to disable. + float ConfigTooltipsWrapWidth; // = 0.0f // MaSzyna addition: the text of SetTooltip() and SetItemTooltip() wraps at this width, in pixels; 0: it doesn't wrap. BeginTooltip() is not affected. // Inputs Behaviors // (other variables, ones which are expected to be tweaked within UI code, are exposed in ImGuiStyle)