Created
December 18, 2012 06:37
-
-
Save dvdsgl/4325599 to your computer and use it in GitHub Desktop.
Extension method for succinct RectangleF mutation expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class RectangleExtensions | |
{ | |
public static RectangleF With (this RectangleF self, | |
float? X = null, float? Y = null, | |
float? Width = null, float? Height = null) | |
{ | |
return new RectangleF (X ?? self.X, Y ?? self.Y, Width ?? self.Width, Height ?? self.Height); | |
} | |
static T Id<T> (T t) { return t; } | |
public static RectangleF With (this RectangleF self, | |
Func<float,float> X = null, Func<float,float> Y = null, | |
Func<float,float> Width = null, Func<float,float> Height = null) | |
{ | |
return new RectangleF ((X ?? Id) (self.X), (Y ?? Id) (self.Y), | |
(Width ?? Id) (self.Width), (Height ?? Id) (self.Height)); | |
} | |
} | |
// Demo 1 | |
UIView.Animate (0.5, () => { | |
View.Frame = View.Frame.With (Width: 200, Y: 50); | |
}); | |
// Demo 2 | |
UIView.Animate (0.5, () => { | |
View.Frame = View.Frame.With (Y: y => y - 100); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment