瀏覽代碼

Added some properties to border and panel fixes

Krzysztof Krysiński 4 月之前
父節點
當前提交
623649885b

+ 18 - 4
src/PixiEditor.Extensions.Sdk/Api/FlyUI/Border.cs

@@ -6,14 +6,22 @@ public class Border : SingleChildLayoutElement
 {
     public Color Color { get; set; }
     public Edges Thickness { get; set; }
-    
+
     public Edges CornerRadius { get; set; }
-    
+
     public Edges Padding { get; set; }
-    
+
     public Edges Margin { get; set; }
 
-    public Border(LayoutElement child = null, Color color = default, Edges thickness = default, Edges cornerRadius = default, Edges padding = default, Edges margin = default)
+    public Color BackgroundColor { get; set; }
+
+    public double Width { get; set; }
+
+    public double Height { get; set; }
+
+    public Border(LayoutElement child = null, Color color = default, Edges thickness = default,
+        Edges cornerRadius = default, Edges padding = default, Edges margin = default, double width = -1, double height = -1,
+        Color backgroundColor = default)
     {
         Child = child;
         Color = color;
@@ -21,6 +29,9 @@ public class Border : SingleChildLayoutElement
         CornerRadius = cornerRadius;
         Padding = padding;
         Margin = margin;
+        Width = width;
+        Height = height;
+        BackgroundColor = backgroundColor;
     }
 
     public override CompiledControl BuildNative()
@@ -33,6 +44,9 @@ public class Border : SingleChildLayoutElement
         control.AddProperty(CornerRadius);
         control.AddProperty(Padding);
         control.AddProperty(Margin);
+        control.AddProperty(Width);
+        control.AddProperty(Height);
+        control.AddProperty(BackgroundColor);
 
         return control;
     }

+ 49 - 31
src/PixiEditor.Extensions/FlyUI/Elements/Border.cs

@@ -12,71 +12,80 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 public class Border : SingleChildLayoutElement, IPropertyDeserializable
 {
     private Avalonia.Controls.Border border;
-    
-    private Edges _thickness;
-    private Color _color;
+
+    private Edges thickness;
+    private Color color;
     private Edges cornerRadius;
     private Edges padding;
     private Edges margin;
-    
-    public Color Color { get => _color; set => SetField(ref _color, value); }
-    public Edges Thickness { get => _thickness; set => SetField(ref _thickness, value); }
+
+    private Color backgroundColor;
+    private double width = double.NaN;
+    private double height = double.NaN;
+
+    public Color Color { get => color; set => SetField(ref color, value); }
+    public Edges Thickness { get => thickness; set => SetField(ref thickness, value); }
     public Edges CornerRadius { get => cornerRadius; set => SetField(ref cornerRadius, value); }
     public Edges Padding { get => padding; set => SetField(ref padding, value); }
     public Edges Margin { get => margin; set => SetField(ref margin, value); }
-    
+    public Color BackgroundColor { get => backgroundColor; set => SetField(ref backgroundColor, value); }
+    public double Width { get => width; set => SetField(ref width, value); }
+    public double Height { get => height; set => SetField(ref height, value); }
+
     public override Control BuildNative()
     {
         border = new Avalonia.Controls.Border();
-        
+
         border.ClipToBounds = true;
-        
+
         if (Child != null)
         {
             border.Child = Child.BuildNative();
         }
-        
+
         Binding colorBinding = new Binding()
         {
-            Source = this,
-            Path = nameof(Color),
-            Converter = new ColorToAvaloniaBrushConverter()
+            Source = this, Path = nameof(Color), Converter = new ColorToAvaloniaBrushConverter()
         };
-        
+
         Binding edgesBinding = new Binding()
         {
-            Source = this,
-            Path = nameof(Thickness),
-            Converter = new EdgesToThicknessConverter()
+            Source = this, Path = nameof(Thickness), Converter = new EdgesToThicknessConverter()
         };
-        
+
         Binding cornerRadiusBinding = new Binding()
         {
-            Source = this,
-            Path = nameof(CornerRadius),
-            Converter = new EdgesToCornerRadiusConverter()
+            Source = this, Path = nameof(CornerRadius), Converter = new EdgesToCornerRadiusConverter()
         };
-        
+
         Binding paddingBinding = new Binding()
         {
-            Source = this,
-            Path = nameof(Padding),
-            Converter = new EdgesToThicknessConverter()
+            Source = this, Path = nameof(Padding), Converter = new EdgesToThicknessConverter()
         };
-        
+
         Binding marginBinding = new Binding()
         {
-            Source = this,
-            Path = nameof(Margin),
-            Converter = new EdgesToThicknessConverter()
+            Source = this, Path = nameof(Margin), Converter = new EdgesToThicknessConverter()
         };
-        
+
+        Binding backgroundColorBinding = new Binding()
+        {
+            Source = this, Path = nameof(BackgroundColor), Converter = new ColorToAvaloniaBrushConverter()
+        };
+
+        Binding widthBinding = new Binding() { Source = this, Path = nameof(Width), };
+
+        Binding heightBinding = new Binding() { Source = this, Path = nameof(Height), };
+
+        border.Bind(Layoutable.WidthProperty, widthBinding);
+        border.Bind(Layoutable.HeightProperty, heightBinding);
+        border.Bind(Avalonia.Controls.Border.BackgroundProperty, backgroundColorBinding);
         border.Bind(Avalonia.Controls.Border.BorderBrushProperty, colorBinding);
         border.Bind(Avalonia.Controls.Border.BorderThicknessProperty, edgesBinding);
         border.Bind(Avalonia.Controls.Border.CornerRadiusProperty, cornerRadiusBinding);
         border.Bind(Decorator.PaddingProperty, paddingBinding);
         border.Bind(Layoutable.MarginProperty, marginBinding);
-        
+
         return border;
     }
 
@@ -97,6 +106,9 @@ public class Border : SingleChildLayoutElement, IPropertyDeserializable
         yield return CornerRadius;
         yield return Padding;
         yield return Margin;
+        yield return BackgroundColor;
+        yield return Width;
+        yield return Height;
     }
 
     public void DeserializeProperties(ImmutableList<object> values)
