2
0
flabbet 1 жил өмнө
parent
commit
39bda379a7

+ 7 - 1
src/PixiEditor.ClosedBeta/ClosedBetaExtension.cs

@@ -6,6 +6,12 @@ public class ClosedBetaExtension : PixiEditorExtension
 {
     public override void OnInitialized()
     {
-        Api.WindowProvider.CreatePopupWindow("Welcome to the closed beta!", new WelcomeMessage()).ShowDialog();
+        WelcomeMessage welcomeMessage = new();
+        var window = Api.WindowProvider.CreatePopupWindow("Welcome to the closed beta!", welcomeMessage);
+        welcomeMessage.OnContinue += () => window.Close();
+        
+        window.CanResize = false;
+        window.CanMinimize = false;
+        window.ShowDialog();
     }
 }

+ 6 - 2
src/PixiEditor.ClosedBeta/WelcomeMessage.cs

@@ -4,8 +4,12 @@ namespace PixiEditor.ClosedBeta;
 
 public class WelcomeMessage : StatefulElement<WelcomeMessageState>
 {
+    public event Action OnContinue;
+    
     public override WelcomeMessageState CreateState()
-    {
-        return new WelcomeMessageState();
+    { 
+        WelcomeMessageState state = new WelcomeMessageState();
+        state.OnContinue += () => OnContinue?.Invoke();
+        return state;
     }
 }

+ 31 - 2
src/PixiEditor.ClosedBeta/WelcomeMessageState.cs

@@ -1,4 +1,5 @@
 using PixiEditor.Extensions.CommonApi.FlyUI.Properties;
+using PixiEditor.Extensions.Sdk;
 using PixiEditor.Extensions.Sdk.Api.FlyUI;
 
 namespace PixiEditor.ClosedBeta;
@@ -16,8 +17,14 @@ we have a few things to note:
 - Promised features available in this beta are: Animations, Procedural Art (Nodes)
 
 Click on below checkboxes that you understand what you are getting into and you are ready to test the app.
+
+I understand that:
 ";
 
+    private bool[] _checkboxes = new bool[4];
+
+    public event Action OnContinue;
+
     public override LayoutElement BuildElement()
     {
         return new Layout(body:
@@ -28,14 +35,36 @@ Click on below checkboxes that you understand what you are getting into and you
                         FontStyle.Normal,
                         fontSize: 24)),
                     new Text(Body, TextWrap.Wrap, fontSize: 18),
+                    new CheckBox(new Text("The app is unstable and may crash and freeze"),
+                        onCheckedChanged: (args) => CheckboxChanged(args.Sender as CheckBox, 0)),
+                    new CheckBox(new Text("I may encounter unfinished features and placeholders"),
+                        onCheckedChanged: (args) => CheckboxChanged(args.Sender as CheckBox, 1)),
+                    new CheckBox(new Text("I may lose my work due to bugs"),
+                        onCheckedChanged: (args) => CheckboxChanged(args.Sender as CheckBox, 2)),
+                    new CheckBox(new Text("I will have a lot of fun testing the app"),
+                        onCheckedChanged: (args) => CheckboxChanged(args.Sender as CheckBox, 3)),
                     new Container(
                         width: 100,
                         child:
-                        new Button(new Text("Continue")
-                        )
+                        AllCheckBoxesChecked()
+                            ? new Button(new Text("Continue"), onClick: (args) => { OnContinue?.Invoke(); })
+                            : new Text("Select All Checkboxes to continue", fontSize: 12)
                     )
                 )
             )
         );
     }
+
+    void CheckboxChanged(CheckBox checkBox, int index)
+    {
+        SetState(() =>
+        {
+            _checkboxes[index] = checkBox.IsChecked;
+        });
+    }
+
+    private bool AllCheckBoxesChecked()
+    {
+        return _checkboxes.All(x => x);
+    }
 }

+ 14 - 3
src/PixiEditor.Extensions/FlyUI/Elements/Align.cs

