fix(dock): fix build breaks, handle size reordering, and add size change subscriptions

This commit is contained in:
2026-03-28 18:25:45 +09:00
parent 4713bfe7da
commit 3c9c95ad73
5 changed files with 48 additions and 26 deletions

View File

@@ -42,27 +42,45 @@ public partial class DockGroupNode : DockNode
private void OnChildrenChanged(object? sender, NotifyCollectionChangedEventArgs e) private void OnChildrenChanged(object? sender, NotifyCollectionChangedEventArgs e)
{ {
// Maintain Sizes collection to match Children // Maintain Sizes collection to match Children
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null) switch (e.Action)
{ {
for (int i = 0; i < e.NewItems.Count; i++) case NotifyCollectionChangedAction.Add:
{ if (e.NewItems != null)
Sizes.Insert(e.NewStartingIndex + i, new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star)); {
} for (int i = 0; i < e.NewItems.Count; i++)
} {
else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null) Sizes.Insert(e.NewStartingIndex + i, new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star));
{ }
for (int i = 0; i < e.OldItems.Count; i++) }
{ break;
Sizes.RemoveAt(e.OldStartingIndex); case NotifyCollectionChangedAction.Remove:
} if (e.OldItems != null)
} {
else if (e.Action == NotifyCollectionChangedAction.Reset) for (int i = 0; i < e.OldItems.Count; i++)
{ {
Sizes.Clear(); Sizes.RemoveAt(e.OldStartingIndex);
foreach (var _ in _children) }
{ }
Sizes.Add(new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star)); break;
} case NotifyCollectionChangedAction.Move:
Sizes.Move(e.OldStartingIndex, e.NewStartingIndex);
break;
case NotifyCollectionChangedAction.Replace:
if (e.NewItems != null)
{
for (int i = 0; i < e.NewItems.Count; i++)
{
Sizes[e.NewStartingIndex + i] = new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star);
}
}
break;
case NotifyCollectionChangedAction.Reset:
Sizes.Clear();
foreach (var _ in _children)
{
Sizes.Add(new Microsoft.UI.Xaml.GridLength(1, Microsoft.UI.Xaml.GridUnitType.Star));
}
break;
} }
} }

View File

@@ -2,7 +2,6 @@ using Ghost.Editor.Core.Controls.Internal.Docking;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Data;
using System.Diagnostics;
namespace Ghost.Editor.View.Controls; namespace Ghost.Editor.View.Controls;

View File

@@ -19,6 +19,7 @@ public sealed partial class DockLayout
if (node is DockGroupNode groupNode) if (node is DockGroupNode groupNode)
{ {
((INotifyCollectionChanged)groupNode.Children).CollectionChanged += OnChildrenCollectionChanged; ((INotifyCollectionChanged)groupNode.Children).CollectionChanged += OnChildrenCollectionChanged;
groupNode.Sizes.CollectionChanged += OnSizesCollectionChanged;
foreach (var child in groupNode.Children) foreach (var child in groupNode.Children)
{ {
SubscribeToNode(child); SubscribeToNode(child);
@@ -38,6 +39,7 @@ public sealed partial class DockLayout
if (node is DockGroupNode groupNode) if (node is DockGroupNode groupNode)
{ {
((INotifyCollectionChanged)groupNode.Children).CollectionChanged -= OnChildrenCollectionChanged; ((INotifyCollectionChanged)groupNode.Children).CollectionChanged -= OnChildrenCollectionChanged;
groupNode.Sizes.CollectionChanged -= OnSizesCollectionChanged;
foreach (var child in groupNode.Children) foreach (var child in groupNode.Children)
{ {
UnsubscribeFromNode(child); UnsubscribeFromNode(child);
@@ -55,11 +57,17 @@ public sealed partial class DockLayout
if (node is DockGroupNode groupNode) if (node is DockGroupNode groupNode)
{ {
((INotifyCollectionChanged)groupNode.Children).CollectionChanged -= OnChildrenCollectionChanged; ((INotifyCollectionChanged)groupNode.Children).CollectionChanged -= OnChildrenCollectionChanged;
groupNode.Sizes.CollectionChanged -= OnSizesCollectionChanged;
} }
} }
_subscribedNodes.Clear(); _subscribedNodes.Clear();
} }
private void OnSizesCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
RenderTree();
}
private void OnNodePropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e) private void OnNodePropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{ {
// Filter to structural property names // Filter to structural property names

View File

@@ -1,11 +1,6 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using Ghost.Core;
using Ghost.Editor.Core.Controls.Internal.Docking; using Ghost.Editor.Core.Controls.Internal.Docking;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data;
namespace Ghost.Editor.View.Controls; namespace Ghost.Editor.View.Controls;

View File

@@ -4,8 +4,10 @@ using Ghost.Editor.Core.Contracts;
using Ghost.Editor.Core.Services; using Ghost.Editor.Core.Services;
using Ghost.Editor.Core.Controls.Internal.Docking; using Ghost.Editor.Core.Controls.Internal.Docking;
using Ghost.Editor.View.Controls; using Ghost.Editor.View.Controls;
using Ghost.Editor.View.Pages.EngineEditor;
using Ghost.Editor.ViewModels.Windows; using Ghost.Editor.ViewModels.Windows;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.ApplicationModel; using Windows.ApplicationModel;
using WinUIEx; using WinUIEx;