Skip to content

Commit

Permalink
Replace StackList<ScalarAttribute> with AttributesBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarfgp committed May 13, 2024
1 parent f592997 commit cb0d286
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/Fabulous.Tests/APISketchTests/TestUI.Widgets.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +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,
AttributesBundle(StackList.empty(), ValueNone, ValueNone),
Attributes.Container.Children
)



Expand Down
30 changes: 23 additions & 7 deletions src/Fabulous/Builders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,36 +125,45 @@ type Content<'msg> = { Widgets: MutStackArray1.T<Widget> }
type CollectionBuilder<'msg, 'marker, 'itemMarker> =
struct
val WidgetKey: WidgetKey
val Scalars: StackList<ScalarAttribute>
val Scalars: AttributesBundle
val Attr: WidgetCollectionAttributeDefinition

new(widgetKey: WidgetKey, scalars: StackList<ScalarAttribute>, attr: WidgetCollectionAttributeDefinition) =
new(widgetKey: WidgetKey, scalars: AttributesBundle, attr: WidgetCollectionAttributeDefinition) =
{ 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, ValueNone, ValueSome [| x.Attr.WithValue(attrValue) |]))

member inline _.Combine(a: Content<'msg>, b: Content<'msg>) : Content<'msg> =
let res = MutStackArray1.combineMut(&a.Widgets, b.Widgets)
Expand All @@ -177,7 +186,14 @@ type CollectionBuilder<'msg, 'marker, 'itemMarker> =

[<EditorBrowsable(EditorBrowsableState.Never)>]
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,
struct (StackList.add(&scalarAttributes, attr), widgetAttributes, widgetCollectionAttributes),
x.Attr
)

end

Expand Down

0 comments on commit cb0d286

Please sign in to comment.