fuse-open / fuselibs

Fuselibs is the Uno-libraries that provide the UI framework used in Fuse apps
https://npmjs.com/package/@fuse-open/fuselibs
MIT License
176 stars 72 forks source link

Global values not fully working with Margins #540

Closed eksperts closed 6 years ago

eksperts commented 6 years ago

Reported on community.

Repro:

<App>
    <float ux:Global="SP" ux:Value="15" />
    <StackPanel Background="#999" >
        <Image Url="https://unsplash.it/200/50" StretchMode="Uniform" Margin="SP * 2, SP * 3, SP * 2, SP * 2.5"/>
        <Image Url="https://unsplash.it/200/50" StretchMode="Uniform" Margin="SP * 2, SP * 3"/>
        <Image Url="https://unsplash.it/200/50" StretchMode="Uniform" Margin="30, 45"/>
    </StackPanel>
</App>

The second image should have the same margin on both left and right sides (SP * 2), and on top and bottom (SP * 3). However, it's missing the right and bottom margin.

Same applies for Padding. Other float4 properties with a repeating pattern support (CornerRadius?) should be checked too, but currently there are no reports on them being broken.

fusebuild commented 6 years ago

The forum thread Global values not fully working with Margins posted by mircea@code11.com was linked to this issue.

kusma commented 6 years ago

Uh, that global is a float4, not a float. So I'm not convinced this is what the user wanted.

eksperts commented 6 years ago

oh. slipped my attention, let me test that.

kusma commented 6 years ago

Actually, looks like this is due to difference in behavior between ux expressions and explicit values. The rules for how to implicitly convert is different between these two, I think.

eksperts commented 6 years ago

Yeah, changing the global to float doesn't help, the issue is the same.

I think that should work though. Adjusting original ticket to reflect this.

kusma commented 6 years ago

@eksperts: Yeah, I think I agree. This should have worked.

kusma commented 6 years ago

This seems to fix it:

diff --git a/Source/Fuse.Marshal/Marshal.Cast.uno b/Source/Fuse.Marshal/Marshal.Cast.uno
index 15e4d58..4673868 100644
--- a/Source/Fuse.Marshal/Marshal.Cast.uno
+++ b/Source/Fuse.Marshal/Marshal.Cast.uno
@@ -102,7 +102,18 @@ namespace Fuse
                var y = a.Length > 1 ? ToFloat(a[1]) : 0.0f;
                var z = a.Length > 2 ? ToFloat(a[2]) : 0.0f;
                var w = a.Length > 3 ? ToFloat(a[3]) : 1.0f;
-               return float4(x,y,z,w);
+               switch (a.Length)
+               {
+                   case 0: return default(float4);
+
+                   // let's just write down the conversion rules once
+                   case 1: return ToFloat4(x);
+                   case 2: return ToFloat4(float2(x, y));
+                   case 3: return ToFloat4(float3(x, y, z));
+
+                   default:
+                       return float4(x,y,z,w);
+               }
            }

            double d;
@@ -286,4 +297,4 @@ namespace Fuse
            return new Size(v, unit);
        }
    }
-}
\ No newline at end of file
+}