Browse Source

Removed ActualSize property - use Bounds instead.

pull/39/head
Steven Kirk 12 years ago
parent
commit
c27ddbb17c
  1. 2
      Perspex.Controls/Border.cs
  2. 2
      Perspex.Controls/Control.cs
  3. 4
      Perspex.Controls/Image.cs
  4. 2
      Perspex.Controls/Popup.cs
  5. 2
      Perspex.Controls/Primitives/TemplatedControl.cs
  6. 4
      Perspex.Controls/Primitives/Track.cs
  7. 6
      Perspex.Controls/Shapes/Ellipse.cs
  8. 6
      Perspex.Controls/Shapes/Rectangle.cs
  9. 2
      Perspex.Controls/TextBlock.cs
  10. 12
      Perspex.Layout/Layoutable.cs
  11. 21
      Perspex.SceneGraph/Visual.cs
  12. 2
      Perspex.Themes.Default/DropDownStyle.cs
  13. 16
      Tests/Perspex.Layout.UnitTests/FullLayoutTests.cs

2
Perspex.Controls/Border.cs

@ -51,7 +51,7 @@ namespace Perspex.Controls
Brush background = this.Background; Brush background = this.Background;
Brush borderBrush = this.BorderBrush; Brush borderBrush = this.BorderBrush;
double borderThickness = this.BorderThickness; 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) if (background != null)
{ {

2
Perspex.Controls/Control.cs

@ -170,7 +170,7 @@ namespace Perspex.Controls
public void BringIntoView() public void BringIntoView()
{ {
this.BringIntoView(new Rect(this.ActualSize)); this.BringIntoView(new Rect(this.Bounds.Size));
} }
public void BringIntoView(Rect rect) public void BringIntoView(Rect rect)

4
Perspex.Controls/Image.cs

@ -36,9 +36,9 @@ namespace Perspex.Controls
if (source != null) if (source != null)
{ {
Rect viewPort = new Rect(this.ActualSize); Rect viewPort = new Rect(this.Bounds.Size);
Size sourceSize = new Size(source.PixelWidth, source.PixelHeight); 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; Size scaledSize = sourceSize * scale;
Rect destRect = viewPort Rect destRect = viewPort
.CenterIn(new Rect(scaledSize)) .CenterIn(new Rect(scaledSize))

2
Perspex.Controls/Popup.cs

@ -132,7 +132,7 @@ namespace Perspex.Controls
{ {
if (this.PlacementTarget != null) 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 else
{ {

2
Perspex.Controls/Primitives/TemplatedControl.cs

@ -151,7 +151,7 @@ namespace Perspex.Controls.Primitives
if (child != null) if (child != null)
{ {
child.Arrange(new Rect(finalSize)); child.Arrange(new Rect(finalSize));
return child.ActualSize; return child.Bounds.Size;
} }
else else
{ {

4
Perspex.Controls/Primitives/Track.cs

@ -154,11 +154,11 @@ namespace Perspex.Controls.Primitives
if (this.Orientation == Orientation.Horizontal) 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 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)) if (!double.IsNaN(offset) && !double.IsInfinity(offset))

6
Perspex.Controls/Shapes/Ellipse.cs

@ -18,12 +18,12 @@ namespace Perspex.Controls.Shapes
{ {
get 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); rect = rect.Deflate(this.StrokeThickness / 2);
this.geometry = new EllipseGeometry(rect); this.geometry = new EllipseGeometry(rect);
this.geometrySize = this.ActualSize; this.geometrySize = this.Bounds.Size;
} }
return this.geometry; return this.geometry;

6
Perspex.Controls/Shapes/Rectangle.cs

@ -18,10 +18,10 @@ namespace Perspex.Controls.Shapes
{ {
get 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.geometry = new RectangleGeometry(new Rect(0, 0, this.Bounds.Size.Width, this.Bounds.Size.Height));
this.geometrySize = this.ActualSize; this.geometrySize = this.Bounds.Size;
} }
return this.geometry; return this.geometry;

2
Perspex.Controls/TextBlock.cs

@ -120,7 +120,7 @@ namespace Perspex.Controls
if (background != null) 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); context.DrawText(this.Foreground, new Point(), this.FormattedText);

12
Perspex.Layout/Layoutable.cs

@ -29,9 +29,6 @@ namespace Perspex.Layout
public class Layoutable : Visual, ILayoutable, IEnableLogger public class Layoutable : Visual, ILayoutable, IEnableLogger
{ {
public static readonly PerspexProperty<Size> ActualSizeProperty =
PerspexProperty.Register<Layoutable, Size>("ActualSize");
public static readonly PerspexProperty<double> WidthProperty = public static readonly PerspexProperty<double> WidthProperty =
PerspexProperty.Register<Layoutable, double>("Width", double.NaN); PerspexProperty.Register<Layoutable, double>("Width", double.NaN);
@ -131,11 +128,6 @@ namespace Perspex.Layout
set { this.SetValue(VerticalAlignmentProperty, value); } set { this.SetValue(VerticalAlignmentProperty, value); }
} }
public Size ActualSize
{
get { return this.GetValue(ActualSizeProperty); }
}
public Size? DesiredSize public Size? DesiredSize
{ {
get; get;
@ -327,9 +319,7 @@ namespace Perspex.Layout
break; break;
} }
var bounds = new Rect(originX, originY, size.Width, size.Height); this.Bounds = new Rect(originX, originY, size.Width, size.Height);
this.SetVisualBounds(bounds);
this.SetValue(ActualSizeProperty, bounds.Size);
} }
} }

21
Perspex.SceneGraph/Visual.cs

@ -21,6 +21,9 @@ namespace Perspex
public class Visual : Animatable, IVisual public class Visual : Animatable, IVisual
{ {
public static readonly PerspexProperty<Rect> BoundsProperty =
PerspexProperty.Register<Visual, Rect>("Bounds");
public static readonly PerspexProperty<bool> ClipToBoundsProperty = public static readonly PerspexProperty<bool> ClipToBoundsProperty =
PerspexProperty.Register<Visual, bool>("ClipToBounds"); PerspexProperty.Register<Visual, bool>("ClipToBounds");
@ -36,8 +39,6 @@ namespace Perspex
public static readonly PerspexProperty<Origin> TransformOriginProperty = public static readonly PerspexProperty<Origin> TransformOriginProperty =
PerspexProperty.Register<Visual, Origin>("TransformOrigin", defaultValue: Origin.Default); PerspexProperty.Register<Visual, Origin>("TransformOrigin", defaultValue: Origin.Default);
private Rect bounds;
private PerspexList<IVisual> visualChildren; private PerspexList<IVisual> visualChildren;
private Visual visualParent; private Visual visualParent;
@ -54,6 +55,12 @@ namespace Perspex
this.visualChildren.CollectionChanged += this.VisualChildrenChanged; this.visualChildren.CollectionChanged += this.VisualChildrenChanged;
} }
public Rect Bounds
{
get { return this.GetValue(BoundsProperty); }
protected set { this.SetValue(BoundsProperty, value); }
}
public bool ClipToBounds public bool ClipToBounds
{ {
get { return this.GetValue(ClipToBoundsProperty); } get { return this.GetValue(ClipToBoundsProperty); }
@ -84,11 +91,6 @@ namespace Perspex
set { this.SetValue(TransformOriginProperty, value); } set { this.SetValue(TransformOriginProperty, value); }
} }
Rect IVisual.Bounds
{
get { return this.bounds; }
}
IPerspexReadOnlyList<IVisual> IVisual.VisualChildren IPerspexReadOnlyList<IVisual> IVisual.VisualChildren
{ {
get { return this.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) protected virtual void OnAttachedToVisualTree(IRenderRoot root)
{ {
} }

2
Perspex.Themes.Default/DropDownStyle.cs

@ -99,7 +99,7 @@ namespace Perspex.Themes.Default
PlacementTarget = control, PlacementTarget = control,
StaysOpen = false, StaysOpen = false,
[~~Popup.IsOpenProperty] = control[~~DropDown.IsDropDownOpenProperty], [~~Popup.IsOpenProperty] = control[~~DropDown.IsDropDownOpenProperty],
[~Popup.MinWidthProperty] = control[~DropDown.ActualSizeProperty].Cast<Size>().Select(x => (object)x.Width), [~Popup.MinWidthProperty] = control[~DropDown.BoundsProperty].Cast<Rect>().Select(x => (object)x.Width),
} }
}, },
}, },

