csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
48 lines
1.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Avalonia.Platform;
|
|
|
|
namespace Avalonia.Controls.Primitives.PopupPositioning
|
|
{
|
|
/// <summary>
|
|
/// This class is used to simplify integration of IPopupImpl implementations with popup positioner
|
|
/// </summary>
|
|
public class ManagedPopupPositionerPopupImplHelper : IManagedPopupPositionerPopup
|
|
{
|
|
private readonly IWindowBaseImpl _parent;
|
|
|
|
public delegate void MoveResizeDelegate(PixelPoint position, Size size, double scaling);
|
|
private readonly MoveResizeDelegate _moveResize;
|
|
|
|
public ManagedPopupPositionerPopupImplHelper(IWindowBaseImpl parent, MoveResizeDelegate moveResize)
|
|
{
|
|
_parent = parent;
|
|
_moveResize = moveResize;
|
|
}
|
|
|
|
public IReadOnlyList<ManagedPopupPositionerScreenInfo> Screens =>
|
|
|
|
_parent.Screen.AllScreens.Select(s => new ManagedPopupPositionerScreenInfo(
|
|
s.Bounds.ToRect(1), s.WorkingArea.ToRect(1))).ToList();
|
|
|
|
public Rect ParentClientAreaScreenGeometry
|
|
{
|
|
get
|
|
{
|
|
// Popup positioner operates with abstract coordinates, but in our case they are pixel ones
|
|
var point = _parent.PointToScreen(default);
|
|
var size = _parent.ClientSize * Scaling;
|
|
return new Rect(point.X, point.Y, size.Width, size.Height);
|
|
|
|
}
|
|
}
|
|
|
|
public void MoveAndResize(Point devicePoint, Size virtualSize)
|
|
{
|
|
_moveResize(new PixelPoint((int)devicePoint.X, (int)devicePoint.Y), virtualSize, _parent.Scaling);
|
|
}
|
|
|
|
public virtual double Scaling => _parent.Scaling;
|
|
}
|
|
}
|
|
|