Tooltips: Tweak default offset for non-drag and drop tooltips.
This commit is contained in:
parent
e95d66faa8
commit
534340cd88
@ -41,6 +41,8 @@ Other changes:
|
||||
- Clipper: Rework inner logic to allow functioning with a zero-clear constructor.
|
||||
This is order to facilitate usage for language bindings (e.g cimgui or dear_binding)
|
||||
where user may not be callinga constructor manually. (#5856)
|
||||
- Tooltips: Tweak default offset for non-drag and drop tooltips so underlying items
|
||||
isn't covered as much. (Match offset for drag and drop tooltips)
|
||||
- Debug Tools: Added 'io.ConfigDebugIniSettings' option to save .ini data with extra
|
||||
comments. Currently mainly for inspecting Docking .ini data, but makes saving slower.
|
||||
- Backends: OpenGL3: Fixed support for glBindSampler() backup/restore on ES3. (#6375, #6508) [@jsm174]
|
||||
|
28
imgui.cpp
28
imgui.cpp
@ -993,6 +993,9 @@ static const float WINDOWS_HOVER_PADDING = 4.0f; // Exten
|
||||
static const float WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER = 0.04f; // Reduce visual noise by only highlighting the border after a certain time.
|
||||
static const float WINDOWS_MOUSE_WHEEL_SCROLL_LOCK_TIMER = 0.70f; // Lock scrolled window (so it doesn't pick child windows that are scrolling through) for a certain time, unless mouse moved.
|
||||
|
||||
// Tooltip offset
|
||||
static const ImVec2 TOOLTIP_DEFAULT_OFFSET = ImVec2(16, 10); // Multiplied by g.Style.MouseCursorScale
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] FORWARD DECLARATIONS
|
||||
//-------------------------------------------------------------------------
|
||||
@ -10050,11 +10053,13 @@ bool ImGui::BeginTooltipEx(ImGuiTooltipFlags tooltip_flags, ImGuiWindowFlags ext
|
||||
|
||||
if (g.DragDropWithinSource || g.DragDropWithinTarget)
|
||||
{
|
||||
// The default tooltip position is a little offset to give space to see the context menu (it's also clamped within the current viewport/monitor)
|
||||
// In the context of a dragging tooltip we try to reduce that offset and we enforce following the cursor.
|
||||
// Whatever we do we want to call SetNextWindowPos() to enforce a tooltip position and disable clipping the tooltip without our display area, like regular tooltip do.
|
||||
// Drag and Drop tooltips are positioning differently than other tooltips:
|
||||
// - offset visibility to increase visibility around mouse.
|
||||
// - never clamp within outer viewport boundary.
|
||||
// We call SetNextWindowPos() to enforce position and disable clamping.
|
||||
// See FindBestWindowPosForPopup() for positionning logic of other tooltips (not drag and drop ones).
|
||||
//ImVec2 tooltip_pos = g.IO.MousePos - g.ActiveIdClickOffset - g.Style.WindowPadding;
|
||||
ImVec2 tooltip_pos = g.IO.MousePos + ImVec2(16 * g.Style.MouseCursorScale, 8 * g.Style.MouseCursorScale);
|
||||
ImVec2 tooltip_pos = g.IO.MousePos + TOOLTIP_DEFAULT_OFFSET * g.Style.MouseCursorScale;
|
||||
SetNextWindowPos(tooltip_pos);
|
||||
SetNextWindowBgAlpha(g.Style.Colors[ImGuiCol_PopupBg].w * 0.60f);
|
||||
//PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.60f); // This would be nice but e.g ColorButton with checkboard has issue with transparent colors :(
|
||||
@ -10625,15 +10630,20 @@ ImVec2 ImGui::FindBestWindowPosForPopup(ImGuiWindow* window)
|
||||
}
|
||||
if (window->Flags & ImGuiWindowFlags_Tooltip)
|
||||
{
|
||||
// Position tooltip (always follows mouse)
|
||||
float sc = g.Style.MouseCursorScale;
|
||||
ImVec2 ref_pos = NavCalcPreferredRefPos();
|
||||
// Position tooltip (always follows mouse + clamp within outer boundaries)
|
||||
// Note that drag and drop tooltips are NOT using this path: BeginTooltipEx() manually sets their position.
|
||||
// In theory we could handle both cases in same location, but requires a bit of shuffling as drag and drop tooltips are calling SetWindowPos() leading to 'window_pos_set_by_api' being set in Begin()
|
||||
IM_ASSERT(g.CurrentWindow == window);
|
||||
const float scale = g.Style.MouseCursorScale;
|
||||
const ImVec2 ref_pos = NavCalcPreferredRefPos();
|
||||
const ImVec2 tooltip_pos = ref_pos + TOOLTIP_DEFAULT_OFFSET * scale;
|
||||
ImRect r_avoid;
|
||||
if (!g.NavDisableHighlight && g.NavDisableMouseHover && !(g.IO.ConfigFlags & ImGuiConfigFlags_NavEnableSetMousePos))
|
||||
r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 16, ref_pos.y + 8);
|
||||
else
|
||||
r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 24 * sc, ref_pos.y + 24 * sc); // FIXME: Hard-coded based on mouse cursor shape expectation. Exact dimension not very important.
|
||||
return FindBestWindowPosForPopupEx(ref_pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid, ImGuiPopupPositionPolicy_Tooltip);
|
||||
r_avoid = ImRect(ref_pos.x - 16, ref_pos.y - 8, ref_pos.x + 24 * scale, ref_pos.y + 24 * scale); // FIXME: Hard-coded based on mouse cursor shape expectation. Exact dimension not very important.
|
||||
//GetForegroundDrawList()->AddRect(r_avoid.Min, r_avoid.Max, IM_COL32(255, 0, 255, 255));
|
||||
return FindBestWindowPosForPopupEx(tooltip_pos, window->Size, &window->AutoPosLastDirection, r_outer, r_avoid, ImGuiPopupPositionPolicy_Tooltip);
|
||||
}
|
||||
IM_ASSERT(0);
|
||||
return window->Pos;
|
||||
|
Loading…
Reference in New Issue
Block a user