From d914984214099fe1c34e205e58d10c8a43f222f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20Larivi=C3=A8re?= Date: Sun, 26 Nov 2023 20:09:07 +0100 Subject: [PATCH] Format code --- src/Fabulous.XamarinForms/Program.fs | 10 ++- .../Views/Collections/GridItemsLayout.fs | 72 ++++++++++--------- .../Views/Collections/LinearItemsLayout.fs | 46 ++++++------ .../Views/Collections/_GroupableItemsView.fs | 61 ++++++++-------- .../Views/Collections/_ItemsLayout.fs | 21 ++++-- .../Collections/_ReorderableItemsView.fs | 4 +- .../Views/Collections/_SelectableItemsView.fs | 7 +- .../Views/Collections/_StructuredItemsView.fs | 29 +++++--- src/Fabulous.XamarinForms/Widgets.fs | 6 +- 9 files changed, 139 insertions(+), 117 deletions(-) diff --git a/src/Fabulous.XamarinForms/Program.fs b/src/Fabulous.XamarinForms/Program.fs index 28b1f46..2d51bca 100644 --- a/src/Fabulous.XamarinForms/Program.fs +++ b/src/Fabulous.XamarinForms/Program.fs @@ -16,7 +16,7 @@ module ViewHelpers = match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = def.Key) scalarAttrs with | None -> ValueNone | Some attr -> ValueSome(unbox<'data> attr.Value) - + let private tryGetScalarValue (widget: Widget) (def: SimpleScalarAttributeDefinition<'data>) = match widget.ScalarAttributes with | ValueNone -> ValueNone @@ -83,7 +83,7 @@ module ViewHelpers = true | _ -> true - + /// Given the Orientation of the ItemsLayout is passed to the constructor, it can't be changed later. /// If the orientation changes, a new ItemsLayout has to be created. and private canReuseItemsLayout (prev: Widget) (curr: Widget) = @@ -134,7 +134,11 @@ module Program = define init update view /// Create a program using an MVU loop. Add support for Cmd - let statefulWithCmdMemo (init: 'arg -> 'model * Cmd<'msg>) (update: 'msg -> 'model -> 'model * Cmd<'msg>) (view: 'model -> WidgetBuilder<'msg, Memoized<#IApplication>>) = + let statefulWithCmdMemo + (init: 'arg -> 'model * Cmd<'msg>) + (update: 'msg -> 'model -> 'model * Cmd<'msg>) + (view: 'model -> WidgetBuilder<'msg, Memoized<#IApplication>>) + = define init update view /// Create a program using an MVU loop. Add support for CmdMsg diff --git a/src/Fabulous.XamarinForms/Views/Collections/GridItemsLayout.fs b/src/Fabulous.XamarinForms/Views/Collections/GridItemsLayout.fs index c39c75f..5464ccf 100644 --- a/src/Fabulous.XamarinForms/Views/Collections/GridItemsLayout.fs +++ b/src/Fabulous.XamarinForms/Views/Collections/GridItemsLayout.fs @@ -5,60 +5,62 @@ open Fabulous open Fabulous.ScalarAttributeDefinitions open Xamarin.Forms -type IGridItemsLayout = inherit Fabulous.XamarinForms.IItemsLayout +type IGridItemsLayout = + inherit Fabulous.XamarinForms.IItemsLayout module GridItemsLayout = let Span = Attributes.defineBindableInt GridItemsLayout.SpanProperty - - let WidgetKey = Widgets.registerWithFactory(fun widget -> - let span = - match widget.ScalarAttributes with - | ValueNone -> ValueNone - | ValueSome attrs -> - match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = Span.Key) attrs with - | None -> ValueNone - | Some attr -> ValueSome (SmallScalars.Int.decode attr.NumericValue) - - let orientation = - match widget.ScalarAttributes with - | ValueNone -> failwith "GridItemsLayout must have an orientation attribute" - | ValueSome attrs -> - match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = ItemsLayout.Orientation.Key) attrs with - | None -> failwith "GridItemsLayout must have an orientation attribute" - | Some attr -> SmallScalars.IntEnum.decode attr.NumericValue - - match span with - | ValueNone -> GridItemsLayout(orientation) - | ValueSome span -> GridItemsLayout(span, orientation) - ) - - let HorizontalItemSpacing = Attributes.defineBindableFloat GridItemsLayout.HorizontalItemSpacingProperty - let VerticalItemSpacing = Attributes.defineBindableFloat GridItemsLayout.VerticalItemSpacingProperty + + let WidgetKey = + Widgets.registerWithFactory(fun widget -> + let span = + match widget.ScalarAttributes with + | ValueNone -> ValueNone + | ValueSome attrs -> + match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = Span.Key) attrs with + | None -> ValueNone + | Some attr -> ValueSome(SmallScalars.Int.decode attr.NumericValue) + + let orientation = + match widget.ScalarAttributes with + | ValueNone -> failwith "GridItemsLayout must have an orientation attribute" + | ValueSome attrs -> + match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = ItemsLayout.Orientation.Key) attrs with + | None -> failwith "GridItemsLayout must have an orientation attribute" + | Some attr -> SmallScalars.IntEnum.decode attr.NumericValue + + match span with + | ValueNone -> GridItemsLayout(orientation) + | ValueSome span -> GridItemsLayout(span, orientation)) + + let HorizontalItemSpacing = + Attributes.defineBindableFloat GridItemsLayout.HorizontalItemSpacingProperty + + let VerticalItemSpacing = + Attributes.defineBindableFloat GridItemsLayout.VerticalItemSpacingProperty [] module GridItemsBuilders = type Fabulous.XamarinForms.View with + static member inline GridItemsLayout(orientation: ItemsLayoutOrientation) = - WidgetBuilder<'msg, IGridItemsLayout>( - GridItemsLayout.WidgetKey, - ItemsLayout.Orientation.WithValue(orientation) - ) - + WidgetBuilder<'msg, IGridItemsLayout>(GridItemsLayout.WidgetKey, ItemsLayout.Orientation.WithValue(orientation)) + [] type GridItemsLayoutExtensions = [] static member inline horizontalItemSpacing(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: float) = this.AddScalar(GridItemsLayout.HorizontalItemSpacing.WithValue(value)) - + [] static member inline span(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: int) = this.AddScalar(GridItemsLayout.Span.WithValue(value)) - + [] static member inline verticalItemSpacing(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: float) = this.AddScalar(GridItemsLayout.VerticalItemSpacing.WithValue(value)) - + /// Link a ViewRef to access the direct GridItemsLayout control instance [] static member inline reference(this: WidgetBuilder<'msg, IListView>, value: ViewRef) = - this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox)) \ No newline at end of file + this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox)) diff --git a/src/Fabulous.XamarinForms/Views/Collections/LinearItemsLayout.fs b/src/Fabulous.XamarinForms/Views/Collections/LinearItemsLayout.fs index c2cf38a..db8ef1c 100644 --- a/src/Fabulous.XamarinForms/Views/Collections/LinearItemsLayout.fs +++ b/src/Fabulous.XamarinForms/Views/Collections/LinearItemsLayout.fs @@ -4,39 +4,39 @@ open System.Runtime.CompilerServices open Fabulous open Xamarin.Forms -type ILinearItemsLayout = inherit Fabulous.XamarinForms.IItemsLayout - -module LinearItemsLayout = - let WidgetKey = Widgets.registerWithFactory(fun widget -> - let orientation = - match widget.ScalarAttributes with - | ValueNone -> failwith "LinearItemsLayout must have an orientation attribute" - | ValueSome attrs -> - match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = ItemsLayout.Orientation.Key) attrs with - | None -> failwith "LinearItemsLayout must have an orientation attribute" - | Some attr -> SmallScalars.IntEnum.decode attr.NumericValue - - LinearItemsLayout(orientation) - ) - - let ItemSpacing = Attributes.defineBindableWithEquality LinearItemsLayout.ItemSpacingProperty +type ILinearItemsLayout = + inherit Fabulous.XamarinForms.IItemsLayout + +module LinearItemsLayout = + let WidgetKey = + Widgets.registerWithFactory(fun widget -> + let orientation = + match widget.ScalarAttributes with + | ValueNone -> failwith "LinearItemsLayout must have an orientation attribute" + | ValueSome attrs -> + match Array.tryFind (fun (attr: ScalarAttribute) -> attr.Key = ItemsLayout.Orientation.Key) attrs with + | None -> failwith "LinearItemsLayout must have an orientation attribute" + | Some attr -> SmallScalars.IntEnum.decode attr.NumericValue + + LinearItemsLayout(orientation)) + + let ItemSpacing = + Attributes.defineBindableWithEquality LinearItemsLayout.ItemSpacingProperty [] module LinearItemsBuilders = type Fabulous.XamarinForms.View with + static member inline LinearItemsLayout(orientation: ItemsLayoutOrientation) = - WidgetBuilder<'msg, ILinearItemsLayout>( - LinearItemsLayout.WidgetKey, - ItemsLayout.Orientation.WithValue(orientation) - ) - + WidgetBuilder<'msg, ILinearItemsLayout>(LinearItemsLayout.WidgetKey, ItemsLayout.Orientation.WithValue(orientation)) + [] type LinearItemsLayoutExtensions = [] static member inline itemSpacing(this: WidgetBuilder<'msg, #ILinearItemsLayout>, value: float) = this.AddScalar(LinearItemsLayout.ItemSpacing.WithValue(value)) - + /// Link a ViewRef to access the direct LinearItemsLayout control instance [] static member inline reference(this: WidgetBuilder<'msg, IListView>, value: ViewRef) = - this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox)) \ No newline at end of file + this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox)) diff --git a/src/Fabulous.XamarinForms/Views/Collections/_GroupableItemsView.fs b/src/Fabulous.XamarinForms/Views/Collections/_GroupableItemsView.fs index 3d79f37..87a058a 100644 --- a/src/Fabulous.XamarinForms/Views/Collections/_GroupableItemsView.fs +++ b/src/Fabulous.XamarinForms/Views/Collections/_GroupableItemsView.fs @@ -4,35 +4,36 @@ open Fabulous open Fabulous.XamarinForms open Xamarin.Forms -type IGroupableItemsView = inherit ISelectableItemsView +type IGroupableItemsView = + inherit ISelectableItemsView module GroupableItemsView = - let GroupedItemsSource = - Attributes.defineSimpleScalar - "CollectionView_GroupedItemsSource" - (fun a b -> ScalarAttributeComparers.equalityCompare a.OriginalItems b.OriginalItems) - (fun _ newValueOpt node -> - let collectionView = node.Target :?> GroupableItemsView - - match newValueOpt with - | ValueNone -> - collectionView.IsGrouped <- false - collectionView.ClearValue(CollectionView.ItemsSourceProperty) - collectionView.ClearValue(CollectionView.GroupHeaderTemplateProperty) - collectionView.ClearValue(CollectionView.GroupFooterTemplateProperty) - collectionView.ClearValue(CollectionView.ItemTemplateProperty) - - | ValueSome value -> - collectionView.IsGrouped <- true - - collectionView.SetValue(CollectionView.ItemTemplateProperty, WidgetDataTemplateSelector(node, unbox >> value.ItemTemplate)) - - collectionView.SetValue(CollectionView.GroupHeaderTemplateProperty, WidgetDataTemplateSelector(node, unbox >> value.HeaderTemplate)) - - if value.FooterTemplate.IsSome then - collectionView.SetValue( - CollectionView.GroupFooterTemplateProperty, - WidgetDataTemplateSelector(node, unbox >> value.FooterTemplate.Value) - ) - - collectionView.SetValue(CollectionView.ItemsSourceProperty, value.OriginalItems)) \ No newline at end of file + let GroupedItemsSource = + Attributes.defineSimpleScalar + "CollectionView_GroupedItemsSource" + (fun a b -> ScalarAttributeComparers.equalityCompare a.OriginalItems b.OriginalItems) + (fun _ newValueOpt node -> + let collectionView = node.Target :?> GroupableItemsView + + match newValueOpt with + | ValueNone -> + collectionView.IsGrouped <- false + collectionView.ClearValue(CollectionView.ItemsSourceProperty) + collectionView.ClearValue(CollectionView.GroupHeaderTemplateProperty) + collectionView.ClearValue(CollectionView.GroupFooterTemplateProperty) + collectionView.ClearValue(CollectionView.ItemTemplateProperty) + + | ValueSome value -> + collectionView.IsGrouped <- true + + collectionView.SetValue(CollectionView.ItemTemplateProperty, WidgetDataTemplateSelector(node, unbox >> value.ItemTemplate)) + + collectionView.SetValue(CollectionView.GroupHeaderTemplateProperty, WidgetDataTemplateSelector(node, unbox >> value.HeaderTemplate)) + + if value.FooterTemplate.IsSome then + collectionView.SetValue( + CollectionView.GroupFooterTemplateProperty, + WidgetDataTemplateSelector(node, unbox >> value.FooterTemplate.Value) + ) + + collectionView.SetValue(CollectionView.ItemsSourceProperty, value.OriginalItems)) diff --git a/src/Fabulous.XamarinForms/Views/Collections/_ItemsLayout.fs b/src/Fabulous.XamarinForms/Views/Collections/_ItemsLayout.fs index 12288db..b2ab724 100644 --- a/src/Fabulous.XamarinForms/Views/Collections/_ItemsLayout.fs +++ b/src/Fabulous.XamarinForms/Views/Collections/_ItemsLayout.fs @@ -5,19 +5,26 @@ open Fabulous open Fabulous.ScalarAttributeDefinitions open Xamarin.Forms -type IItemsLayout = interface end +type IItemsLayout = + interface + end module ItemsLayout = - let Orientation: SmallScalarAttributeDefinition = Attributes.defineSmallScalar "ItemsLayout_Orientation" SmallScalars.IntEnum.decode (fun _ _ _ -> ()) - let SnapPointsAlignment = Attributes.defineBindableEnum ItemsLayout.SnapPointsAlignmentProperty - let SnapPointsType = Attributes.defineBindableEnum ItemsLayout.SnapPointsTypeProperty - + let Orientation: SmallScalarAttributeDefinition = + Attributes.defineSmallScalar "ItemsLayout_Orientation" SmallScalars.IntEnum.decode (fun _ _ _ -> ()) + + let SnapPointsAlignment = + Attributes.defineBindableEnum ItemsLayout.SnapPointsAlignmentProperty + + let SnapPointsType = + Attributes.defineBindableEnum ItemsLayout.SnapPointsTypeProperty + [] type ItemsLayoutModifiers = [] static member snapPointsAlignment(this: WidgetBuilder<'msg, #IItemsLayout>, value: SnapPointsAlignment) = this.AddScalar(ItemsLayout.SnapPointsAlignment.WithValue(value)) - + [] static member snapPointsType(this: WidgetBuilder<'msg, #IItemsLayout>, value: SnapPointsType) = - this.AddScalar(ItemsLayout.SnapPointsType.WithValue(value)) \ No newline at end of file + this.AddScalar(ItemsLayout.SnapPointsType.WithValue(value)) diff --git a/src/Fabulous.XamarinForms/Views/Collections/_ReorderableItemsView.fs b/src/Fabulous.XamarinForms/Views/Collections/_ReorderableItemsView.fs index ae3dfcf..cf76e7f 100644 --- a/src/Fabulous.XamarinForms/Views/Collections/_ReorderableItemsView.fs +++ b/src/Fabulous.XamarinForms/Views/Collections/_ReorderableItemsView.fs @@ -1,4 +1,4 @@ namespace Fabulous.XamarinForms -type IReordableItemsView = inherit IGroupableItemsView - +type IReordableItemsView = + inherit IGroupableItemsView diff --git a/src/Fabulous.XamarinForms/Views/Collections/_SelectableItemsView.fs b/src/Fabulous.XamarinForms/Views/Collections/_SelectableItemsView.fs index 092abd0..ffb2ed1 100644 --- a/src/Fabulous.XamarinForms/Views/Collections/_SelectableItemsView.fs +++ b/src/Fabulous.XamarinForms/Views/Collections/_SelectableItemsView.fs @@ -4,7 +4,8 @@ open System.Runtime.CompilerServices open Xamarin.Forms open Fabulous -type ISelectableItemsView = inherit IStructuredItemsView +type ISelectableItemsView = + inherit IStructuredItemsView module SelectableItemsView = let SelectionMode = @@ -12,7 +13,7 @@ module SelectableItemsView = let SelectionChanged = Attributes.defineEvent "CollectionView_SelectionChanged" (fun target -> (target :?> CollectionView).SelectionChanged) - + [] type SelectableItemsView = [] @@ -21,4 +22,4 @@ type SelectableItemsView = [] static member inline onSelectionChanged(this: WidgetBuilder<'msg, #ISelectableItemsView>, onSelectionChanged: SelectionChangedEventArgs -> 'msg) = - this.AddScalar(SelectableItemsView.SelectionChanged.WithValue(fun args -> onSelectionChanged args |> box)) \ No newline at end of file + this.AddScalar(SelectableItemsView.SelectionChanged.WithValue(fun args -> onSelectionChanged args |> box)) diff --git a/src/Fabulous.XamarinForms/Views/Collections/_StructuredItemsView.fs b/src/Fabulous.XamarinForms/Views/Collections/_StructuredItemsView.fs index 6b4f6c6..bfc6dfd 100644 --- a/src/Fabulous.XamarinForms/Views/Collections/_StructuredItemsView.fs +++ b/src/Fabulous.XamarinForms/Views/Collections/_StructuredItemsView.fs @@ -4,17 +4,20 @@ open System.Runtime.CompilerServices open Fabulous open Xamarin.Forms -type IStructuredItemsView = inherit IItemsView +type IStructuredItemsView = + inherit IItemsView module StructuredItemsView = let Footer = Attributes.defineBindableWidget StructuredItemsView.FooterProperty - + let Header = Attributes.defineBindableWidget StructuredItemsView.HeaderProperty - - let ItemsSizingStrategy = Attributes.defineBindableEnum StructuredItemsView.ItemSizingStrategyProperty - - let ItemsLayout = Attributes.defineBindableWidget StructuredItemsView.ItemsLayoutProperty - + + let ItemsSizingStrategy = + Attributes.defineBindableEnum StructuredItemsView.ItemSizingStrategyProperty + + let ItemsLayout = + Attributes.defineBindableWidget StructuredItemsView.ItemsLayoutProperty + [] type StructuredItemsViewModifiers = [] @@ -24,7 +27,7 @@ type StructuredItemsViewModifiers = content: WidgetBuilder<'msg, 'contentMarker> ) = this.AddWidget(StructuredItemsView.Footer.WithValue(content.Compile())) - + [] static member inline header<'msg, 'marker, 'contentMarker when 'marker :> IStructuredItemsView and 'contentMarker :> IView> ( @@ -34,13 +37,17 @@ type StructuredItemsViewModifiers = this.AddWidget(StructuredItemsView.Header.WithValue(content.Compile())) [] - static member inline itemsSizingStrategy<'msg, 'marker when 'marker :> IStructuredItemsView>(this: WidgetBuilder<'msg, 'marker>, value: ItemSizingStrategy) = + static member inline itemsSizingStrategy<'msg, 'marker when 'marker :> IStructuredItemsView> + ( + this: WidgetBuilder<'msg, 'marker>, + value: ItemSizingStrategy + ) = this.AddScalar(StructuredItemsView.ItemsSizingStrategy.WithValue(value)) - + [] static member inline itemsLayout<'msg, 'marker, 'contentMarker when 'marker :> IStructuredItemsView and 'contentMarker :> Fabulous.XamarinForms.IItemsLayout> ( this: WidgetBuilder<'msg, 'marker>, content: WidgetBuilder<'msg, 'contentMarker> ) = - this.AddWidget(StructuredItemsView.ItemsLayout.WithValue(content.Compile())) \ No newline at end of file + this.AddWidget(StructuredItemsView.ItemsLayout.WithValue(content.Compile())) diff --git a/src/Fabulous.XamarinForms/Widgets.fs b/src/Fabulous.XamarinForms/Widgets.fs index 775cd86..02da67e 100644 --- a/src/Fabulous.XamarinForms/Widgets.fs +++ b/src/Fabulous.XamarinForms/Widgets.fs @@ -65,15 +65,15 @@ module Widgets = WidgetDefinitionStore.set key definition key - + let rec registerWithFactory<'T when 'T :> Xamarin.Forms.BindableObject> (factory: Widget -> 'T) = registerWithFactoryAndAdditionalSetup<'T> factory (fun _ _ -> ()) - + let registerWithAdditionalSetup<'T when 'T :> Xamarin.Forms.BindableObject and 'T: (new: unit -> 'T)> (additionalSetup: 'T -> IViewNode -> unit) = registerWithFactoryAndAdditionalSetup<'T> (fun _ -> new 'T()) additionalSetup let register<'T when 'T :> Xamarin.Forms.BindableObject and 'T: (new: unit -> 'T)> () = - registerWithFactory<'T> (fun _ -> new 'T()) + registerWithFactory<'T>(fun _ -> new 'T()) module WidgetHelpers = let inline compileSeq (items: seq>) =