Browse Source

avalonia: added digital forms time field

Kenric Nugteren 2 months ago
parent
commit
e233f40267

+ 42 - 0
PRS.Avalonia/PRS.Avalonia/Components/FormsEditor/Fields/DFTimeFieldControl.cs

@@ -0,0 +1,42 @@
+using Avalonia.Controls;
+using Avalonia.Media;
+using InABox.Avalonia.Components;
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRS.Avalonia.DigitalForms;
+
+class DFTimeFieldControl : DigitalFormFieldControl<DFLayoutTimeField, DFLayoutTimeFieldProperties, TimeSpan, TimeSpan?>
+{
+    private TimeSelectorButton Time = null!; // late-initialising
+
+    protected override Control Create()
+    {
+        Time = new TimeSelectorButton();
+        var def = Field.Properties.Default;
+        Time.Time = def == default ? DateTime.Now.TimeOfDay : def;
+        Time.TimeChanged += (sender, e) => ChangeField();
+        
+        return Time;
+    }
+
+    public override TimeSpan? GetSerializedValue() => Time.Time;
+
+    public override void SetSerializedValue(TimeSpan? value) => Time.Time = value;
+
+    public override TimeSpan GetValue() => Time.Time ?? TimeSpan.MinValue;
+
+    public override void SetValue(TimeSpan value) => Time.Time = value;
+
+    protected override bool IsEmpty() => Time.Time == null || Time.Time == TimeSpan.MinValue;
+
+    public override void SetBackground(IBrush brush, bool defaultColour)
+    {
+        Time.Background = brush;
+    }
+}

+ 6 - 0
PRS.Avalonia/PRS.Avalonia/Theme/FormControlStyles.axaml

@@ -11,6 +11,12 @@
         <Setter Property="Foreground" Value="{DynamicResource PrsButtonForeground}" />
         <Setter Property="CornerRadius" Value="{DynamicResource PrsCornerRadius}" />
 	</Style>
+	<Style Selector=":is(forms|DigitalFormControl).DFFieldControl components|TimeSelectorButton">
+        <Setter Property="BorderBrush" Value="{DynamicResource PrsButtonBorder}" />
+        <Setter Property="BorderThickness" Value="{DynamicResource PrsBorderThickness}"/>
+        <Setter Property="Foreground" Value="{DynamicResource PrsButtonForeground}" />
+        <Setter Property="CornerRadius" Value="{DynamicResource PrsCornerRadius}" />
+	</Style>
 	
 	<Style Selector=":is(forms|DigitalFormControl).DFFieldControl forms|RadioOptionControl">
         <Setter Property="BorderBrush" Value="{DynamicResource PrsButtonBorder}" />