Browse Source

Row and Column is now built with DockPanel

Krzysztof Krysiński 1 year ago
parent
commit
19a72c201f

+ 4 - 4
src/PixiEditor.Extensions.Tests/LayoutBuilderElementsTests.cs

@@ -19,8 +19,8 @@ public class LayoutBuilderElementsTests
         Panel grid = (Panel)result;
         Panel grid = (Panel)result;
         Assert.Single(grid.Children);
         Assert.Single(grid.Children);
 
 
-        Assert.IsType<StackPanel>(grid.Children[0]);
-        Panel childGrid = (StackPanel)grid.Children[0];
+        Assert.IsType<DockPanel>(grid.Children[0]);
+        Panel childGrid = (DockPanel)grid.Children[0];
 
 
         Assert.Equal(Avalonia.Layout.HorizontalAlignment.Stretch, childGrid.HorizontalAlignment);
         Assert.Equal(Avalonia.Layout.HorizontalAlignment.Stretch, childGrid.HorizontalAlignment);
         Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, childGrid.VerticalAlignment);
         Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, childGrid.VerticalAlignment);
@@ -52,8 +52,8 @@ public class LayoutBuilderElementsTests
         Panel grid = (Panel)result;
         Panel grid = (Panel)result;
         Assert.Single(grid.Children);
         Assert.Single(grid.Children);
 
 
-        Assert.IsType<StackPanel>(grid.Children[0]);
-        Panel childGrid = (StackPanel)grid.Children[0];
+        Assert.IsType<DockPanel>(grid.Children[0]);
+        Panel childGrid = (DockPanel)grid.Children[0];
 
 
         Assert.Equal(Avalonia.Layout.HorizontalAlignment.Stretch, childGrid.HorizontalAlignment);
         Assert.Equal(Avalonia.Layout.HorizontalAlignment.Stretch, childGrid.HorizontalAlignment);
         Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, childGrid.VerticalAlignment);
         Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, childGrid.VerticalAlignment);

+ 5 - 5
src/PixiEditor.Extensions.Tests/LayoutBuilderTests.cs

@@ -155,19 +155,19 @@ public class LayoutBuilderTests
         var native = testStatefulElement.BuildNative();
         var native = testStatefulElement.BuildNative();
 
 
         Assert.IsType<ContentPresenter>(native);
         Assert.IsType<ContentPresenter>(native);
-        Assert.IsType<StackPanel>((native as ContentPresenter).Content);
-        StackPanel panel = (native as ContentPresenter).Content as StackPanel;
+        Assert.IsType<DockPanel>((native as ContentPresenter).Content);
+        DockPanel panel = (native as ContentPresenter).Content as DockPanel;
 
 
         Assert.Equal(2, panel.Children.Count);
         Assert.Equal(2, panel.Children.Count);
 
 
         Assert.IsType<Avalonia.Controls.Button>(panel.Children[0]);
         Assert.IsType<Avalonia.Controls.Button>(panel.Children[0]);
-        Assert.IsType<StackPanel>(panel.Children[1]);
+        Assert.IsType<DockPanel>(panel.Children[1]);
 
 
-        Assert.Empty((panel.Children[1] as StackPanel).Children);
+        Assert.Empty((panel.Children[1] as DockPanel).Children);
         Assert.Empty(testStatefulElement.State.Rows);
         Assert.Empty(testStatefulElement.State.Rows);
 
 
         Avalonia.Controls.Button button = (Avalonia.Controls.Button)panel.Children[0];
         Avalonia.Controls.Button button = (Avalonia.Controls.Button)panel.Children[0];
-        StackPanel innerPanel = (StackPanel)panel.Children[1];
+        DockPanel innerPanel = (DockPanel)panel.Children[1];
 
 
         button.RaiseEvent(new RoutedEventArgs(Avalonia.Controls.Button.ClickEvent));
         button.RaiseEvent(new RoutedEventArgs(Avalonia.Controls.Button.ClickEvent));
 
 

+ 1 - 0
src/PixiEditor.Extensions.Wasm/Api/LayoutBuilding/CompiledControl.cs

@@ -38,6 +38,7 @@ public class CompiledControl
         return Serialize(new List<byte>()).ToArray();
         return Serialize(new List<byte>()).ToArray();
     }
     }
 
 
