From 46cba9bd934ac86bdf96a7573ab4fd98e69dc801 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Aneer?=
 <3542167+beyon@users.noreply.github.com>
Date: Tue, 14 Nov 2023 22:32:24 +0100
Subject: [PATCH 1/3] Adds Column and RowDefinitions to DSL in Grid.fs

---
 src/Avalonia.FuncUI/DSL/Panels/Grid.fs | 84 +++++++++++++++++++++++++-
 1 file changed, 83 insertions(+), 1 deletion(-)

diff --git a/src/Avalonia.FuncUI/DSL/Panels/Grid.fs b/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
index 07fe9bc6..2869f0c0 100644
--- a/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
+++ b/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
@@ -1,5 +1,67 @@
 namespace Avalonia.FuncUI.DSL
 
+[<AutoOpen>]
+module ColumnDefinition =  
+    open Avalonia.Controls
+    
+    [<RequireQualifiedAccess>]
+    type ColumnSize =
+    /// The column is auto-sized to fit it's contents
+    | Auto
+    /// The column is sized in device independent pixels
+    | Pixel of float
+    /// The column is sized as a weighted proportion of available space
+    | Star of float
+
+    type ColumnDefinition with
+
+        /// <summary>
+        /// Define the properties of a Grid column
+        /// </summary>
+        /// <param name="columnSize">Declare if the column size should be automatic, proportional or specified in pixels</param>
+        /// <param name="minWidth">Optional minimum column width in pixels</param>
+        /// <param name="maxWidth">Optional maximum column width in pixels</param>
+        static member create(columnSize: ColumnSize , ?minWidth: float, ?maxWidth: float) =
+            let columnDefinition = ColumnDefinition()
+            match columnSize with
+            | ColumnSize.Auto -> columnDefinition.Width <- GridLength(0.0, GridUnitType.Auto)
+            | ColumnSize.Pixel width -> columnDefinition.Width <- GridLength(width, GridUnitType.Pixel)
+            | ColumnSize.Star proportionalWidth -> columnDefinition.Width <- GridLength(proportionalWidth, GridUnitType.Star)
+            minWidth |> Option.iter (fun minW -> columnDefinition.MinWidth <- minW)
+            maxWidth |> Option.iter (fun maxW -> columnDefinition.MaxWidth <- maxW)
+            columnDefinition
+
+[<AutoOpen>]
+module RowDefinition =  
+    open Avalonia.Controls
+
+    [<RequireQualifiedAccess>]
+    type RowSize =
+    /// The row is auto-sized to fit it's contents
+    | Auto
+    /// The row is sized in device independent pixels
+    | Pixel of float
+    /// The row is sized as a weighted proportion of available space
+    | Star of float
+
+    type RowDefinition with
+
+        /// <summary>
+        /// Define the properties of a Grid row
+        /// </summary>
+        /// <param name="rowSize">Declare if row size should be automatic, proportional or specified in pixels</param>
+        /// <param name="minHeight">Optional minimum row height in pixels</param>
+        /// <param name="maxHeight">Optional maximum row height in pixels</param>
+        static member create(rowSize: RowSize, ?minHeight: float, ?maxHeight: float) =
+            let rowDefinition = RowDefinition()
+            match rowSize with
+            | RowSize.Auto -> rowDefinition.Height <- GridLength(0.0, GridUnitType.Auto)
+            | RowSize.Pixel height -> rowDefinition.Height <- GridLength(height, GridUnitType.Pixel)
+            | RowSize.Star proportionalHeight -> rowDefinition.Height <- GridLength(proportionalHeight, GridUnitType.Star)
+            minHeight |> Option.iter (fun minH -> rowDefinition.MinHeight <- minH)
+            maxHeight |> Option.iter (fun maxH -> rowDefinition.MaxHeight <- maxH)
+            rowDefinition
+
 [<AutoOpen>]
 module Grid =  
     open Avalonia.Controls
