Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLariviere committed Nov 26, 2023
1 parent 3cd1735 commit d914984
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 117 deletions.
10 changes: 7 additions & 3 deletions src/Fabulous.XamarinForms/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) =
Expand Down Expand Up @@ -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
Expand Down
72 changes: 37 additions & 35 deletions src/Fabulous.XamarinForms/Views/Collections/GridItemsLayout.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemsLayoutOrientation> 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<ItemsLayoutOrientation> 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

[<AutoOpen>]
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))

[<Extension>]
type GridItemsLayoutExtensions =
[<Extension>]
static member inline horizontalItemSpacing(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: float) =
this.AddScalar(GridItemsLayout.HorizontalItemSpacing.WithValue(value))

[<Extension>]
static member inline span(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: int) =
this.AddScalar(GridItemsLayout.Span.WithValue(value))

[<Extension>]
static member inline verticalItemSpacing(this: WidgetBuilder<'msg, #IGridItemsLayout>, value: float) =
this.AddScalar(GridItemsLayout.VerticalItemSpacing.WithValue(value))

/// <summary>Link a ViewRef to access the direct GridItemsLayout control instance</summary>
[<Extension>]
static member inline reference(this: WidgetBuilder<'msg, IListView>, value: ViewRef<GridItemsLayout>) =
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))
46 changes: 23 additions & 23 deletions src/Fabulous.XamarinForms/Views/Collections/LinearItemsLayout.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemsLayoutOrientation> attr.NumericValue

LinearItemsLayout(orientation)
)

let ItemSpacing = Attributes.defineBindableWithEquality<float> 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<ItemsLayoutOrientation> attr.NumericValue

LinearItemsLayout(orientation))

let ItemSpacing =
Attributes.defineBindableWithEquality<float> LinearItemsLayout.ItemSpacingProperty

[<AutoOpen>]
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))

[<Extension>]
type LinearItemsLayoutExtensions =
[<Extension>]
static member inline itemSpacing(this: WidgetBuilder<'msg, #ILinearItemsLayout>, value: float) =
this.AddScalar(LinearItemsLayout.ItemSpacing.WithValue(value))

/// <summary>Link a ViewRef to access the direct LinearItemsLayout control instance</summary>
[<Extension>]
static member inline reference(this: WidgetBuilder<'msg, IListView>, value: ViewRef<LinearItemsLayout>) =
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))
this.AddScalar(ViewRefAttributes.ViewRef.WithValue(value.Unbox))
61 changes: 31 additions & 30 deletions src/Fabulous.XamarinForms/Views/Collections/_GroupableItemsView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GroupedWidgetItems>
"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))
let GroupedItemsSource =
Attributes.defineSimpleScalar<GroupedWidgetItems>
"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))
21 changes: 14 additions & 7 deletions src/Fabulous.XamarinForms/Views/Collections/_ItemsLayout.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemsLayoutOrientation> = Attributes.defineSmallScalar "ItemsLayout_Orientation" SmallScalars.IntEnum.decode (fun _ _ _ -> ())
let SnapPointsAlignment = Attributes.defineBindableEnum<SnapPointsAlignment> ItemsLayout.SnapPointsAlignmentProperty
let SnapPointsType = Attributes.defineBindableEnum<SnapPointsType> ItemsLayout.SnapPointsTypeProperty

let Orientation: SmallScalarAttributeDefinition<ItemsLayoutOrientation> =
Attributes.defineSmallScalar "ItemsLayout_Orientation" SmallScalars.IntEnum.decode (fun _ _ _ -> ())

let SnapPointsAlignment =
Attributes.defineBindableEnum<SnapPointsAlignment> ItemsLayout.SnapPointsAlignmentProperty

let SnapPointsType =
Attributes.defineBindableEnum<SnapPointsType> ItemsLayout.SnapPointsTypeProperty

[<Extension>]
type ItemsLayoutModifiers =
[<Extension>]
static member snapPointsAlignment(this: WidgetBuilder<'msg, #IItemsLayout>, value: SnapPointsAlignment) =
this.AddScalar(ItemsLayout.SnapPointsAlignment.WithValue(value))

[<Extension>]
static member snapPointsType(this: WidgetBuilder<'msg, #IItemsLayout>, value: SnapPointsType) =
this.AddScalar(ItemsLayout.SnapPointsType.WithValue(value))
this.AddScalar(ItemsLayout.SnapPointsType.WithValue(value))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Fabulous.XamarinForms

type IReordableItemsView = inherit IGroupableItemsView

type IReordableItemsView =
inherit IGroupableItemsView
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ open System.Runtime.CompilerServices
open Xamarin.Forms
open Fabulous

type ISelectableItemsView = inherit IStructuredItemsView
type ISelectableItemsView =
inherit IStructuredItemsView

module SelectableItemsView =
let SelectionMode =
Attributes.defineBindableEnum<SelectionMode> CollectionView.SelectionModeProperty

let SelectionChanged =
Attributes.defineEvent<SelectionChangedEventArgs> "CollectionView_SelectionChanged" (fun target -> (target :?> CollectionView).SelectionChanged)

[<Extension>]
type SelectableItemsView =
[<Extension>]
Expand All @@ -21,4 +22,4 @@ type SelectableItemsView =

[<Extension>]
static member inline onSelectionChanged(this: WidgetBuilder<'msg, #ISelectableItemsView>, onSelectionChanged: SelectionChangedEventArgs -> 'msg) =
this.AddScalar(SelectableItemsView.SelectionChanged.WithValue(fun args -> onSelectionChanged args |> box))
this.AddScalar(SelectableItemsView.SelectionChanged.WithValue(fun args -> onSelectionChanged args |> box))
29 changes: 18 additions & 11 deletions src/Fabulous.XamarinForms/Views/Collections/_StructuredItemsView.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemSizingStrategy> StructuredItemsView.ItemSizingStrategyProperty

let ItemsLayout = Attributes.defineBindableWidget StructuredItemsView.ItemsLayoutProperty


let ItemsSizingStrategy =
Attributes.defineBindableEnum<ItemSizingStrategy> StructuredItemsView.ItemSizingStrategyProperty

let ItemsLayout =
Attributes.defineBindableWidget StructuredItemsView.ItemsLayoutProperty

[<Extension>]
type StructuredItemsViewModifiers =
[<Extension>]
Expand All @@ -24,7 +27,7 @@ type StructuredItemsViewModifiers =
content: WidgetBuilder<'msg, 'contentMarker>
) =
this.AddWidget(StructuredItemsView.Footer.WithValue(content.Compile()))

[<Extension>]
static member inline header<'msg, 'marker, 'contentMarker when 'marker :> IStructuredItemsView and 'contentMarker :> IView>
(
Expand All @@ -34,13 +37,17 @@ type StructuredItemsViewModifiers =
this.AddWidget(StructuredItemsView.Header.WithValue(content.Compile()))

[<Extension>]
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))

[<Extension>]
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()))
this.AddWidget(StructuredItemsView.ItemsLayout.WithValue(content.Compile()))
Loading

0 comments on commit d914984

Please sign in to comment.