From 70f80597e71aaaa2fcaec76c651545305b9a679c Mon Sep 17 00:00:00 2001 From: Kev Hannen Date: Wed, 15 Mar 2023 09:26:33 +0000 Subject: [PATCH 1/4] Add support for float32 properties which fixes corner radius for Frame --- src/Fabulous.XamarinForms/Attributes.fs | 18 +++++++++++++++++- .../Views/Layouts/Frame.fs | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Fabulous.XamarinForms/Attributes.fs b/src/Fabulous.XamarinForms/Attributes.fs index 282d800..4c0af96 100644 --- a/src/Fabulous.XamarinForms/Attributes.fs +++ b/src/Fabulous.XamarinForms/Attributes.fs @@ -63,6 +63,15 @@ module SmallScalars = let expands = (encoded &&& 0x00000000FFFFFFFFUL) = 1UL LayoutOptions(alignment, expands) + + // should this be in Fabulous? + module Float32 = + let inline encode (v: float32) : uint64 = + v |> float |> BitConverter.DoubleToInt64Bits |> uint64 + + let inline decode (encoded: uint64) : float32 = + encoded |> int64 |> BitConverter.Int64BitsToDouble |> float32 + [] type SmallScalarExtensions() = @@ -77,7 +86,11 @@ type SmallScalarExtensions() = [] static member inline WithValue(this: SmallScalarAttributeDefinition>, value) = this.WithValue(value, SmallScalars.ThemedColor.encode) - + + [] + static member inline WithValue(this: SmallScalarAttributeDefinition, value) = + this.WithValue(value, SmallScalars.Float32.encode) + module Attributes = /// Define an attribute for a BindableProperty let inline defineBindable<'modelType, 'valueType> @@ -113,6 +126,9 @@ module Attributes = /// Define a float attribute for a BindableProperty and encode it as a small scalar (8 bytes) let inline defineBindableFloat (bindableProperty: BindableProperty) = defineSmallBindable bindableProperty SmallScalars.Float.decode + + let inline defineBindableFloat32 (bindableProperty: BindableProperty) = + defineSmallBindable bindableProperty SmallScalars.Float32.decode /// Define a boolean attribute for a BindableProperty and encode it as a small scalar (8 bytes) let inline defineBindableBool (bindableProperty: BindableProperty) = diff --git a/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs b/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs index 1b06d42..60e0a97 100644 --- a/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs +++ b/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs @@ -12,7 +12,7 @@ module Frame = let BorderColor = Attributes.defineBindableAppThemeColor Frame.BorderColorProperty - let CornerRadius = Attributes.defineBindableFloat Frame.CornerRadiusProperty + let CornerRadius = Attributes.defineBindableFloat32 Frame.CornerRadiusProperty let HasShadow = Attributes.defineBindableBool Frame.HasShadowProperty @@ -35,7 +35,7 @@ type FrameModifiers = /// Set the corner radius of the frame /// The corner radius of the frame [] - static member inline cornerRadius(this: WidgetBuilder<'msg, #IFrame>, value: float) = + static member inline cornerRadius(this: WidgetBuilder<'msg, #IFrame>, value: float32) = this.AddScalar(Frame.CornerRadius.WithValue(value)) // Set the shadow of the frame From 1f0d5636b709a716b23fcd09ce7a7fd8d097d5ce Mon Sep 17 00:00:00 2001 From: kevkov Date: Thu, 16 Mar 2023 11:28:04 +0000 Subject: [PATCH 2/4] Update src/Fabulous.XamarinForms/Views/Layouts/Frame.fs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Timothé Larivière --- src/Fabulous.XamarinForms/Views/Layouts/Frame.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs b/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs index 60e0a97..3dcb645 100644 --- a/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs +++ b/src/Fabulous.XamarinForms/Views/Layouts/Frame.fs @@ -35,8 +35,8 @@ type FrameModifiers = /// Set the corner radius of the frame /// The corner radius of the frame [] - static member inline cornerRadius(this: WidgetBuilder<'msg, #IFrame>, value: float32) = - this.AddScalar(Frame.CornerRadius.WithValue(value)) + static member inline cornerRadius(this: WidgetBuilder<'msg, #IFrame>, value: float) = + this.AddScalar(Frame.CornerRadius.WithValue(float32 value)) // Set the shadow of the frame // Whether the frame has a shadow From 8a213897193b41e740629f8559da223325fc8865 Mon Sep 17 00:00:00 2001 From: Kev Hannen Date: Fri, 17 Mar 2023 17:37:10 +0000 Subject: [PATCH 3/4] Updates for PR #35 comments including upgrade to Fabulous 2.3.0 --- CHANGELOG.md | 4 +++- Directory.Packages.props | 2 +- src/Fabulous.XamarinForms/Attributes.fs | 17 ++--------------- .../Fabulous.XamarinForms.fsproj | 2 +- .../blank-vswin/.template.config/template.json | 2 +- 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2b690..9a91b04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -_No unreleased changes_ +### Fixed + +- Add support for float32 properties which fixes corner radius for Frame (https://github.com/fabulous-dev/Fabulous.XamarinForms/pull/35) ## [2.2.0] - 2023-01-24 diff --git a/Directory.Packages.props b/Directory.Packages.props index eaa8543..665c1f1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -5,7 +5,7 @@ - + diff --git a/src/Fabulous.XamarinForms/Attributes.fs b/src/Fabulous.XamarinForms/Attributes.fs index 4c0af96..6eb7701 100644 --- a/src/Fabulous.XamarinForms/Attributes.fs +++ b/src/Fabulous.XamarinForms/Attributes.fs @@ -63,15 +63,6 @@ module SmallScalars = let expands = (encoded &&& 0x00000000FFFFFFFFUL) = 1UL LayoutOptions(alignment, expands) - - // should this be in Fabulous? - module Float32 = - let inline encode (v: float32) : uint64 = - v |> float |> BitConverter.DoubleToInt64Bits |> uint64 - - let inline decode (encoded: uint64) : float32 = - encoded |> int64 |> BitConverter.Int64BitsToDouble |> float32 - [] type SmallScalarExtensions() = @@ -86,11 +77,7 @@ type SmallScalarExtensions() = [] static member inline WithValue(this: SmallScalarAttributeDefinition>, value) = this.WithValue(value, SmallScalars.ThemedColor.encode) - - [] - static member inline WithValue(this: SmallScalarAttributeDefinition, value) = - this.WithValue(value, SmallScalars.Float32.encode) - + module Attributes = /// Define an attribute for a BindableProperty let inline defineBindable<'modelType, 'valueType> @@ -126,7 +113,7 @@ module Attributes = /// Define a float attribute for a BindableProperty and encode it as a small scalar (8 bytes) let inline defineBindableFloat (bindableProperty: BindableProperty) = defineSmallBindable bindableProperty SmallScalars.Float.decode - + let inline defineBindableFloat32 (bindableProperty: BindableProperty) = defineSmallBindable bindableProperty SmallScalars.Float32.decode diff --git a/src/Fabulous.XamarinForms/Fabulous.XamarinForms.fsproj b/src/Fabulous.XamarinForms/Fabulous.XamarinForms.fsproj index b553616..d7245b8 100644 --- a/src/Fabulous.XamarinForms/Fabulous.XamarinForms.fsproj +++ b/src/Fabulous.XamarinForms/Fabulous.XamarinForms.fsproj @@ -140,7 +140,7 @@ --> - + \ No newline at end of file diff --git a/templates/content/blank-vswin/.template.config/template.json b/templates/content/blank-vswin/.template.config/template.json index 1f229a4..b388aac 100644 --- a/templates/content/blank-vswin/.template.config/template.json +++ b/templates/content/blank-vswin/.template.config/template.json @@ -55,7 +55,7 @@ "type": "parameter", "dataType": "string", "replaces": "FabulousPkgVersion", - "defaultValue": "2.2.0" + "defaultValue": "2.3.0" }, "FabulousXFPkgVersion": { "type": "parameter", From b4a807bc969c83f26ac914e6f90de6d63bc92ec2 Mon Sep 17 00:00:00 2001 From: Kev Hannen Date: Sat, 18 Mar 2023 09:11:49 +0000 Subject: [PATCH 4/4] Missing comment, update for PR #35 --- src/Fabulous.XamarinForms/Attributes.fs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Fabulous.XamarinForms/Attributes.fs b/src/Fabulous.XamarinForms/Attributes.fs index 6eb7701..e322da4 100644 --- a/src/Fabulous.XamarinForms/Attributes.fs +++ b/src/Fabulous.XamarinForms/Attributes.fs @@ -114,6 +114,7 @@ module Attributes = let inline defineBindableFloat (bindableProperty: BindableProperty) = defineSmallBindable bindableProperty SmallScalars.Float.decode + /// Define a float32 attribute for a BindableProperty and encode it as a small scalar (8 bytes) let inline defineBindableFloat32 (bindableProperty: BindableProperty) = defineSmallBindable bindableProperty SmallScalars.Float32.decode