@@ -107,4 +169,24 @@ module Grid =
             )
 
         static member rowDefinitions<'t when 't :> Grid>(value: string) : IAttr<'t> =
-            value |> RowDefinitions.Parse |> Grid.rowDefinitions 
\ No newline at end of file
+            value |> RowDefinitions.Parse |> Grid.rowDefinitions 
+
+        /// <summary>
+        /// Add a list of column definitions to the grid
+        /// </summary>
+        /// <param name="columns">List of ColumnDefinition defining how the column widths should be divided</param>
+        static member columnDefinitions (columns: ColumnDefinition list) =
+            let colDefs = ColumnDefinitions()
+            columns
+            |> List.iter (fun column -> colDefs.Add(column))
+            Grid.columnDefinitions colDefs
+
+        /// <summary>
+        /// Add a list of row definitions to the grid
+        /// </summary>
+        /// <param name="rows">List of RowDefinition defining how the row heights should be divided</param>
+        static member rowDefinitions (rows: RowDefinition list) =
+            let rowDefs = RowDefinitions()
+            rows
+            |> List.iter (fun row -> rowDefs.Add(row))
+            Grid.rowDefinitions rowDefs

From e1bfc6197269930c4c7baeb4f8c131ff1243b619 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Aneer?=
 <3542167+beyon@users.noreply.github.com>
Date: Tue, 14 Nov 2023 23:09:23 +0100
Subject: [PATCH 2/3] ColumnSize->ColumnWidth, RowSize->RowHeight + name and
 doc-comment edits

---
 src/Avalonia.FuncUI/DSL/Panels/Grid.fs | 40 +++++++++++++-------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/Avalonia.FuncUI/DSL/Panels/Grid.fs b/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
index 2869f0c0..0ea8868c 100644
--- a/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
+++ b/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
@@ -5,12 +5,12 @@ module ColumnDefinition =
     open Avalonia.Controls
     
     [<RequireQualifiedAccess>]
-    type ColumnSize =
-    /// The column is auto-sized to fit it's contents
+    type ColumnWidth =
+    /// Column is auto-sized to fit it's contents
     | Auto
-    /// The column is sized in device independent pixels
+    /// Column is sized in device independent pixels
     | Pixel of float
-    /// The column is sized as a weighted proportion of available space
+    /// Column is sized as a weighted proportion of available space
     | Star of float
 
     type ColumnDefinition with
@@ -18,15 +18,15 @@ module ColumnDefinition =
         /// <summary>
         /// Define the properties of a Grid column
         /// </summary>
-        /// <param name="columnSize">Declare if the column size should be automatic, proportional or specified in pixels</param>
+        /// <param name="width">Specify column width as automatic, proportional or in pixels</param>
         /// <param name="minWidth">Optional minimum column width in pixels</param>
         /// <param name="maxWidth">Optional maximum column width in pixels</param>
-        static member create(columnSize: ColumnSize , ?minWidth: float, ?maxWidth: float) =
+        static member create(width: ColumnWidth, ?minWidth: float, ?maxWidth: float) =
             let columnDefinition = ColumnDefinition()
-            match columnSize with
-            | ColumnSize.Auto -> columnDefinition.Width <- GridLength(0.0, GridUnitType.Auto)
-            | ColumnSize.Pixel width -> columnDefinition.Width <- GridLength(width, GridUnitType.Pixel)
-            | ColumnSize.Star proportionalWidth -> columnDefinition.Width <- GridLength(proportionalWidth, GridUnitType.Star)
+            match width with
+            | ColumnWidth.Auto -> columnDefinition.Width <- GridLength(0.0, GridUnitType.Auto)
+            | ColumnWidth.Pixel width -> columnDefinition.Width <- GridLength(width, GridUnitType.Pixel)
+            | ColumnWidth.Star proportionalWidth -> columnDefinition.Width <- GridLength(proportionalWidth, GridUnitType.Star)
             minWidth |> Option.iter (fun minW -> columnDefinition.MinWidth <- minW)
             maxWidth |> Option.iter (fun maxW -> columnDefinition.MaxWidth <- maxW)
             columnDefinition
