DragAndDrop core
This commit is contained in:
51
Lattice.UI.Docking.WinUI/Controls/LatticeSplitter.cs
Normal file
51
Lattice.UI.Docking.WinUI/Controls/LatticeSplitter.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Lattice.Core.Docking.Models;
|
||||
using Microsoft.UI.Input;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using System;
|
||||
|
||||
namespace Lattice.UI;
|
||||
|
||||
public class LatticeSplitter : Control
|
||||
{
|
||||
public LatticeSplitter()
|
||||
{
|
||||
this.DefaultStyleKey = typeof(LatticeSplitter);
|
||||
this.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
|
||||
|
||||
this.PointerEntered += (s, e) =>
|
||||
this.ProtectedCursor = InputSystemCursor.Create(InputSystemCursorShape.SizeWestEast);
|
||||
this.PointerExited += (s, e) =>
|
||||
this.ProtectedCursor = null;
|
||||
|
||||
this.ManipulationDelta += OnManipulationDelta;
|
||||
}
|
||||
|
||||
private void OnManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
|
||||
{
|
||||
// 1. Находим модель DockGroup через DataContext
|
||||
if (this.DataContext is not DockGroup group) return;
|
||||
|
||||
// 2. Находим родительский Grid, чтобы знать общие размеры
|
||||
if (VisualTreeHelper.GetParent(this) is not Grid parentGrid ||
|
||||
parentGrid.ActualWidth <= 0 || parentGrid.ActualHeight <= 0)
|
||||
return;
|
||||
|
||||
double totalSize = group.Orientation == SplitDirection.Horizontal
|
||||
? parentGrid.ActualWidth
|
||||
: parentGrid.ActualHeight;
|
||||
|
||||
if (totalSize <= 0) return;
|
||||
|
||||
// 3. Вычисляем изменение Ratio (от -1.0 до 1.0)
|
||||
double delta = group.Orientation == SplitDirection.Horizontal
|
||||
? e.Delta.Translation.X
|
||||
: e.Delta.Translation.Y;
|
||||
|
||||
double ratioChange = delta / totalSize;
|
||||
|
||||
// 4. Обновляем модель (с ограничением от 0.05 до 0.95)
|
||||
group.SplitRatio = Math.Clamp(group.SplitRatio + ratioChange, 0.05, 0.95);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user