mgierlasinski / MagicGradients

Draw breathtaking backgrounds in your Xamarin.Forms application. It's a kind of magic.
MIT License
369 stars 22 forks source link

[Spec] Fluent API for MVU #199

Closed mgierlasinski closed 2 years ago

mgierlasinski commented 2 years ago

Create extension methods for IGradientControl to setup gradients with simple, fluent API useful for MVU-style UI.

Source extensions

Source(IGradientSource source);
Source(string css);
Source(Action<GradientBuilder> build);
new GradientView()
   .Source(new MySource())

new GradientView()
   .Source("linear-gradient(red, green, blue)")

new GradientView()
   .Source(b => b
      .AddLinearGradient(s => s
         .Rotate(45))
      .AddRadialGradient())

Size extensions

Size(Dimensions size);
Size(string css);
new GradientView()
   .Size(Dimensions.Abs(40,40))

new GradientView()
   .Size("40px 40px")

Repeat extensions

Repeat(BackgroundRepeat repeat);
Repeat(string css);
new GradientView()
   .Repeat(BackgroundRepeat.RepeatX)

new GradientView()
   .Repeat("repeat-x")

Mask extensions

Mask(IGradientMask mask);

Use cases

[Body]
View body () => new VStack 
{
   new GradientView()
      .Source("linear-gradient(orange, yellow)")
      .Size("100px 200px"),
   new GradientView()
      .Source(b => b
         .AddLinearGradient(s => s
            .AddStops(Colors.Blue, Colors.Pink)
            .Rotate(90)))
      .Size(Dimensions.Prop(0.5, 0.5))
      .Repeat(BackgroundRepeat.RepeatY)
};