18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 04:05:58 +01:00

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.
This commit is contained in:
maj00r
2026-11-08 19:26:19 +01:00
parent 22c588d8f9
commit be40008808
3 changed files with 16 additions and 1 deletions

View File

@@ -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;

View File

@@ -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)
{

View File

@@ -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 = <main_viewport>, 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')