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

Merge pull request #299 from MaSzyna-EU07/fix/ui-tooltips-stay-in-window

fix(ui): tooltips and popups stay in the main window, and a long tooltip wraps
This commit is contained in:
2026-11-09 12:46:56 +00:00
committed by GitHub
3 changed files with 19 additions and 2 deletions

View File

@@ -409,6 +409,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

@@ -1508,6 +1508,7 @@ ImGuiIO::ImGuiIO()
ConfigWindowsCopyContentsWithCtrlC = false;
ConfigScrollbarScrollByPage = true;
ConfigMemoryCompactTimer = 60.0f;
ConfigTooltipsWrapWidth = 0.0f;
ConfigDebugIsDebuggerPresent = false;
ConfigDebugHighlightIdConflicts = true;
ConfigDebugHighlightIdConflictsShowItemPicker = true;
@@ -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();
}
@@ -16375,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)
@@ -16393,6 +16403,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,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 = <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, 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')
@@ -2375,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)