diff --git a/GSS2.UI.Core/SectionPanel.cs b/GSS2.UI.Core/SectionPanel.cs index 0aafa99..363d82c 100644 --- a/GSS2.UI.Core/SectionPanel.cs +++ b/GSS2.UI.Core/SectionPanel.cs @@ -241,6 +241,40 @@ public class SectionPanel : Panel InvalidateArrange(); } + protected override void OnSizeChanged(SizeChangedEventArgs e) + { + if (!_initialized || + e.PreviousSize.Width == 0 || + e.PreviousSize.Height == 0) + { + base.OnSizeChanged(e); + return; + } + + Console.WriteLine($"{e.NewSize} {e.PreviousSize}"); + + foreach (var (child, i) in _childIndeces) + { + var transform = child.RenderTransform as TranslateTransform; + if (transform is null) + { + transform = new TranslateTransform(); + child.RenderTransform = transform; + } + Console.WriteLine($"{i} {transform}"); + if (child.RenderTransformOrigin != RelativePoint.TopLeft) + child.RenderTransformOrigin = RelativePoint.TopLeft; + + _ = Orientation switch + { + Orientation.Vertical => transform.Y += transform.Y == 0 ? 0 : e.PreviousSize.Height - e.NewSize.Height, + Orientation.Horizontal => transform.X += transform.X == 0 ? 0 : e.PreviousSize.Width - e.NewSize.Width, + _ => 0 + }; + Console.WriteLine($"{i} {transform}"); + } + base.OnSizeChanged(e); + } protected override Size MeasureOverride(Size availableSize) { foreach (var child in Children) @@ -252,19 +286,21 @@ public class SectionPanel : Panel if (!_initialized) { foreach (var (i, child) in Children.Enumerate()) - { - var rect = Orientation switch - { - Orientation.Vertical => new Rect(0, i * finalSize.Height, finalSize.Width, finalSize.Height), - Orientation.Horizontal => new Rect(i * finalSize.Width, 0, finalSize.Width, finalSize.Height), - _ => default - }; _childIndeces.Add(child, i); - child.Arrange(rect); - } _initialized = true; } - else if (Children.Count() > 1) + + foreach (var (child, i) in _childIndeces) + { + var rect = Orientation switch + { + Orientation.Vertical => new Rect(0, i * finalSize.Height, finalSize.Width, finalSize.Height), + Orientation.Horizontal => new Rect(i * finalSize.Width, 0, finalSize.Width, finalSize.Height), + _ => default + }; + child.Arrange(rect); + } + if (Children.Count() > 1) Dispatcher.UIThread.Post(async () => _ = ApplyOffset(finalSize, true), DispatcherPriority.Render); return finalSize;