diff options
7 files changed, 75 insertions, 26 deletions
diff --git a/AndroidNative/FormsViewGroup/src/com/xamarin/forms/platform/android/FormsViewGroup.java b/AndroidNative/FormsViewGroup/src/com/xamarin/forms/platform/android/FormsViewGroup.java index 2168f323..b9ce8e80 100644 --- a/AndroidNative/FormsViewGroup/src/com/xamarin/forms/platform/android/FormsViewGroup.java +++ b/AndroidNative/FormsViewGroup/src/com/xamarin/forms/platform/android/FormsViewGroup.java @@ -72,7 +72,8 @@ public class FormsViewGroup extends ViewGroup { float rotation, float rotationX, float rotationY, - float scale, + float scaleX, + float scaleY float translationX, float translationY){ setPivotX (pivotX); @@ -88,8 +89,8 @@ public class FormsViewGroup extends ViewGroup { setRotation (rotation); setRotationX (rotationX); setRotationY (rotationY); - setScaleX (scale); - setScaleY (scale); + setScaleX (scaleX); + setScaleY (sclaeY); setTranslationX (translationX); setTranslationY (translationY); } diff --git a/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs b/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs index e189f839..18276d81 100644 --- a/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs +++ b/Xamarin.Forms.Controls/GalleryPages/ScaleRotate.cs @@ -39,19 +39,41 @@ namespace Xamarin.Forms.Controls scaleSlider.SetBinding(Slider.ValueProperty, new Binding("Scale", BindingMode.TwoWay)); + // Label and Slider for ScaleX property. + Label scaleXSliderValue = new Label { + VerticalTextAlignment = TextAlignment.Center + }; + Grid.SetRow(scaleXSliderValue, 1); + Grid.SetColumn(scaleXSliderValue, 0); + + Slider scaleXSlider = new Slider { + Maximum = 10 + }; + Grid.SetRow(scaleXSlider, 1); + Grid.SetColumn(scaleXSlider, 1); + + // Set Bindings. + scaleXSliderValue.BindingContext = scaleXSlider; + scaleXSliderValue.SetBinding(Label.TextProperty, + new Binding("Value", BindingMode.OneWay, null, null, "ScaleX = {0:F1}")); + + scaleXSlider.BindingContext = label; + scaleXSlider.SetBinding(Slider.ValueProperty, + new Binding("ScaleX", BindingMode.TwoWay)); + // Label and Slider for Rotation property. Label rotationSliderValue = new Label { VerticalTextAlignment = TextAlignment.Center }; - Grid.SetRow(rotationSliderValue, 1); + Grid.SetRow(rotationSliderValue, 2); Grid.SetColumn(rotationSliderValue, 0); Slider rotationSlider = new Slider { Maximum = 360 }; - Grid.SetRow(rotationSlider, 1); + Grid.SetRow(rotationSlider, 2); Grid.SetColumn(rotationSlider, 1); // Set Bindings. @@ -68,7 +90,7 @@ namespace Xamarin.Forms.Controls { VerticalTextAlignment = TextAlignment.Center }; - Grid.SetRow(anchorxStepperValue, 2); + Grid.SetRow(anchorxStepperValue, 3); Grid.SetColumn(anchorxStepperValue, 0); Stepper anchorxStepper = new Stepper @@ -77,7 +99,7 @@ namespace Xamarin.Forms.Controls Minimum = -1, Increment = 0.5 }; - Grid.SetRow(anchorxStepper, 2); + Grid.SetRow(anchorxStepper, 3); Grid.SetColumn(anchorxStepper, 1); // Set bindings. @@ -94,7 +116,7 @@ namespace Xamarin.Forms.Controls { VerticalTextAlignment = TextAlignment.Center }; - Grid.SetRow(anchoryStepperValue, 3); + Grid.SetRow(anchoryStepperValue, 4); Grid.SetColumn(anchoryStepperValue, 0); Stepper anchoryStepper = new Stepper @@ -103,7 +125,7 @@ namespace Xamarin.Forms.Controls Minimum = -1, Increment = 0.5 }; - Grid.SetRow(anchoryStepper, 3); + Grid.SetRow(anchoryStepper, 4); Grid.SetColumn(anchoryStepper, 1); // Set bindings. @@ -130,6 +152,7 @@ namespace Xamarin.Forms.Controls new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = GridLength.Auto }, + new RowDefinition { Height = GridLength.Auto }, }, ColumnDefinitions = { @@ -140,6 +163,8 @@ namespace Xamarin.Forms.Controls { scaleSliderValue, scaleSlider, + scaleXSliderValue, + scaleXSlider, rotationSliderValue, rotationSlider, anchorxStepperValue, diff --git a/Xamarin.Forms.Core/VisualElement.cs b/Xamarin.Forms.Core/VisualElement.cs index 352e2549..e0125f36 100644 --- a/Xamarin.Forms.Core/VisualElement.cs +++ b/Xamarin.Forms.Core/VisualElement.cs @@ -48,6 +48,10 @@ namespace Xamarin.Forms public static readonly BindableProperty ScaleProperty = BindableProperty.Create("Scale", typeof(double), typeof(VisualElement), 1d); + public static readonly BindableProperty ScaleXProperty = BindableProperty.Create("ScaleX", typeof(double), typeof(VisualElement), 1d); + + public static readonly BindableProperty ScaleYProperty = BindableProperty.Create("ScaleY", typeof(double), typeof(VisualElement), 1d); + public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create("IsVisible", typeof(bool), typeof(VisualElement), true, propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable).OnIsVisibleChanged((bool)oldvalue, (bool)newvalue)); @@ -242,6 +246,16 @@ namespace Xamarin.Forms set { SetValue(ScaleProperty, value); } } + public double ScaleX { + get { return (double)GetValue(ScaleXProperty); } + set { SetValue(ScaleXProperty, value); } + } + + public double ScaleY { + get { return (double)GetValue(ScaleYProperty); } + set { SetValue(ScaleYProperty, value); } + } + public Style Style { get { return (Style)GetValue(StyleProperty); } diff --git a/Xamarin.Forms.Platform.Android/VisualElementTracker.cs b/Xamarin.Forms.Platform.Android/VisualElementTracker.cs index 7ade4596..b2e9fe47 100644 --- a/Xamarin.Forms.Platform.Android/VisualElementTracker.cs +++ b/Xamarin.Forms.Platform.Android/VisualElementTracker.cs @@ -120,7 +120,7 @@ namespace Xamarin.Forms.Platform.Android if (e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName) _layoutNeeded = true; - else if (e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || + else if (e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.ScaleXProperty.PropertyName || e.PropertyName == VisualElement.ScaleYProperty.PropertyName || e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName || e.PropertyName == VisualElement.IsVisibleProperty.PropertyName || e.PropertyName == VisualElement.OpacityProperty.PropertyName || e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName) @@ -138,7 +138,7 @@ namespace Xamarin.Forms.Platform.Android UpdateAnchorX(); else if (e.PropertyName == VisualElement.AnchorYProperty.PropertyName) UpdateAnchorY(); - else if (e.PropertyName == VisualElement.ScaleProperty.PropertyName) + else if (e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.ScaleXProperty.PropertyName || e.PropertyName == VisualElement.ScaleYProperty.PropertyName) UpdateScale(); else if (e.PropertyName == VisualElement.RotationProperty.PropertyName) UpdateRotation(); @@ -230,7 +230,7 @@ namespace Xamarin.Forms.Platform.Android UpdateRotationX(); if (oldElement.RotationY != newElement.RotationY) UpdateRotationY(); - if (oldElement.Scale != newElement.Scale) + if (oldElement.Scale != newElement.Scale || oldElement.ScaleX != newElement.ScaleY || oldElement.ScaleY != newElement.ScaleY) UpdateScale(); // ReSharper restore CompareOfFloatsByEqualityOperator @@ -299,9 +299,18 @@ namespace Xamarin.Forms.Platform.Android if (aview is FormsViewGroup) { var formsViewGroup = (FormsViewGroup)aview; - formsViewGroup.SendBatchUpdate((float)(view.AnchorX * _context.ToPixels(view.Width)), (float)(view.AnchorY * _context.ToPixels(view.Height)), - (int)(view.IsVisible ? ViewStates.Visible : ViewStates.Invisible), view.IsEnabled, (float)view.Opacity, (float)view.Rotation, (float)view.RotationX, (float)view.RotationY, (float)view.Scale, - _context.ToPixels(view.TranslationX), _context.ToPixels(view.TranslationY)); + formsViewGroup.SendBatchUpdate((float)(view.AnchorX * _context.ToPixels(view.Width)), + (float)(view.AnchorY * _context.ToPixels(view.Height)), + (int)(view.IsVisible ? ViewStates.Visible : ViewStates.Invisible), + view.IsEnabled, + (float)view.Opacity, + (float)view.Rotation, + (float)view.RotationX, + (float)view.RotationY, + (float)view.ScaleX, + (float)view.ScaleY, + _context.ToPixels(view.TranslationX), + _context.ToPixels(view.TranslationY)); } else { @@ -365,8 +374,8 @@ namespace Xamarin.Forms.Platform.Android VisualElement view = _renderer.Element; AView aview = _renderer.ViewGroup; - aview.ScaleX = (float)view.Scale; - aview.ScaleY = (float)view.Scale; + aview.ScaleX = (float)view.Scale * (float)view.ScaleX; + aview.ScaleY = (float)view.Scale * (float)view.ScaleY; } void UpdateTranslationX() diff --git a/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs b/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs index 45b51a95..c197bbfc 100644 --- a/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs +++ b/Xamarin.Forms.Platform.WP8/VisualElementTracker.cs @@ -160,7 +160,7 @@ namespace Xamarin.Forms.Platform.WinPhone MaybeInvalidate(); else if (e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName) UpdateScaleAndRotation(Model, Element); - else if (e.PropertyName == VisualElement.ScaleProperty.PropertyName) + else if (e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.ScaleXProperty.PropertyName || e.PropertyName == VisualElement.ScaleYProperty.PropertyName ) UpdateScaleAndRotation(Model, Element); else if (e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName) @@ -350,9 +350,8 @@ namespace Xamarin.Forms.Platform.WinPhone { double anchorX = view.AnchorX; double anchorY = view.AnchorY; - double scale = view.Scale; frameworkElement.RenderTransformOrigin = new System.Windows.Point(anchorX, anchorY); - frameworkElement.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; + frameworkElement.RenderTransform = new ScaleTransform { ScaleX = view.Scale * view.ScaleX, ScaleY = view.Scale * view.ScaleY }; UpdateRotation(view, frameworkElement); } diff --git a/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs b/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs index 760b9b30..6eadec76 100644 --- a/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs +++ b/Xamarin.Forms.Platform.WinRT/VisualElementTracker.cs @@ -188,7 +188,7 @@ namespace Xamarin.Forms.Platform.WinRT { UpdateScaleAndRotation(Element, Container); } - else if (e.PropertyName == VisualElement.ScaleProperty.PropertyName) + else if (e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.ScaleXProperty.PropertyName ||)e.PropertyName == VisualElement.ScaleYProperty.PropertyName { UpdateScaleAndRotation(Element, Container); } @@ -470,9 +470,8 @@ namespace Xamarin.Forms.Platform.WinRT { double anchorX = view.AnchorX; double anchorY = view.AnchorY; - double scale = view.Scale; frameworkElement.RenderTransformOrigin = new Windows.Foundation.Point(anchorX, anchorY); - frameworkElement.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; + frameworkElement.RenderTransform = new ScaleTransform { ScaleX = view.Scale * view.ScaleX, view.Scale * view.ScaleY = scale }; UpdateRotation(view, frameworkElement); } diff --git a/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs b/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs index 29840e2d..4ca75395 100644 --- a/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs +++ b/Xamarin.Forms.Platform.iOS/VisualElementTracker.cs @@ -78,7 +78,7 @@ namespace Xamarin.Forms.Platform.MacOS { if (e.PropertyName == VisualElement.XProperty.PropertyName || e.PropertyName == VisualElement.YProperty.PropertyName || e.PropertyName == VisualElement.WidthProperty.PropertyName || e.PropertyName == VisualElement.HeightProperty.PropertyName || e.PropertyName == VisualElement.AnchorXProperty.PropertyName || e.PropertyName == VisualElement.AnchorYProperty.PropertyName || - e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || + e.PropertyName == VisualElement.TranslationXProperty.PropertyName || e.PropertyName == VisualElement.TranslationYProperty.PropertyName || e.PropertyName == VisualElement.ScaleProperty.PropertyName || e.PropertyName == VisualElement.ScaleXProperty.PropertyName || e.PropertyName == VisualElement.ScaleYProperty.PropertyName || e.PropertyName == VisualElement.RotationProperty.PropertyName || e.PropertyName == VisualElement.RotationXProperty.PropertyName || e.PropertyName == VisualElement.RotationYProperty.PropertyName || e.PropertyName == VisualElement.IsVisibleProperty.PropertyName || e.PropertyName == VisualElement.IsEnabledProperty.PropertyName || e.PropertyName == VisualElement.InputTransparentProperty.PropertyName || e.PropertyName == VisualElement.OpacityProperty.PropertyName) @@ -135,6 +135,8 @@ namespace Xamarin.Forms.Platform.MacOS var rotationY = (float)view.RotationY; var rotation = (float)view.Rotation; var scale = (float)view.Scale; + var scaleX = (float)view.ScaleX * scale; + var scaleY = (float)view.ScaleY * scale; var width = (float)view.Width; var height = (float)view.Height; var x = (float)view.X; @@ -227,8 +229,8 @@ namespace Xamarin.Forms.Platform.MacOS if (Math.Abs(translationX) > epsilon || Math.Abs(translationY) > epsilon) transform = transform.Translate(translationX, translationY, 0); - if (Math.Abs(scale - 1) > epsilon) - transform = transform.Scale(scale); + if (Math.Abs(scaleX - 1) > epsilon || Math.Abs(scaleY - 1) > epsilon) + transform = transform.Scale(scaleX, scaleY, scale); // not just an optimization, iOS will not "pixel align" a view which has m34 set if (Math.Abs(rotationY % 180) > epsilon || Math.Abs(rotationX % 180) > epsilon) |