Problematic placement of tooltips in the bottom left corner
Describe the bug
When you have a button in the bottom left corner of the app and the window is maximized or moved close to the task bar the tooltip of the button is shown directly over the button so that can't click the button.
To Reproduce
Simple example.
<Grid
ColumnDefinitions="Auto, 1*"
RowDefinitions="1*, Auto">
<Button
Grid.Row="1"
Grid.Column="0"
Content="✎"
ToolTip.Tip="Edit list settings" />
</Grid>
Expected behavior
I would expect that the tooltip does not appear over the button so that the button remains clickable.
Avalonia version
11.3.7
OS
Windows
Additional context
No response
Can you explicitly set the tooltip placement here, like Top?
I'm not able to repro it on the control catalog. could you post a video of it occuring? Thanks
Setting the tooltip placement to top does not help. Then the tooltip covers a different half of the button.
I'm not able to repro it on the control catalog. could you post a video of it occuring?
There is not very much to see in a video beside the tooltip appearing as shown in the screenshot.
There is a default vertical offset. This can also be overwritten.
I'm guessing it's a scaling+positioning issue.
The bug is immediately reproducible when pasting the sample XAML into the sandbox project.
It looks a lot to me like when using Pointer placement, if there isn't enough room for the tooltip to appear beneath the pointer then Avalonia instead tries to place it right next to the pointer. Which as pointed out isn't a good idea because it obscures the object beneath the pointer.
A better solution would be to place the tooltip above the pointer, with the bottom edge aligned to the pointer's Y position plus a small gap. Now there is always at least a small clickable surface.
Just stumbled upon this very same bug. Buttons at (or near) the bottom of the window becomes unresponsive while tooltip is showing when a window is at the bottom(or maximized) of the display area.
This is especially problematic on Linux/X11 environment because a tooltip does not show up (#11179). So, from a user's perspective, a button is just unresponsive for no obvious reasons for a while. It took me a while to figure out why because I was on Ubuntu when I realized something is wrong. On Windows, at least tooltip popup is shown, so there is some clue as to why.
I checked to see other apps' behaviors like WPF and WinUI3 and they automatically change popup placement to top instead of bottom when a window is at the bottom(or maximized).
I think Avalonia should follow the same behavior.
Avalonia v11.3.13 Ubuntu 24.04, Windows 11
Root cause, as read in Avalonia 12.1.4 (decompiled Avalonia.Controls):
PopupPositionerExtensions.Update gives Placement=Pointer a 1×1 anchor rectangle at the pointer, with anchor TopLeft and gravity BottomRight. When the tooltip does not fit below the pointer, ManagedPopupPositioner.Calculate flips anchor and gravity (GetUnconstrained(anchor.FlipY(), gravity.FlipY())), but GetUnconstrained still adds the original, unflipped offset. With the default ToolTip.VerticalOffset = 20, the flipped tooltip's bottom edge therefore ends 21 px below the pointer, so the tooltip sits on the pointer. The next click goes to the tooltip, which ToolTipService closes on LeftButtonDown without the press reaching the control underneath, so the first click on a bottom-edge button is lost.
The same code path is used on macOS (Avalonia.Native PopupImpl uses ManagedPopupPositioner, bounded by the screen working area), on Windows (Avalonia.Win32 PopupImpl) and by overlay popups (bounded by the window). Negating the offset on the flipped axis, as suggested in #4976, would fix it.
Workarounds
- Per control:
ToolTip.Placement="Right"(orLeft) withToolTip.VerticalOffset="0". - App-wide, keeping today's look: a
CustomPopupPlacementCallbackcannot see whether the popup will flip (it runs beforeCalculate), but it does not need to. Move the vertical offset into the anchor rectangle, which flips symmetrically. Unflipped, the result is pixel-identical toPlacement=Pointer; flipped, the tooltip endsoffset - 1px above the pointer. Sketch:
// pointer = the last pointer position in top-level coordinates (TopLevel.LastPointerPosition is internal,
// so record it yourself from a PointerMoved class handler on TopLevel, per top level).
static void Place(CustomPopupPlacement p, Point pointer)
{
var v = p.Offset.Y; // e.g. the default 20
p.Gravity = PopupGravity.BottomRight;
if (v < 1)
{
p.AnchorRectangle = new Rect(pointer, new Size(1, 1));
p.Anchor = PopupAnchor.TopLeft;
return;
}
// From pointer.Y + 1 - v to pointer.Y + v, anchored at its bottom edge, no vertical offset.
p.AnchorRectangle = new Rect(pointer.X, pointer.Y + 1 - v, 1, 2 * v - 1);
p.Anchor = PopupAnchor.BottomLeft;
p.Offset = new Point(p.Offset.X, 0);
}
Apply it with ToolTip.Placement = Custom and ToolTip.CustomPopupPlacementCallback at style priority, so an explicit placement on a control still wins. The same treatment is needed for a Bottom-style fallback when no pointer has been seen yet: a plain Placement=Bottom has the identical flip bug, and its +offset pushes a flipped tooltip down onto the control.