Browse Source

Initial thinkings for form layout

Kenric Nugteren 1 year ago
parent
commit
7f606c2b64

+ 56 - 0
InABox.Core/DigitalForms/NewLayout/Containers/GridLayout.cs

@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace InABox.Core.DigitalForms.NewLayout
+{
+    public enum GridLayoutLengthType
+    {
+        Auto,
+        Star,
+        Value
+    }
+
+    public class GridLayoutLength
+    {
+        public static GridLayoutLength Auto => new GridLayoutLength(GridLayoutLengthType.Auto, 1);
+
+        public GridLayoutLengthType Type { get; set; }
+
+        public double Value { get; set; }
+
+        public GridLayoutLength(GridLayoutLengthType type, double value)
+        {
+            Type = type;
+            Value = value;
+        }
+    }
+
+    public class FormControlGridCell
+    {
+        public int Row { get; set; } = 0;
+
+        public int RowSpan { get; set; } = 1;
+
+        public int Column { get; set; } = 0;
+
+        public int ColumnSpan { get; set; } = 1;
+
+        public Guid ControlID {  get; set; }
+    }
+
+    /// <summary>
+    /// A container control that lays its items out in a grid.
+    /// </summary>
+    /// <remarks>
+    /// Rows and columns begin counting at 0.
+    /// </remarks>
+    public class FormControlGrid : FormControl
+    {
+        public List<GridLayoutLength> RowLengths { get; set; } = new List<GridLayoutLength>();
+
+        public List<GridLayoutLength> ColumnLengths { get; set; } = new List<GridLayoutLength>();
+
+        public List<FormControlGridCell> Controls { get; set; } = new List<FormControlGridCell>();
+    }
+}

+ 18 - 0
InABox.Core/DigitalForms/NewLayout/Containers/TabControl.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace InABox.Core.DigitalForms.NewLayout
+{
+    public class TabControlTab
+    {
+        public string Title { get; set; } = "";
+
+        public Guid ControlID { get; set; }
+    }
+
+    public class TabControl : FormControl
+    {
+        public List<TabControlTab> Tabs { get; set; } = new List<TabControlTab>();
+    }
+}

+ 20 - 0
InABox.Core/DigitalForms/NewLayout/FormControl.cs

@@ -0,0 +1,20 @@
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
+using System.Text;
+using System.Xml.Linq;
+
+namespace InABox.Core.DigitalForms.NewLayout
+{
+    /// <summary>
+    /// A form control is <i>any</i> object which can be inside a <see cref="FormLayout"/>.
+    /// </summary>
+    public class FormControl
+    {
+        /// <summary>
+        /// All <see cref="FormControl"/>s have an <see cref="ID"/>, which the <see cref="FormLayout"/> uses to put them into containers and layouts.
+        /// </summary>
+        public Guid ID { get; set; } = Guid.NewGuid();
+    }
+}

+ 23 - 0
InABox.Core/DigitalForms/NewLayout/FormLayout.cs

@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace InABox.Core.DigitalForms.NewLayout
+{
+    public class FormLayout
+    {
+        public FormControlGrid Grid { get; set; } = new FormControlGrid();
+
+        private Dictionary<Guid, FormControl> Controls { get; set; } = new Dictionary<Guid, FormControl>();
+
+        public FormControl? GetControl(Guid id)
+        {
+            return Controls.GetValueOrDefault(id);
+        }
+
+        public void AddControl(FormControl control)
+        {
+            Controls.Add(control.ID, control);
+        }
+    }
+}