@@ -36,12 +36,12 @@ module RowDefinition =
     open Avalonia.Controls
 
     [<RequireQualifiedAccess>]
-    type RowSize =
-    /// The row is auto-sized to fit it's contents
+    type RowHeight =
+    /// Row is auto-sized to fit it's contents
     | Auto
-    /// The row is sized in device independent pixels
+    /// Row is sized in device independent pixels
     | Pixel of float
-    /// The row is sized as a weighted proportion of available space
+    /// Row is sized as a weighted proportion of available space
     | Star of float
 
     type RowDefinition with
@@ -49,15 +49,15 @@ module RowDefinition =
         /// <summary>
         /// Define the properties of a Grid row
         /// </summary>
-        /// <param name="rowSize">Declare if row size should be automatic, proportional or specified in pixels</param>
+        /// <param name="height">Specify row height as automatic, proportional or in pixels</param>
         /// <param name="minHeight">Optional minimum row height in pixels</param>
         /// <param name="maxHeight">Optional maximum row height in pixels</param>
-        static member create(rowSize: RowSize, ?minHeight: float, ?maxHeight: float) =
+        static member create(height: RowHeight, ?minHeight: float, ?maxHeight: float) =
             let rowDefinition = RowDefinition()
-            match rowSize with
-            | RowSize.Auto -> rowDefinition.Height <- GridLength(0.0, GridUnitType.Auto)
-            | RowSize.Pixel height -> rowDefinition.Height <- GridLength(height, GridUnitType.Pixel)
-            | RowSize.Star proportionalHeight -> rowDefinition.Height <- GridLength(proportionalHeight, GridUnitType.Star)
+            match height with
+            | RowHeight.Auto -> rowDefinition.Height <- GridLength(0.0, GridUnitType.Auto)
+            | RowHeight.Pixel height -> rowDefinition.Height <- GridLength(height, GridUnitType.Pixel)
+            | RowHeight.Star proportionalHeight -> rowDefinition.Height <- GridLength(proportionalHeight, GridUnitType.Star)
             minHeight |> Option.iter (fun minH -> rowDefinition.MinHeight <- minH)
             maxHeight |> Option.iter (fun maxH -> rowDefinition.MaxHeight <- maxH)
             rowDefinition

From fc2d1615c21b5e69fccfbd385bb99d62a254cd9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Aneer?=
 <3542167+beyon@users.noreply.github.com>
Date: Wed, 15 Nov 2023 16:38:36 +0100
Subject: [PATCH 3/3] Change Column/RowDefinition DU to struct DU

---
 src/Avalonia.FuncUI/DSL/Panels/Grid.fs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/Avalonia.FuncUI/DSL/Panels/Grid.fs b/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
index 0ea8868c..e3a44e76 100644
--- a/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
+++ b/src/Avalonia.FuncUI/DSL/Panels/Grid.fs
@@ -4,14 +4,15 @@ namespace Avalonia.FuncUI.DSL
 module ColumnDefinition =  
     open Avalonia.Controls
     
+    [<Struct>]
     [<RequireQualifiedAccess>]
     type ColumnWidth =
     /// Column is auto-sized to fit it's contents
     | Auto
     /// Column is sized in device independent pixels
-    | Pixel of float
+    | Pixel of widthInPixels: float
     /// Column is sized as a weighted proportion of available space
-    | Star of float
+    | Star of proportion: float
 
     type ColumnDefinition with
 
@@ -35,14 +36,15 @@ module ColumnDefinition =
 module RowDefinition =  
     open Avalonia.Controls
 
+    [<Struct>]
     [<RequireQualifiedAccess>]
     type RowHeight =
     /// Row is auto-sized to fit it's contents
     | Auto
     /// Row is sized in device independent pixels
-    | Pixel of float
+    | Pixel of heightInPixels: float
     /// Row is sized as a weighted proportion of available space
-    | Star of float
+    | Star of proportion: float
 
     type RowDefinition with