added feature - show tootip near careet
This commit is contained in:
@@ -22,6 +22,10 @@ public partial class LayoutPopupWindow : Window
|
||||
|
||||
DataContext = viewModel;
|
||||
_settings = settings;
|
||||
|
||||
// Создаём окно заранее, чтобы задать его границы до первого показа:
|
||||
// иначе оно на мгновение появляется в размере по умолчанию
|
||||
new WindowInteropHelper(this).EnsureHandle();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,20 +74,40 @@ public partial class LayoutPopupWindow : Window
|
||||
return;
|
||||
}
|
||||
|
||||
if (_settings.PlacementMode == PopupPlacementMode.AtCursor)
|
||||
{
|
||||
ApplyBoundsAtCursor(handle);
|
||||
}
|
||||
else
|
||||
if (_settings.PlacementMode == PopupPlacementMode.FixedPoint)
|
||||
{
|
||||
ApplyBoundsOnScreen(handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
ApplyBoundsNearAnchor(handle, GetAnchor());
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyBoundsAtCursor(IntPtr handle)
|
||||
// Точка привязки: каретка в поле ввода либо курсор мыши. Курсор — это
|
||||
// прямоугольник нулевого размера, поэтому расчёт углов у них общий
|
||||
private PopupWindowNative.Rect GetAnchor()
|
||||
{
|
||||
if (_settings.PlacementMode == PopupPlacementMode.AtCaret &&
|
||||
CaretNative.TryGetCaretRect() is { } caret)
|
||||
{
|
||||
return caret;
|
||||
}
|
||||
|
||||
PopupWindowNative.Point cursor = PopupWindowNative.GetCursorPosition();
|
||||
double scale = PopupWindowNative.GetScaleAt(cursor);
|
||||
return new PopupWindowNative.Rect
|
||||
{
|
||||
Left = cursor.X,
|
||||
Top = cursor.Y,
|
||||
Right = cursor.X,
|
||||
Bottom = cursor.Y,
|
||||
};
|
||||
}
|
||||
|
||||
private void ApplyBoundsNearAnchor(IntPtr handle, PopupWindowNative.Rect anchor)
|
||||
{
|
||||
var anchorPoint = new PopupWindowNative.Point { X = anchor.Left, Y = anchor.Top };
|
||||
double scale = PopupWindowNative.GetScaleAt(anchorPoint);
|
||||
|
||||
int width = ToPixels(_contentSize.Width, scale);
|
||||
int height = ToPixels(_contentSize.Height, scale);
|
||||
@@ -92,8 +116,8 @@ public partial class LayoutPopupWindow : Window
|
||||
bool toRight = _settings.CursorCorner is CursorCorner.BottomRight or CursorCorner.TopRight;
|
||||
bool toBottom = _settings.CursorCorner is CursorCorner.BottomRight or CursorCorner.BottomLeft;
|
||||
|
||||
int x = toRight ? cursor.X + offset : cursor.X - offset - width;
|
||||
int y = toBottom ? cursor.Y + offset : cursor.Y - offset - height;
|
||||
int x = toRight ? anchor.Right + offset : anchor.Left - offset - width;
|
||||
int y = toBottom ? anchor.Bottom + offset : anchor.Top - offset - height;
|
||||
|
||||
PopupWindowNative.SetBounds(handle, x, y, width, height);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user