modified PopupLayout
This commit is contained in:
@@ -2,6 +2,7 @@ using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using CursorLang.Interop;
|
||||
using CursorLang.Models;
|
||||
using CursorLang.Services;
|
||||
using CursorLang.ViewModels;
|
||||
|
||||
namespace CursorLang.Views;
|
||||
@@ -11,7 +12,7 @@ namespace CursorLang.Views;
|
||||
/// Responsible only for showing it, its size and its place on screen: when to take it
|
||||
/// down is decided by <see cref="Services.LayoutPopupService"/>.
|
||||
/// </summary>
|
||||
public partial class LayoutPopupWindow : Window
|
||||
public partial class LayoutPopupWindow : Window, ILayoutPopupWindow
|
||||
{
|
||||
private readonly AppSettings _settings;
|
||||
private Size _contentSize;
|
||||
@@ -94,14 +95,7 @@ public partial class LayoutPopupWindow : Window
|
||||
return caret;
|
||||
}
|
||||
|
||||
PopupWindowNative.Point cursor = PopupWindowNative.GetCursorPosition();
|
||||
return new PopupWindowNative.Rect
|
||||
{
|
||||
Left = cursor.X,
|
||||
Top = cursor.Y,
|
||||
Right = cursor.X,
|
||||
Bottom = cursor.Y,
|
||||
};
|
||||
return PopupLayout.AsAnchor(PopupWindowNative.GetCursorPosition());
|
||||
}
|
||||
|
||||
private void ApplyBoundsNearAnchor(IntPtr handle, PopupWindowNative.Rect anchor)
|
||||
@@ -112,59 +106,27 @@ public partial class LayoutPopupWindow : Window
|
||||
// Every anchor mode has a side and an offset of its own
|
||||
bool atCaret = _settings.PlacementMode == PopupPlacementMode.AtCaret;
|
||||
AnchorSide side = atCaret ? _settings.CaretSide : _settings.CursorSide;
|
||||
int offset = ToPixels(atCaret ? _settings.CaretOffset : _settings.CursorOffset, scale);
|
||||
int offset = PopupLayout.ToPixels(atCaret ? _settings.CaretOffset : _settings.CursorOffset, scale);
|
||||
|
||||
int width = ToPixels(_contentSize.Width, scale);
|
||||
int height = ToPixels(_contentSize.Height, scale);
|
||||
int width = PopupLayout.ToPixels(_contentSize.Width, scale);
|
||||
int height = PopupLayout.ToPixels(_contentSize.Height, scale);
|
||||
|
||||
int toLeftOf = anchor.Left - offset - width;
|
||||
int toRightOf = anchor.Right + offset;
|
||||
int above = anchor.Top - offset - height;
|
||||
int below = anchor.Bottom + offset;
|
||||
// Для сторон «слева» и «справа» подсказка встаёт вровень с точкой привязки
|
||||
int middle = anchor.Top + (((anchor.Bottom - anchor.Top) - height) / 2);
|
||||
PopupWindowNative.Point position = PopupLayout.NearAnchor(anchor, side, offset, width, height);
|
||||
|
||||
(int x, int y) = side switch
|
||||
{
|
||||
AnchorSide.TopLeft => (toLeftOf, above),
|
||||
AnchorSide.TopRight => (toRightOf, above),
|
||||
AnchorSide.Left => (toLeftOf, middle),
|
||||
AnchorSide.Right => (toRightOf, middle),
|
||||
AnchorSide.BottomLeft => (toLeftOf, below),
|
||||
_ => (toRightOf, below),
|
||||
};
|
||||
|
||||
PopupWindowNative.SetBounds(handle, x, y, width, height);
|
||||
PopupWindowNative.SetBounds(handle, position.X, position.Y, width, height);
|
||||
}
|
||||
|
||||
private void ApplyBoundsOnScreen(IntPtr handle)
|
||||
{
|
||||
(PopupWindowNative.Rect work, double scale) = PopupWindowNative.GetActiveMonitorWorkArea();
|
||||
|
||||
int width = ToPixels(_contentSize.Width, scale);
|
||||
int height = ToPixels(_contentSize.Height, scale);
|
||||
int margin = ToPixels(_settings.ScreenMargin, scale);
|
||||
int width = PopupLayout.ToPixels(_contentSize.Width, scale);
|
||||
int height = PopupLayout.ToPixels(_contentSize.Height, scale);
|
||||
int margin = PopupLayout.ToPixels(_settings.ScreenMargin, scale);
|
||||
|
||||
int left = work.Left + margin;
|
||||
int right = work.Right - margin - width;
|
||||
int top = work.Top + margin;
|
||||
int bottom = work.Bottom - margin - height;
|
||||
int centerX = work.Left + ((work.Right - work.Left - width) / 2);
|
||||
int centerY = work.Top + ((work.Bottom - work.Top - height) / 2);
|
||||
PopupWindowNative.Point position =
|
||||
PopupLayout.OnScreen(work, _settings.ScreenPosition, margin, width, height);
|
||||
|
||||
(int x, int y) = _settings.ScreenPosition switch
|
||||
{
|
||||
ScreenPosition.TopLeft => (left, top),
|
||||
ScreenPosition.Top => (centerX, top),
|
||||
ScreenPosition.TopRight => (right, top),
|
||||
ScreenPosition.BottomLeft => (left, bottom),
|
||||
ScreenPosition.Bottom => (centerX, bottom),
|
||||
ScreenPosition.BottomRight => (right, bottom),
|
||||
_ => (centerX, centerY),
|
||||
};
|
||||
|
||||
PopupWindowNative.SetBounds(handle, x, y, width, height);
|
||||
PopupWindowNative.SetBounds(handle, position.X, position.Y, width, height);
|
||||
}
|
||||
|
||||
private static int ToPixels(double wpfUnits, double scale) => (int)Math.Round(wpfUnits * scale);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user