16
Tests/Perspex.Layout.UnitTests/FullLayoutTests.cs

@ -57,11 +57,11 @@ namespace Perspex.Layout.UnitTests
window.LayoutManager.ExecuteLayoutPass(); window.LayoutManager.ExecuteLayoutPass();
Assert.Equal(new Size(400, 400), border.ActualSize); Assert.Equal(new Size(400, 400), border.Bounds.Size);
textBlock.Width = 200; textBlock.Width = 200;
window.LayoutManager.ExecuteLayoutPass(); 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(); window.LayoutManager.ExecuteLayoutPass();
Assert.Equal(new Size(800, 600), window.ActualSize); Assert.Equal(new Size(800, 600), window.Bounds.Size);
Assert.Equal(new Size(200, 200), scrollViewer.ActualSize); Assert.Equal(new Size(200, 200), scrollViewer.Bounds.Size);
Assert.Equal(new Point(300, 200), Position(scrollViewer)); 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<ScrollBar>().ToList(); var scrollBars = scrollViewer.GetTemplateChildren().OfType<ScrollBar>().ToList();
var presenters = scrollViewer.GetTemplateChildren().OfType<ScrollContentPresenter>().ToList(); var presenters = scrollViewer.GetTemplateChildren().OfType<ScrollContentPresenter>().ToList();
@ -109,15 +109,15 @@ namespace Perspex.Layout.UnitTests
Assert.Equal(1, presenters.Count); Assert.Equal(1, presenters.Count);
var presenter = presenters[0]; 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 horzScroll = scrollBars.Single(x => x.Orientation == Orientation.Horizontal);
var vertScroll = scrollBars.Single(x => x.Orientation == Orientation.Vertical); var vertScroll = scrollBars.Single(x => x.Orientation == Orientation.Vertical);
Assert.True(horzScroll.IsVisible); Assert.True(horzScroll.IsVisible);
Assert.True(vertScroll.IsVisible); Assert.True(vertScroll.IsVisible);
Assert.Equal(new Size(190, 10), horzScroll.ActualSize); Assert.Equal(new Size(190, 10), horzScroll.Bounds.Size);
Assert.Equal(new Size(10, 190), vertScroll.ActualSize); Assert.Equal(new Size(10, 190), vertScroll.Bounds.Size);
Assert.Equal(new Point(0, 190), Position(horzScroll)); Assert.Equal(new Point(0, 190), Position(horzScroll));
Assert.Equal(new Point(190, 0), Position(vertScroll)); Assert.Equal(new Point(190, 0), Position(vertScroll));
} }

Loading…
Cancel
Save