@@ -106,5 +118,11 @@ public class Border : SingleChildLayoutElement, IPropertyDeserializable
         CornerRadius = (Edges)values.ElementAtOrDefault(2, default(Edges));
         Padding = (Edges)values.ElementAtOrDefault(3, default(Edges));
         Margin = (Edges)values.ElementAtOrDefault(4, default(Edges));
+        Width = (double)values.ElementAtOrDefault(5, double.NaN);
+        Height = (double)values.ElementAtOrDefault(6, double.NaN);
+        BackgroundColor = (Color)values.ElementAtOrDefault(7, default(Color));
+
+        Width = Width < 0 ? double.NaN : Width;
+        Height = Height < 0 ? double.NaN : Height;
     }
 }

+ 2 - 11
src/PixiEditor.Extensions/UI/Panels/ColumnPanel.cs

@@ -16,7 +16,8 @@ public class ColumnPanel : Panel
         foreach (var child in Children)
         {
             child.Measure(availableSize);
-            size = new Size(Math.Max(size.Width, child.DesiredSize.Width), size.Height + child.DesiredSize.Height);
+            size += new Size(0, child.DesiredSize.Height);
+            size = new Size(Math.Max(size.Width, child.DesiredSize.Width), size.Height);
         }
 
         if (MainAxisAlignment == MainAxisAlignment.SpaceBetween)
@@ -32,16 +33,6 @@ public class ColumnPanel : Panel
             size = new Size(size.Width, availableSize.Height);
         }
 
-        if (CrossAxisAlignment == CrossAxisAlignment.Center)
-        {
-            size = new Size(availableSize.Width, size.Height);
-        }
-
-        if (CrossAxisAlignment == CrossAxisAlignment.End)
-        {
-            size = new Size(availableSize.Width, size.Height);
-        }
-
         return size;
     }
 

+ 2 - 11
src/PixiEditor.Extensions/UI/Panels/RowPanel.cs

@@ -16,7 +16,8 @@ public class RowPanel : Panel
         foreach (var child in Children)
         {
             child.Measure(availableSize);
-            size = new Size(Math.Max(size.Width, child.DesiredSize.Width), size.Height + child.DesiredSize.Height);
+            size += new Size(child.DesiredSize.Width, 0);
+            size = new Size(size.Width, Math.Max(size.Height, child.DesiredSize.Height));
         }
 
         if (MainAxisAlignment == MainAxisAlignment.SpaceBetween)
@@ -32,16 +33,6 @@ public class RowPanel : Panel
             size = new Size (availableSize.Width, size.Height);
         }
 
-        if (CrossAxisAlignment == CrossAxisAlignment.Center)
-        {
-            size = new Size(availableSize.Width, size.Height);
-        }
-
-        if (CrossAxisAlignment == CrossAxisAlignment.End)
-        {
-            size = new Size(availableSize.Width, size.Height);
-        }
-
         return size;
     }