Pārlūkot izejas kodu

avalonia: Added double and integer form fields

Kenric Nugteren 2 mēneši atpakaļ
vecāks
revīzija
7b5e98b92e

+ 56 - 0
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFDoubleFieldControl.cs

@@ -0,0 +1,56 @@
+using Avalonia.Controls;
+using Avalonia.Layout;
+using Avalonia.Media;
+using InABox.Avalonia.Components;
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRS.Avalonia.DigitalForms;
+
+class DFDoubleFieldControl : DigitalFormFieldControl<DFLayoutDoubleField, DFLayoutDoubleFieldProperties, double, double?>
+{
+    private DoubleBox Double = null!; // late-initialising
+
+    protected override Control Create()
+    {
+        Double = new DoubleBox();
+        Double.Value = (decimal)Field.Properties.Default;
+        Double.HorizontalContentAlignment = HorizontalAlignment.Center;
+        Double.VerticalContentAlignment = VerticalAlignment.Center;
+        Double.VerticalAlignment = VerticalAlignment.Stretch;
+        Double.ValueChanged += (sender, e) => ChangeField();
+        Double.FormatString = Field.Properties.Format;
+        return Double;
+    }
+
+    public override void SetSerializedValue(double? value)
+    {
+        Double.Value = (decimal?)value;
+    }
+
+    public override double? GetSerializedValue()
+    {
+        return (double?)Double.Value;
+    }
+
+    public override double GetValue()
+    {
+        return (double?)Double.Value ?? 0.0;
+    }
+
+    public override void SetValue(double value)
+    {
+        Double.Value = (decimal?)value;
+    }
+    protected override bool IsEmpty() => Double.Value == null;
+
+    public override void SetBackground(IBrush brush, bool defaultColour)
+    {
+        Double.Background = brush;
+    }
+}

+ 64 - 0
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFIntegerFieldControl.cs

@@ -0,0 +1,64 @@
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Interactivity;
+using Avalonia.Layout;
+using Avalonia.Media;
+using InABox.Avalonia.Components;
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRS.Avalonia.DigitalForms;
+
+class DFIntegerFieldControl : DigitalFormFieldControl<DFLayoutIntegerField, DFLayoutIntegerFieldProperties, int, int?>
+{
+    private IntegerBox Integer = null!; // late-initialising
+
+    protected override Control Create()
+    {
+        Integer = new IntegerBox();
+        Integer.Value = Field.Properties.Default;
+        Integer.HorizontalContentAlignment = HorizontalAlignment.Center;
+        Integer.VerticalContentAlignment = VerticalAlignment.Center;
+        Integer.VerticalAlignment = VerticalAlignment.Stretch;
+        Integer.ValueChanged += (sender, e) => ChangeField();
+
+        return Integer;
+    }
+
+    public override int? GetSerializedValue()
+    {
+        var value = Integer.Value;
+        if (value != null)
+            return Convert.ToInt32(value);
+        return null;
+    }
+
+    public override void SetSerializedValue(int? value)
+    {
+        Integer.Value = value;
+    }
+
+    public override int GetValue()
+    {
+        var value = Integer.Value;
+        if (value != null)
+            return Convert.ToInt32(value);
+        return 0;
+    }
+
+    public override void SetValue(int value)
+    {
+        Integer.Value = value;
+    }
+    protected override bool IsEmpty() => Integer.Value == null;
+
+    public override void SetBackground(IBrush brush, bool defaultColour)
+    {
+        Integer.Background = brush;
+    }
+}