using Lattice.Core.Docking.Abstractions;
using Lattice.Core.Docking.Models;
using Lattice.UI.Docking.Abstractions;
using Lattice.UI.Docking.Factories;
using Microsoft.UI.Xaml;
using System;
namespace Lattice.UI.Docking.WinUI.Factories;
///
/// Фабрика контролов для платформы WinUI.
/// Создает UI-элементы для отображения компонентов системы докинга.
///
public sealed class WinUIDockControlFactory : DockControlFactoryBase, IDockControlFactory
{
private readonly IDockTheme _theme;
///
/// Инициализирует новый экземпляр фабрики WinUI.
///
/// Тема оформления.
public WinUIDockControlFactory(IDockTheme theme)
{
_theme = theme ?? throw new ArgumentNullException(nameof(theme));
}
///
public override IDockGroupControl CreateGroupControl(DockGroup group)
{
var control = new LatticeDockGroup();
ConfigureControl(control, group);
control.ApplyTheme(_theme);
return control;
}
///
public override IDockLeafControl CreateLeafControl(DockLeaf leaf)
{
var control = new LatticeTabControl();
ConfigureControl(control, leaf);
control.ApplyTheme(_theme);
return control;
}
///
public override IFloatingWindowControl CreateFloatingWindowControl(DockWindow window)
{
// TODO: Реализовать создание плавающего окна
throw new NotImplementedException();
}
///
public override IAutoHidePanelControl CreateAutoHidePanelControl(AutoHidePanel panel)
{
// TODO: Реализовать создание автоскрываемой панели
throw new NotImplementedException();
}
///
public override IDockSplitterControl CreateSplitterControl(SplitDirection orientation)
{
var control = new LatticeSplitter
{
Orientation = orientation
};
ConfigureControl(control);
control.ApplyTheme(_theme);
return control;
}
///
/// Создает хост для размещения системы докинга.
///
public IDockHost CreateDockHost()
{
var host = new LatticeDockHost();
ConfigureControl(host);
host.ApplyTheme(_theme);
return host;
}
private void ConfigureControl(IDockControl control, IDockElement? model = null)
{
if (control == null) return;
control.Model = model;
control.LayoutManager = LatticeUIFramework.LayoutManager;
control.DragDropService = LatticeUIFramework.DragDropService;
control.ContextManager = LatticeUIFramework.ContextManager;
if (control is FrameworkElement frameworkElement && model != null)
{
frameworkElement.DataContext = model;
}
}
}