+    // DO NOT REMOVE, used by reflection-based layout compiler, using Serialize with Span<byte> throws error.
     public byte[] SerializeBytes()
     public byte[] SerializeBytes()
     {
     {
         return Serialize(new List<byte>()).ToArray();
         return Serialize(new List<byte>()).ToArray();

+ 12 - 3
src/PixiEditor.Extensions/LayoutBuilding/Elements/Column.cs

@@ -2,13 +2,14 @@
 using System.Collections.Specialized;
 using System.Collections.Specialized;
 using System.ComponentModel;
 using System.ComponentModel;
 using Avalonia.Controls;
 using Avalonia.Controls;
+using Avalonia.Layout;
 using Avalonia.Threading;
 using Avalonia.Threading;
 
 
 namespace PixiEditor.Extensions.LayoutBuilding.Elements;
 namespace PixiEditor.Extensions.LayoutBuilding.Elements;
 
 
 public class Column : MultiChildLayoutElement
 public class Column : MultiChildLayoutElement
 {
 {
-    private StackPanel panel;
+    private DockPanel panel;
 
 
     public Column()
     public Column()
     {
     {
@@ -29,6 +30,7 @@ public class Column : MultiChildLayoutElement
                 foreach (LayoutElement? item in e.NewItems)
                 foreach (LayoutElement? item in e.NewItems)
                 {
                 {
                     var newChild = item.BuildNative();
                     var newChild = item.BuildNative();
+                    DockPanel.SetDock(newChild, Dock.Top);
                     panel.Children.Add(newChild);
                     panel.Children.Add(newChild);
                 }
                 }
             }
             }
@@ -44,13 +46,20 @@ public class Column : MultiChildLayoutElement
 
 
     public override Control BuildNative()
     public override Control BuildNative()
     {
     {
-        panel = new StackPanel
+        panel = new DockPanel
         {
         {
-            Orientation = Avalonia.Layout.Orientation.Vertical
+            LastChildFill = true,
+            HorizontalAlignment = HorizontalAlignment.Stretch,
+            VerticalAlignment = VerticalAlignment.Stretch
         };
         };
 
 
         panel.Children.AddRange(Children.Select(x => x.BuildNative()));
         panel.Children.AddRange(Children.Select(x => x.BuildNative()));
 
 
+        foreach (var child in panel.Children)
+        {
+            DockPanel.SetDock(child, Dock.Top);
+        }
+
         return panel;
         return panel;
     }
     }
 }
 }

+ 11 - 3
src/PixiEditor.Extensions/LayoutBuilding/Elements/Row.cs

@@ -6,7 +6,7 @@ namespace PixiEditor.Extensions.LayoutBuilding.Elements;
 
 
 public class Row : MultiChildLayoutElement
 public class Row : MultiChildLayoutElement
 {
 {
-    private StackPanel panel;
+    private DockPanel panel;
     public Row()
     public Row()
     {
     {
     }
     }
@@ -26,6 +26,7 @@ public class Row : MultiChildLayoutElement
                 foreach (LayoutElement? item in e.NewItems)
                 foreach (LayoutElement? item in e.NewItems)
                 {
                 {
                     var newChild = item.BuildNative();
                     var newChild = item.BuildNative();
+                    DockPanel.SetDock(newChild, Dock.Left);
                     panel.Children.Add(newChild);
                     panel.Children.Add(newChild);
                 }
                 }
             }
             }
@@ -41,13 +42,20 @@ public class Row : MultiChildLayoutElement
 
 
     public override Control BuildNative()
     public override Control BuildNative()
     {
     {
-        panel = new StackPanel
+        panel = new DockPanel()
         {
         {
-            Orientation = Avalonia.Layout.Orientation.Horizontal
+            LastChildFill = true,
+            HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Stretch,
+            VerticalAlignment = Avalonia.Layout.VerticalAlignment.Stretch
         };
         };
 
 
         panel.Children.AddRange(Children.Select(x => x.BuildNative()));
         panel.Children.AddRange(Children.Select(x => x.BuildNative()));
 
 
+        foreach (var child in panel.Children)
+        {
+            DockPanel.SetDock(child, Dock.Left);
+        }
+
         return panel;
         return panel;
     }
     }
 }
 }

+ 0 - 0
src/PixiEditor.Extensions/LayoutBuilding/Elements/Exceptions/DuplicateIdElementException.cs → src/PixiEditor.Extensions/LayoutBuilding/Exceptions/DuplicateIdElementException.cs