133 lines
3.2 KiB
C#
133 lines
3.2 KiB
C#
using Lattice.Core.Docking.Abstractions;
|
|
using System.ComponentModel;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace Lattice.Core.Docking.Models;
|
|
|
|
public class DockGroup : IDockElement, INotifyPropertyChanged
|
|
{
|
|
private IDockElement _first;
|
|
private IDockElement _second;
|
|
private SplitDirection _orientation;
|
|
private double _splitRatio = 0.5;
|
|
private IDockElement? _parent;
|
|
private double _width;
|
|
private double _height;
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
public DockGroup(IDockElement first, IDockElement second, SplitDirection orientation)
|
|
{
|
|
First = first ?? throw new ArgumentNullException(nameof(first));
|
|
Second = second ?? throw new ArgumentNullException(nameof(second));
|
|
Orientation = orientation;
|
|
}
|
|
|
|
public string Id { get; } = Guid.NewGuid().ToString();
|
|
|
|
public IDockElement? Parent
|
|
{
|
|
get => _parent;
|
|
set
|
|
{
|
|
if (_parent != value)
|
|
{
|
|
_parent = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public IDockElement First
|
|
{
|
|
get => _first;
|
|
set
|
|
{
|
|
if (_first != value)
|
|
{
|
|
_first = value ?? throw new ArgumentNullException(nameof(value));
|
|
_first.Parent = this;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public IDockElement Second
|
|
{
|
|
get => _second;
|
|
set
|
|
{
|
|
if (_second != value)
|
|
{
|
|
_second = value ?? throw new ArgumentNullException(nameof(value));
|
|
_second.Parent = this;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public SplitDirection Orientation
|
|
{
|
|
get => _orientation;
|
|
set
|
|
{
|
|
if (_orientation != value)
|
|
{
|
|
_orientation = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public double SplitRatio
|
|
{
|
|
get => _splitRatio;
|
|
set
|
|
{
|
|
if (Math.Abs(_splitRatio - value) > 0.001)
|
|
{
|
|
_splitRatio = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public double Width
|
|
{
|
|
get => _width;
|
|
set
|
|
{
|
|
if (Math.Abs(_width - value) > 0.001)
|
|
{
|
|
_width = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public double Height
|
|
{
|
|
get => _height;
|
|
set
|
|
{
|
|
if (Math.Abs(_height - value) > 0.001)
|
|
{
|
|
_height = value;
|
|
OnPropertyChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
public double MinWidth => Orientation == SplitDirection.Horizontal
|
|
? First.MinWidth + Second.MinWidth
|
|
: Math.Max(First.MinWidth, Second.MinWidth);
|
|
|
|
public double MinHeight => Orientation == SplitDirection.Vertical
|
|
? First.MinHeight + Second.MinHeight
|
|
: Math.Max(First.MinHeight, Second.MinHeight);
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
{
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
}
|
|
} |