From c27ddbb17cf6df58e9c103f07e0ab6ebd7c7749e Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Thu, 9 Apr 2015 10:56:36 +0100 Subject: [PATCH] Removed ActualSize property - use Bounds instead. --- Perspex.Controls/Border.cs | 2 +- Perspex.Controls/Control.cs | 2 +- Perspex.Controls/Image.cs | 4 ++-- Perspex.Controls/Popup.cs | 2 +- .../Primitives/TemplatedControl.cs | 2 +- Perspex.Controls/Primitives/Track.cs | 4 ++-- Perspex.Controls/Shapes/Ellipse.cs | 6 +++--- Perspex.Controls/Shapes/Rectangle.cs | 6 +++--- Perspex.Controls/TextBlock.cs | 2 +- Perspex.Layout/Layoutable.cs | 12 +---------- Perspex.SceneGraph/Visual.cs | 21 ++++++++----------- Perspex.Themes.Default/DropDownStyle.cs | 2 +- .../FullLayoutTests.cs | 16 +++++++------- 13 files changed, 34 insertions(+), 47 deletions(-) diff --git a/Perspex.Controls/Border.cs b/Perspex.Controls/Border.cs index cf8f25ac71..133e2c63eb 100644 --- a/Perspex.Controls/Border.cs +++ b/Perspex.Controls/Border.cs @@ -51,7 +51,7 @@ namespace Perspex.Controls Brush background = this.Background; Brush borderBrush = this.BorderBrush; double borderThickness = this.BorderThickness; - Rect rect = new Rect(this.ActualSize).Deflate(this.BorderThickness / 2); + Rect rect = new Rect(this.Bounds.Size).Deflate(this.BorderThickness / 2); if (background != null) { diff --git a/Perspex.Controls/Control.cs b/Perspex.Controls/Control.cs index a28f6c7bdf..8d4714b2f3 100644 --- a/Perspex.Controls/Control.cs +++ b/Perspex.Controls/Control.cs @@ -170,7 +170,7 @@ namespace Perspex.Controls public void BringIntoView() { - this.BringIntoView(new Rect(this.ActualSize)); + this.BringIntoView(new Rect(this.Bounds.Size)); } public void BringIntoView(Rect rect) diff --git a/Perspex.Controls/Image.cs b/Perspex.Controls/Image.cs index dab6bb1bc1..3e3ef957b2 100644 --- a/Perspex.Controls/Image.cs +++ b/Perspex.Controls/Image.cs @@ -36,9 +36,9 @@ namespace Perspex.Controls if (source != null) { - Rect viewPort = new Rect(this.ActualSize); + Rect viewPort = new Rect(this.Bounds.Size); Size sourceSize = new Size(source.PixelWidth, source.PixelHeight); - Vector scale = CalculateScaling(this.ActualSize, sourceSize, this.Stretch); + Vector scale = CalculateScaling(this.Bounds.Size, sourceSize, this.Stretch); Size scaledSize = sourceSize * scale; Rect destRect = viewPort .CenterIn(new Rect(scaledSize)) diff --git a/Perspex.Controls/Popup.cs b/Perspex.Controls/Popup.cs index e0ef087c7d..a54518fb4d 100644 --- a/Perspex.Controls/Popup.cs +++ b/Perspex.Controls/Popup.cs @@ -132,7 +132,7 @@ namespace Perspex.Controls { if (this.PlacementTarget != null) { - return this.PlacementTarget.PointToScreen(new Point(0, this.PlacementTarget.ActualSize.Height)); + return this.PlacementTarget.PointToScreen(new Point(0, this.PlacementTarget.Bounds.Size.Height)); } else { diff --git a/Perspex.Controls/Primitives/TemplatedControl.cs b/Perspex.Controls/Primitives/TemplatedControl.cs index 2ddfe4b815..555878d610 100644 --- a/Perspex.Controls/Primitives/TemplatedControl.cs +++ b/Perspex.Controls/Primitives/TemplatedControl.cs @@ -151,7 +151,7 @@ namespace Perspex.Controls.Primitives if (child != null) { child.Arrange(new Rect(finalSize)); - return child.ActualSize; + return child.Bounds.Size; } else { diff --git a/Perspex.Controls/Primitives/Track.cs b/Perspex.Controls/Primitives/Track.cs index 2e26608b28..adf388a635 100644 --- a/Perspex.Controls/Primitives/Track.cs +++ b/Perspex.Controls/Primitives/Track.cs @@ -154,11 +154,11 @@ namespace Perspex.Controls.Primitives if (this.Orientation == Orientation.Horizontal) { - offset = e.Vector.X / ((this.ActualSize.Width - this.Thumb.ActualSize.Width) / range); + offset = e.Vector.X / ((this.Bounds.Size.Width - this.Thumb.Bounds.Size.Width) / range); } else { - offset = e.Vector.Y * (range / (this.ActualSize.Height - this.Thumb.ActualSize.Height)); + offset = e.Vector.Y * (range / (this.Bounds.Size.Height - this.Thumb.Bounds.Size.Height)); } if (!double.IsNaN(offset) && !double.IsInfinity(offset)) diff --git a/Perspex.Controls/Shapes/Ellipse.cs b/Perspex.Controls/Shapes/Ellipse.cs index edbacc02f0..bec10c30ea 100644 --- a/Perspex.Controls/Shapes/Ellipse.cs +++ b/Perspex.Controls/Shapes/Ellipse.cs @@ -18,12 +18,12 @@ namespace Perspex.Controls.Shapes { get { - if (this.geometry == null || this.geometrySize != this.ActualSize) + if (this.geometry == null || this.geometrySize != this.Bounds.Size) { - var rect = new Rect(0, 0, this.ActualSize.Width, this.ActualSize.Height); + var rect = new Rect(0, 0, this.Bounds.Size.Width, this.Bounds.Size.Height); rect = rect.Deflate(this.StrokeThickness / 2); this.geometry = new EllipseGeometry(rect); - this.geometrySize = this.ActualSize; + this.geometrySize = this.Bounds.Size; } return this.geometry; diff --git a/Perspex.Controls/Shapes/Rectangle.cs b/Perspex.Controls/Shapes/Rectangle.cs index 830033b082..8bdc2589e8 100644 --- a/Perspex.Controls/Shapes/Rectangle.cs +++ b/Perspex.Controls/Shapes/Rectangle.cs @@ -18,10 +18,10 @@ namespace Perspex.Controls.Shapes { get { - if (this.geometry == null || this.geometrySize != this.ActualSize) + if (this.geometry == null || this.geometrySize != this.Bounds.Size) { - this.geometry = new RectangleGeometry(new Rect(0, 0, this.ActualSize.Width, this.ActualSize.Height)); - this.geometrySize = this.ActualSize; + this.geometry = new RectangleGeometry(new Rect(0, 0, this.Bounds.Size.Width, this.Bounds.Size.Height)); + this.geometrySize = this.Bounds.Size; } return this.geometry; diff --git a/Perspex.Controls/TextBlock.cs b/Perspex.Controls/TextBlock.cs index 52d78d9b46..1a639fc0d9 100644 --- a/Perspex.Controls/TextBlock.cs +++ b/Perspex.Controls/TextBlock.cs @@ -120,7 +120,7 @@ namespace Perspex.Controls if (background != null) { - context.FillRectange(background, new Rect(this.ActualSize)); + context.FillRectange(background, new Rect(this.Bounds.Size)); } context.DrawText(this.Foreground, new Point(), this.FormattedText); diff --git a/Perspex.Layout/Layoutable.cs b/Perspex.Layout/Layoutable.cs index e562363990..e15d9f7d85 100644 --- a/Perspex.Layout/Layoutable.cs +++ b/Perspex.Layout/Layoutable.cs @@ -29,9 +29,6 @@ namespace Perspex.Layout public class Layoutable : Visual, ILayoutable, IEnableLogger { - public static readonly PerspexProperty ActualSizeProperty = - PerspexProperty.Register("ActualSize"); - public static readonly PerspexProperty WidthProperty = PerspexProperty.Register("Width", double.NaN); @@ -131,11 +128,6 @@ namespace Perspex.Layout set { this.SetValue(VerticalAlignmentProperty, value); } } - public Size ActualSize - { - get { return this.GetValue(ActualSizeProperty); } - } - public Size? DesiredSize { get; @@ -327,9 +319,7 @@ namespace Perspex.Layout break; } - var bounds = new Rect(originX, originY, size.Width, size.Height); - this.SetVisualBounds(bounds); - this.SetValue(ActualSizeProperty, bounds.Size); + this.Bounds = new Rect(originX, originY, size.Width, size.Height); } } diff --git a/Perspex.SceneGraph/Visual.cs b/Perspex.SceneGraph/Visual.cs index df2f43d306..591da36471 100644 --- a/Perspex.SceneGraph/Visual.cs +++ b/Perspex.SceneGraph/Visual.cs @@ -21,6 +21,9 @@ namespace Perspex public class Visual : Animatable, IVisual { + public static readonly PerspexProperty BoundsProperty = + PerspexProperty.Register("Bounds"); + public static readonly PerspexProperty ClipToBoundsProperty = PerspexProperty.Register("ClipToBounds"); @@ -36,8 +39,6 @@ namespace Perspex public static readonly PerspexProperty TransformOriginProperty = PerspexProperty.Register("TransformOrigin", defaultValue: Origin.Default); - private Rect bounds; - private PerspexList visualChildren; private Visual visualParent; @@ -54,6 +55,12 @@ namespace Perspex this.visualChildren.CollectionChanged += this.VisualChildrenChanged; } + public Rect Bounds + { + get { return this.GetValue(BoundsProperty); } + protected set { this.SetValue(BoundsProperty, value); } + } + public bool ClipToBounds { get { return this.GetValue(ClipToBoundsProperty); } @@ -84,11 +91,6 @@ namespace Perspex set { this.SetValue(TransformOriginProperty, value); } } - Rect IVisual.Bounds - { - get { return this.bounds; } - } - IPerspexReadOnlyList IVisual.VisualChildren { get { return this.visualChildren; } @@ -173,11 +175,6 @@ namespace Perspex } } - protected void SetVisualBounds(Rect bounds) - { - this.bounds = bounds; - } - protected virtual void OnAttachedToVisualTree(IRenderRoot root) { } diff --git a/Perspex.Themes.Default/DropDownStyle.cs b/Perspex.Themes.Default/DropDownStyle.cs index 01ff12a492..ada87df2a1 100644 --- a/Perspex.Themes.Default/DropDownStyle.cs +++ b/Perspex.Themes.Default/DropDownStyle.cs @@ -99,7 +99,7 @@ namespace Perspex.Themes.Default PlacementTarget = control, StaysOpen = false, [~~Popup.IsOpenProperty] = control[~~DropDown.IsDropDownOpenProperty], - [~Popup.MinWidthProperty] = control[~DropDown.ActualSizeProperty].Cast().Select(x => (object)x.Width), + [~Popup.MinWidthProperty] = control[~DropDown.BoundsProperty].Cast().Select(x => (object)x.Width), } }, }, diff --git a/Tests/Perspex.Layout.UnitTests/FullLayoutTests.cs b/Tests/Perspex.Layout.UnitTests/FullLayoutTests.cs index 68a006fc86..00e078e44c 100644 --- a/Tests/Perspex.Layout.UnitTests/FullLayoutTests.cs +++ b/Tests/Perspex.Layout.UnitTests/FullLayoutTests.cs @@ -57,11 +57,11 @@ namespace Perspex.Layout.UnitTests window.LayoutManager.ExecuteLayoutPass(); - Assert.Equal(new Size(400, 400), border.ActualSize); + Assert.Equal(new Size(400, 400), border.Bounds.Size); textBlock.Width = 200; window.LayoutManager.ExecuteLayoutPass(); - Assert.Equal(new Size(200, 400), border.ActualSize); + Assert.Equal(new Size(200, 400), border.Bounds.Size); } } @@ -97,10 +97,10 @@ namespace Perspex.Layout.UnitTests window.LayoutManager.ExecuteLayoutPass(); - Assert.Equal(new Size(800, 600), window.ActualSize); - Assert.Equal(new Size(200, 200), scrollViewer.ActualSize); + Assert.Equal(new Size(800, 600), window.Bounds.Size); + Assert.Equal(new Size(200, 200), scrollViewer.Bounds.Size); Assert.Equal(new Point(300, 200), Position(scrollViewer)); - Assert.Equal(new Size(400, 400), textBlock.ActualSize); + Assert.Equal(new Size(400, 400), textBlock.Bounds.Size); var scrollBars = scrollViewer.GetTemplateChildren().OfType().ToList(); var presenters = scrollViewer.GetTemplateChildren().OfType().ToList(); @@ -109,15 +109,15 @@ namespace Perspex.Layout.UnitTests Assert.Equal(1, presenters.Count); var presenter = presenters[0]; - Assert.Equal(new Size(190, 190), presenter.ActualSize); + Assert.Equal(new Size(190, 190), presenter.Bounds.Size); var horzScroll = scrollBars.Single(x => x.Orientation == Orientation.Horizontal); var vertScroll = scrollBars.Single(x => x.Orientation == Orientation.Vertical); Assert.True(horzScroll.IsVisible); Assert.True(vertScroll.IsVisible); - Assert.Equal(new Size(190, 10), horzScroll.ActualSize); - Assert.Equal(new Size(10, 190), vertScroll.ActualSize); + Assert.Equal(new Size(190, 10), horzScroll.Bounds.Size); + Assert.Equal(new Size(10, 190), vertScroll.Bounds.Size); Assert.Equal(new Point(0, 190), Position(horzScroll)); Assert.Equal(new Point(190, 0), Position(vertScroll)); }