From 01c52d27f7166b8e42fbf3544840c556d1c2172f Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 13 May 2024 21:20:06 +0100 Subject: [PATCH] Replace StackList with AttributesBundle --- .../APISketchTests/TestUI.Widgets.fs | 8 +++-- src/Fabulous/Builders.fs | 30 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs b/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs index 71543f877..47b671343 100644 --- a/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs +++ b/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs @@ -155,9 +155,11 @@ module TestUI_Widgets = ) static member Stack<'msg, 'marker when 'marker :> IMarker>() = - CollectionBuilder<'msg, TestStackMarker, 'marker>(TestStackKey, StackList.empty(), Attributes.Container.Children) - - + CollectionBuilder<'msg, TestStackMarker, 'marker>( + TestStackKey, + Attributes.Container.Children, + AttributesBundle(StackList.empty(), ValueNone, ValueNone) + ) [] type CollectionBuilderExtensions = diff --git a/src/Fabulous/Builders.fs b/src/Fabulous/Builders.fs index e9c883252..5ade1d542 100644 --- a/src/Fabulous/Builders.fs +++ b/src/Fabulous/Builders.fs @@ -125,36 +125,45 @@ type Content<'msg> = { Widgets: MutStackArray1.T } type CollectionBuilder<'msg, 'marker, 'itemMarker> = struct val WidgetKey: WidgetKey - val Scalars: StackList val Attr: WidgetCollectionAttributeDefinition + val Scalars: AttributesBundle - new(widgetKey: WidgetKey, scalars: StackList, attr: WidgetCollectionAttributeDefinition) = + new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalars: AttributesBundle) = { WidgetKey = widgetKey Scalars = scalars Attr = attr } new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition) = { WidgetKey = widgetKey - Scalars = StackList.empty() + Scalars = AttributesBundle(StackList.empty(), ValueNone, ValueNone) Attr = attr } new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalar: ScalarAttribute) = { WidgetKey = widgetKey - Scalars = StackList.one scalar + Scalars = AttributesBundle(StackList.one scalar, ValueNone, ValueNone) Attr = attr } new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalarA: ScalarAttribute, scalarB: ScalarAttribute) = { WidgetKey = widgetKey - Scalars = StackList.two(scalarA, scalarB) + Scalars = AttributesBundle(StackList.two(scalarA, scalarB), ValueNone, ValueNone) Attr = attr } member inline x.Run(c: Content<'msg>) = + let struct (scalars, widgets, widgetCollections) = x.Scalars + let attrValue = match MutStackArray1.toArraySlice &c.Widgets with | ValueNone -> ArraySlice.emptyWithNull() | ValueSome slice -> slice - WidgetBuilder<'msg, 'marker>(x.WidgetKey, AttributesBundle(x.Scalars, ValueNone, ValueSome [| x.Attr.WithValue(attrValue) |])) + let widgetCollAttr = x.Attr.WithValue(attrValue) + + let widgetCollections = + match widgetCollections with + | ValueNone -> ValueSome([| widgetCollAttr |]) + | ValueSome widgetCollectionAttributes -> ValueSome(Array.appendOne widgetCollAttr widgetCollectionAttributes) + + WidgetBuilder<'msg, 'marker>(x.WidgetKey, AttributesBundle(scalars, widgets, widgetCollections)) member inline _.Combine(a: Content<'msg>, b: Content<'msg>) : Content<'msg> = let res = MutStackArray1.combineMut(&a.Widgets, b.Widgets) @@ -177,7 +186,14 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker> = [] member inline x.AddScalar(attr: ScalarAttribute) = - CollectionBuilder<'msg, 'marker, 'itemMarker>(x.WidgetKey, StackList.add(&x.Scalars, attr), x.Attr) + let struct (scalarAttributes, widgetAttributes, widgetCollectionAttributes) = + x.Scalars + + CollectionBuilder<'msg, 'marker, 'itemMarker>( + x.WidgetKey, + x.Attr, + struct (StackList.add(&scalarAttributes, attr), widgetAttributes, widgetCollectionAttributes) + ) end