From 01c52d27f7166b8e42fbf3544840c556d1c2172f Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Mon, 13 May 2024 21:20:06 +0100 Subject: [PATCH 1/5] 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 From 5c1f2996ca592af69488e195cb4ab5fd80a12149 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 15 May 2024 18:02:19 +0100 Subject: [PATCH 2/5] Update src/Fabulous/Builders.fs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Timothé Larivière --- src/Fabulous/Builders.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Fabulous/Builders.fs b/src/Fabulous/Builders.fs index 5ade1d542..7f4065405 100644 --- a/src/Fabulous/Builders.fs +++ b/src/Fabulous/Builders.fs @@ -126,7 +126,7 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker> = struct val WidgetKey: WidgetKey val Attr: WidgetCollectionAttributeDefinition - val Scalars: AttributesBundle + val Attributes: AttributesBundle new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalars: AttributesBundle) = { WidgetKey = widgetKey From 34f95f0760734fb4160f0743aca6787d3aecd1c8 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 15 May 2024 18:02:31 +0100 Subject: [PATCH 3/5] Update src/Fabulous/Builders.fs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Timothé Larivière --- src/Fabulous/Builders.fs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Fabulous/Builders.fs b/src/Fabulous/Builders.fs index 7f4065405..0b6f429ac 100644 --- a/src/Fabulous/Builders.fs +++ b/src/Fabulous/Builders.fs @@ -128,10 +128,15 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker> = val Attr: WidgetCollectionAttributeDefinition val Attributes: AttributesBundle - new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalars: AttributesBundle) = + new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, attributes: AttributesBundle) = { WidgetKey = widgetKey - Scalars = scalars - Attr = attr } + Attr = attr + Attributes = attributes } + + new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalars: StackList) = + { WidgetKey = widgetKey + Attr = attr + Attributes = AttributesBundle(scalars, ValueNone, ValueNone) } new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition) = { WidgetKey = widgetKey From 526198d90d3879b7591fff35a1563f61481f9999 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Wed, 15 May 2024 18:25:05 +0100 Subject: [PATCH 4/5] Fix PR comments --- .../APISketchTests/TestUI.Widgets.fs | 6 +---- src/Fabulous/Builders.fs | 26 +++++++++---------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs b/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs index 47b671343..be031185c 100644 --- a/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs +++ b/src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs @@ -155,11 +155,7 @@ module TestUI_Widgets = ) static member Stack<'msg, 'marker when 'marker :> IMarker>() = - CollectionBuilder<'msg, TestStackMarker, 'marker>( - TestStackKey, - Attributes.Container.Children, - AttributesBundle(StackList.empty(), ValueNone, ValueNone) - ) + CollectionBuilder<'msg, TestStackMarker, 'marker>(TestStackKey, StackList.empty(), Attributes.Container.Children) [] type CollectionBuilderExtensions = diff --git a/src/Fabulous/Builders.fs b/src/Fabulous/Builders.fs index 0b6f429ac..68df45e17 100644 --- a/src/Fabulous/Builders.fs +++ b/src/Fabulous/Builders.fs @@ -128,33 +128,33 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker> = val Attr: WidgetCollectionAttributeDefinition val Attributes: AttributesBundle - new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, attributes: AttributesBundle) = - { WidgetKey = widgetKey - Attr = attr - Attributes = attributes } - - new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalars: StackList) = + new(widgetKey: WidgetKey, scalars: StackList, attr: WidgetCollectionAttributeDefinition) = { WidgetKey = widgetKey - Attr = attr - Attributes = AttributesBundle(scalars, ValueNone, ValueNone) } + Attributes = AttributesBundle(scalars, ValueNone, ValueNone) + Attr = attr } new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition) = { WidgetKey = widgetKey - Scalars = AttributesBundle(StackList.empty(), ValueNone, ValueNone) + Attributes = AttributesBundle(StackList.empty(), ValueNone, ValueNone) + Attr = attr } + + new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, attributes: AttributesBundle) = + { WidgetKey = widgetKey + Attributes = attributes Attr = attr } new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalar: ScalarAttribute) = { WidgetKey = widgetKey - Scalars = AttributesBundle(StackList.one scalar, ValueNone, ValueNone) + Attributes = AttributesBundle(StackList.one scalar, ValueNone, ValueNone) Attr = attr } new(widgetKey: WidgetKey, attr: WidgetCollectionAttributeDefinition, scalarA: ScalarAttribute, scalarB: ScalarAttribute) = { WidgetKey = widgetKey - Scalars = AttributesBundle(StackList.two(scalarA, scalarB), ValueNone, ValueNone) + Attributes = AttributesBundle(StackList.two(scalarA, scalarB), ValueNone, ValueNone) Attr = attr } member inline x.Run(c: Content<'msg>) = - let struct (scalars, widgets, widgetCollections) = x.Scalars + let struct (scalars, widgets, widgetCollections) = x.Attributes let attrValue = match MutStackArray1.toArraySlice &c.Widgets with @@ -192,7 +192,7 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker> = [] member inline x.AddScalar(attr: ScalarAttribute) = let struct (scalarAttributes, widgetAttributes, widgetCollectionAttributes) = - x.Scalars + x.Attributes CollectionBuilder<'msg, 'marker, 'itemMarker>( x.WidgetKey, From 05cc057b788453597fbf1cd8d086c2a52f6514c9 Mon Sep 17 00:00:00 2001 From: Edgar Gonzalez Date: Fri, 17 May 2024 08:20:16 +0100 Subject: [PATCH 5/5] release notes --- CHANGELOG.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef3c6c0aa..157eaa5d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 _No unreleased changes_ +## [3.0.0-pre5] - 2024-05-17 + +### Added +- Add new `CollectionBuilder` constructor using an `AttributesBundle` by @edgarfgp in https://github.com/fabulous-dev/Fabulous/pull/1081 + ## [3.0.0-pre4] - 2024-04-19 ### Added @@ -134,7 +139,8 @@ _No unreleased changes_ ### Changed - Fabulous.XamarinForms & Fabulous.MauiControls have been moved been out of the Fabulous repository. Find them in their own repositories: [https://github.com/fabulous-dev/Fabulous.XamarinForms](https://github.com/fabulous-dev/Fabulous.XamarinForms) / [https://github.com/fabulous-dev/Fabulous.MauiControls](https://github.com/fabulous-dev/Fabulous.MauiControls) -[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre4...HEAD +[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre5...HEAD +[3.0.0-pre5]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre5 [3.0.0-pre4]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre4 [3.0.0-pre3]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre3 [3.0.0-pre2]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre2