72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Shapes;
|
|
|
|
namespace Lattice.UI.Primitives;
|
|
|
|
/// <summary>
|
|
/// Визуальный оверлей, отображающий зоны приземления (Drop Zones) и якоря докинга.
|
|
/// </summary>
|
|
[TemplatePart(Name = "OverlayCanvas", Type = typeof(Canvas))]
|
|
[TemplatePart(Name = "DropPreview", Type = typeof(Rectangle))]
|
|
[TemplatePart(Name = "AnchorGroup", Type = typeof(Grid))]
|
|
public class DockAnchorOverlay : Control
|
|
{
|
|
private Canvas? _overlayCanvas;
|
|
private Rectangle? _dropPreview;
|
|
private Grid? _anchorGroup;
|
|
|
|
public DockAnchorOverlay()
|
|
{
|
|
// Привязываем стиль из Generic.xaml
|
|
this.DefaultStyleKey = typeof(DockAnchorOverlay);
|
|
|
|
// По умолчанию скрыт, показывается только во время Drag-and-Drop
|
|
this.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
protected override void OnApplyTemplate()
|
|
{
|
|
base.OnApplyTemplate();
|
|
|
|
_overlayCanvas = GetTemplateChild("OverlayCanvas") as Canvas;
|
|
_dropPreview = GetTemplateChild("DropPreview") as Rectangle;
|
|
_anchorGroup = GetTemplateChild("AnchorGroup") as Grid;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Отображает превью будущей зоны закрепления.
|
|
/// </summary>
|
|
/// <param name="rect">Координаты и размер зоны.</param>
|
|
public void ShowPreview(Windows.Foundation.Rect rect)
|
|
{
|
|
if (_dropPreview == null) return;
|
|
|
|
_dropPreview.Visibility = Visibility.Visible;
|
|
Canvas.SetLeft(_dropPreview, rect.X);
|
|
Canvas.SetTop(_dropPreview, rect.Y);
|
|
_dropPreview.Width = rect.Width;
|
|
_dropPreview.Height = rect.Height;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Скрывает превью зоны.
|
|
/// </summary>
|
|
public void HidePreview()
|
|
{
|
|
if (_dropPreview != null)
|
|
_dropPreview.Visibility = Visibility.Collapsed;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Центрирует группу якорей (ромб) относительно указанной точки.
|
|
/// </summary>
|
|
public void PositionAnchors(Windows.Foundation.Point centerPoint)
|
|
{
|
|
if (_anchorGroup == null) return;
|
|
|
|
Canvas.SetLeft(_anchorGroup, centerPoint.X - (_anchorGroup.Width / 2));
|
|
Canvas.SetTop(_anchorGroup, centerPoint.Y - (_anchorGroup.Height / 2));
|
|
}
|
|
}
|