@@ -8,6 +8,7 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 
 public class Align : SingleChildLayoutElement, IPropertyDeserializable
 {
+    private Panel _panel; 
     public Alignment Alignment { get; set; }
 
     public Align(LayoutElement child = null, Alignment alignment = Alignment.Center)
@@ -18,17 +19,27 @@ public class Align : SingleChildLayoutElement, IPropertyDeserializable
 
     public override Control BuildNative()
     {
-        Panel panel = new Panel
+        _panel = new Panel
         {
             HorizontalAlignment = DecomposeHorizontalAlignment(Alignment), VerticalAlignment = DecomposeVerticalAlignment(Alignment)
         };
 
         if (Child != null)
         {
-            panel.Children.Add(Child.BuildNative());
+            _panel.Children.Add(Child.BuildNative());
         }
 
-        return panel;
+        return _panel;
+    }
+
+    protected override void AddChild(Control child)
+    {
+        _panel.Children.Add(child);
+    }
+
+    protected override void RemoveChild()
+    {
+        _panel.Children.Clear(); 
     }
 
     private HorizontalAlignment DecomposeHorizontalAlignment(Alignment alignment)

+ 13 - 1
src/PixiEditor.Extensions/FlyUI/Elements/Border.cs

@@ -11,6 +11,8 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 
 public class Border : SingleChildLayoutElement, IPropertyDeserializable
 {
+    private Avalonia.Controls.Border border;
+    
     private Edges _thickness;
     private Color _color;
     private Edges cornerRadius;
@@ -25,7 +27,7 @@ public class Border : SingleChildLayoutElement, IPropertyDeserializable
     
     public override Control BuildNative()
     {
-        Avalonia.Controls.Border border = new Avalonia.Controls.Border();
+        border = new Avalonia.Controls.Border();
         
         border.ClipToBounds = true;
         
@@ -78,6 +80,16 @@ public class Border : SingleChildLayoutElement, IPropertyDeserializable
         return border;
     }
 
+    protected override void AddChild(Control child)
+    {
+        border.Child = child;
+    }
+
+    protected override void RemoveChild()
+    {
+        border.Child = null;
+    }
+
     public IEnumerable<object> GetProperties()
     {
         yield return Color;

+ 15 - 4
src/PixiEditor.Extensions/FlyUI/Elements/Button.cs

@@ -7,6 +7,7 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 
 public class Button : SingleChildLayoutElement
 {
+    private Avalonia.Controls.Button _button;
     public event ElementEventHandler Click
     {
         add => AddEvent(nameof(Click), value);
@@ -29,12 +30,22 @@ public class Button : SingleChildLayoutElement
 
     public override Control BuildNative()
     {
-        Avalonia.Controls.Button btn = new Avalonia.Controls.Button();
+        _button = new Avalonia.Controls.Button();
         Binding binding = new Binding(nameof(Child)) { Source = this, Converter = LayoutElementToNativeControlConverter.Instance };
-        btn.Bind(Avalonia.Controls.Button.ContentProperty, binding);
+        _button.Bind(Avalonia.Controls.Button.ContentProperty, binding);
 
-        btn.Click += (sender, args) => RaiseEvent(nameof(Click), new ElementEventArgs() { Sender = this });
+        _button.Click += (sender, args) => RaiseEvent(nameof(Click), new ElementEventArgs() { Sender = this });
 
-        return btn;
+        return _button;
+    }
+
+    protected override void AddChild(Control child)
+    {
+        _button.Content = child;
+    }
+
+    protected override void RemoveChild()
+    {
+        _button.Content = null;
     }
 }

+ 10 - 18
src/PixiEditor.Extensions/FlyUI/Elements/Center.cs

@@ -14,24 +14,6 @@ public class Center : SingleChildLayoutElement
     public Center(LayoutElement child = null)
     {
         Child = child;
-        PropertyChanged += OnPropertyChanged;
-    }
-
-    private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
-    {
-        if(panel == null)
-        {
-            return;
-        }
-
-        if (e.PropertyName == nameof(Child))
-        {
-            panel.Children.Clear();
-            if (Child != null)
-            {
-                panel.Children.Add(Child.BuildNative());
-            }
-        }
     }
 
     public override Control BuildNative()
@@ -50,4 +32,14 @@ public class Center : SingleChildLayoutElement
 
         return panel;
     }
+
+    protected override void AddChild(Control child)
+    {
+        panel.Children.Add(child);
+    }
+
+    protected override void RemoveChild()
+    {
+        panel.Children.Clear();
+    }
 }

+ 12 - 2
src/PixiEditor.Extensions/FlyUI/Elements/CheckBox.cs

@@ -6,7 +6,7 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 
 public class CheckBox : SingleChildLayoutElement
 {
-    
+    private Avalonia.Controls.CheckBox checkbox;    
     public event ElementEventHandler<ToggleEventArgs> CheckedChanged
     {
         add => AddEvent(nameof(CheckedChanged), value);
@@ -15,7 +15,7 @@ public class CheckBox : SingleChildLayoutElement
 
     public override Control BuildNative()
     {
-        Avalonia.Controls.CheckBox checkbox = new Avalonia.Controls.CheckBox();
+        checkbox = new Avalonia.Controls.CheckBox();
         Binding binding =
             new Binding(nameof(Child)) { Source = this, Converter = LayoutElementToNativeControlConverter.Instance };
         checkbox.Bind(ContentControl.ContentProperty, binding);
@@ -26,4 +26,14 @@ public class CheckBox : SingleChildLayoutElement
 
         return checkbox;
     }
+
+    protected override void AddChild(Control child)
+    {
+        checkbox.Content = child;
+    }
+
+    protected override void RemoveChild()
+    {
+        checkbox.Content = null;
+    }
 }

+ 22 - 17
src/PixiEditor.Extensions/FlyUI/Elements/Container.cs

@@ -11,6 +11,7 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 
 public class Container : SingleChildLayoutElement, IPropertyDeserializable
 {
+    private Panel _panel; 
     private Edges _margin = Edges.All(0);
     private Color _backgroundColor = Colors.Transparent;
     private double _width = double.NaN;
@@ -23,13 +24,13 @@ public class Container : SingleChildLayoutElement, IPropertyDeserializable
     
     public override Control BuildNative()
     {
-        Panel panel = new Panel();
+        _panel = new Panel();
         
-        panel.ClipToBounds = true;
+        _panel.ClipToBounds = true;
         
         if(Child != null)
         {
-            panel.Children.Add(Child.BuildNative());
+            _panel.Children.Add(Child.BuildNative());
         }
         
         Binding marginBinding = new()
@@ -58,25 +59,29 @@ public class Container : SingleChildLayoutElement, IPropertyDeserializable
             Path = nameof(Height),
         };
         
-        panel.Bind(Layoutable.MarginProperty, marginBinding);
-        panel.Bind(Panel.BackgroundProperty, backgroundColorBinding);
-        panel.Bind(Layoutable.WidthProperty, widthBinding);
-        panel.Bind(Layoutable.HeightProperty, heightBinding);
+        _panel.Bind(Layoutable.MarginProperty, marginBinding);
+        _panel.Bind(Panel.BackgroundProperty, backgroundColorBinding);
+        _panel.Bind(Layoutable.WidthProperty, widthBinding);
+        _panel.Bind(Layoutable.HeightProperty, heightBinding);
         
-        return panel;
+        return _panel;
+    }
+
+    protected override void AddChild(Control child)
+    {
+        _panel.Children.Add(child);
+    }
+
+    protected override void RemoveChild()
+    {
+        _panel.Children.Clear();
     }
 
     public IEnumerable<object> GetProperties()
     {
-        yield return Margin.Left;
-        yield return Margin.Top;
-        yield return Margin.Right;
-        yield return Margin.Bottom;
-        
-        yield return BackgroundColor.R;
-        yield return BackgroundColor.G;
-        yield return BackgroundColor.B;
-        yield return BackgroundColor.A;
+        yield return Margin;
+
+        yield return BackgroundColor;
         
         yield return Width;
         yield return Height;

+ 12 - 1
src/PixiEditor.Extensions/FlyUI/Elements/Layout.cs

@@ -4,6 +4,7 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 
 public class Layout : SingleChildLayoutElement
 {
+    private Panel panel;
     public Layout()
     {
 
@@ -16,7 +17,7 @@ public class Layout : SingleChildLayoutElement
 
     public override Control BuildNative()
     {
-        Panel panel = new Panel();
+        panel = new Panel();
         if (Child != null)
         {
             panel.Children.Add(Child.BuildNative());
@@ -24,4 +25,14 @@ public class Layout : SingleChildLayoutElement
 
         return panel;
     }
+
+    protected override void AddChild(Control child)
+    {
+        panel.Children.Add(child);
+    }
+
+    protected override void RemoveChild()
+    {
+        panel.Children.Clear();
+    }
 }

+ 5 - 0
src/PixiEditor.Extensions/FlyUI/Elements/MultiChildLayoutElement.cs

@@ -25,6 +25,8 @@ public abstract class MultiChildLayoutElement : LayoutElement, IMultiChildLayout
     }
 
     public abstract override Control BuildNative();
+    /*public abstract void AddChild(Control child);
+    public abstract void RemoveChild(int atIndex);*/
 
     public IEnumerator<ILayoutElement<Control>> GetEnumerator()
     {
@@ -44,10 +46,13 @@ public abstract class MultiChildLayoutElement : LayoutElement, IMultiChildLayout
     public void AddChild(ILayoutElement<Control> child)
     {
         Children.Add((LayoutElement)child);
+        //AddChild(child.BuildNative());
     }
 
     public void RemoveChild(ILayoutElement<Control> child)
     {
+        int index = Children.IndexOf((LayoutElement)child);
         Children.Remove((LayoutElement)child);
+        //RemoveChild(index);   
     }
 }

+ 15 - 4
src/PixiEditor.Extensions/FlyUI/Elements/Padding.cs

@@ -10,16 +10,17 @@ namespace PixiEditor.Extensions.FlyUI.Elements;
 
 public class Padding : SingleChildLayoutElement, IPropertyDeserializable
 {
+    private Decorator _decorator;
     private Edges _edges = Edges.All(0);
     
     public Edges Edges { get => _edges; set => SetField(ref _edges, value); }
     public override Control BuildNative()
     {
-        Decorator decorator = new();
+        _decorator = new();
         
         if(Child != null)
         {
-            decorator.Child = Child.BuildNative();
+            _decorator.Child = Child.BuildNative();
         }
         
         Binding edgesBinding = new()
@@ -29,9 +30,19 @@ public class Padding : SingleChildLayoutElement, IPropertyDeserializable
             Converter = new EdgesToThicknessConverter(),
         };
         
-        decorator.Bind(Decorator.PaddingProperty, edgesBinding);
+        _decorator.Bind(Decorator.PaddingProperty, edgesBinding);
         
-        return decorator;
+        return _decorator;
+    }
+
+    protected override void AddChild(Control child)
+    {
+        _decorator.Child = child;
+    }
+
+    protected override void RemoveChild()
+    {
+        _decorator.Child = null;
     }
 
     public IEnumerable<object> GetProperties()

+ 8 - 1
src/PixiEditor.Extensions/FlyUI/Elements/SingleChildLayoutElement.cs

@@ -17,10 +17,15 @@ public abstract class SingleChildLayoutElement : LayoutElement, ISingleChildLayo
     public LayoutElement Child
     {
         get => _child;
-        set => SetField(ref _child, value);
+        set
+        {
+            SetField(ref _child, value);
+        }
     }
 
     public abstract override Control BuildNative();
+    protected abstract void AddChild(Control child);
+    protected abstract void RemoveChild();
 
     void IChildHost.DeserializeChildren(List<ILayoutElement<Control>> children)
     {
@@ -30,11 +35,13 @@ public abstract class SingleChildLayoutElement : LayoutElement, ISingleChildLayo
     public void AddChild(ILayoutElement<Control> child)
     {
         Child = (LayoutElement)child;
+        AddChild(child.BuildNative());
     }
 
     public void RemoveChild(ILayoutElement<Control> child)
     {
         Child = null;
+        RemoveChild();
     }
 
     public IEnumerator<ILayoutElement<Control>> GetEnumerator()