diff --git a/Perspex/Controls/StackPanel.cs b/Perspex/Controls/StackPanel.cs index 6d2ddc6404..9a7ab81318 100644 --- a/Perspex/Controls/StackPanel.cs +++ b/Perspex/Controls/StackPanel.cs @@ -138,18 +138,8 @@ namespace Perspex.Controls else { childHeight = finalSize.Height; - Rect childFinal = new Rect(arrangedWidth, 0, childWidth, childHeight); - - if (childFinal.IsEmpty) - { - child.Arrange(new Rect()); - } - else - { - child.Arrange(childFinal); - } - + child.Arrange(childFinal); arrangedWidth += childWidth + gap; arrangedHeight = Math.Max(arrangedHeight, childHeight); } diff --git a/Perspex/Media/RectangleGeometry.cs b/Perspex/Media/RectangleGeometry.cs new file mode 100644 index 0000000000..f04db66b36 --- /dev/null +++ b/Perspex/Media/RectangleGeometry.cs @@ -0,0 +1,35 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Media +{ + using System; + using Splat; + + public class RectangleGeometry : Geometry + { + public RectangleGeometry(Rect rect) + { + IStreamGeometryImpl impl = Locator.Current.GetService(); + + using (IStreamGeometryContextImpl context = impl.Open()) + { + context.BeginFigure(rect.TopLeft, true); + context.LineTo(rect.TopRight); + context.LineTo(rect.BottomRight); + context.LineTo(rect.BottomLeft); + context.EndFigure(true); + } + + this.PlatformImpl = impl; + } + + public override Rect Bounds + { + get { return this.PlatformImpl.Bounds; } + } + } +} diff --git a/Perspex/Perspex.csproj b/Perspex/Perspex.csproj index 5c7cd43d9c..423f63861a 100644 --- a/Perspex/Perspex.csproj +++ b/Perspex/Perspex.csproj @@ -87,10 +87,12 @@ + + diff --git a/Perspex/Rect.cs b/Perspex/Rect.cs index 3dd3db62ca..56c99a1f4e 100644 --- a/Perspex/Rect.cs +++ b/Perspex/Rect.cs @@ -122,6 +122,54 @@ namespace Perspex get { return new Size(this.width, this.height); } } + /// + /// Gets the right position of the rectangle. + /// + public double Right + { + get { return this.x + this.width; } + } + + /// + /// Gets the bottom position of the rectangle. + /// + public double Bottom + { + get { return this.y + this.height; } + } + + /// + /// Gets the top left point of the rectangle. + /// + public Point TopLeft + { + get { return new Point(this.x, this.y); } + } + + /// + /// Gets the top right point of the rectangle. + /// + public Point TopRight + { + get { return new Point(this.Right, this.y); } + } + + /// + /// Gets the bottom left point of the rectangle. + /// + public Point BottomLeft + { + get { return new Point(this.x, this.Bottom); } + } + + /// + /// Gets the bottom right point of the rectangle. + /// + public Point BottomRight + { + get { return new Point(this.Right, this.Bottom); } + } + /// /// Gets a value that indicates whether the rectangle is empty. /// diff --git a/Perspex/Shapes/Path.cs b/Perspex/Shapes/Path.cs index b0ba2d0897..534a7fc753 100644 --- a/Perspex/Shapes/Path.cs +++ b/Perspex/Shapes/Path.cs @@ -24,13 +24,5 @@ namespace Perspex.Shapes { get { return this.Data; } } - - public override void Render(IDrawingContext context) - { - if (this.Data != null && this.Visibility == Visibility.Visible) - { - context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.Data); - } - } } } diff --git a/Perspex/Shapes/Rectangle.cs b/Perspex/Shapes/Rectangle.cs new file mode 100644 index 0000000000..d62809f0fb --- /dev/null +++ b/Perspex/Shapes/Rectangle.cs @@ -0,0 +1,33 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.Shapes +{ + using System; + using System.Reactive.Linq; + using Perspex.Media; + + public class Rectangle : Shape + { + private Size size; + + public override Geometry DefiningGeometry + { + get { return new RectangleGeometry(new Rect(size)); } + } + + protected override Size MeasureContent(Size availableSize) + { + return new Size(this.Width, this.Height); + } + + protected override Size ArrangeContent(Size finalSize) + { + this.size = finalSize; + return base.ArrangeContent(finalSize); + } + } +} diff --git a/Perspex/Shapes/Shape.cs b/Perspex/Shapes/Shape.cs index ea668338d0..068b5e8520 100644 --- a/Perspex/Shapes/Shape.cs +++ b/Perspex/Shapes/Shape.cs @@ -60,20 +60,14 @@ namespace Perspex.Shapes protected override Size MeasureContent(Size availableSize) { - Pen pen = (this.Stroke != null) ? new Pen(this.Stroke, this.StrokeThickness) : null; Rect shapeBounds = this.RenderedGeometry.Bounds; + double width = this.Width; + double height = this.Height; double desiredX = availableSize.Width; double desiredY = availableSize.Height; double sx = 0.0; double sy = 0.0; - if (this.Stretch == Stretch.None) - { - return new Size( - shapeBounds.X + shapeBounds.Width, - shapeBounds.Y + shapeBounds.Height); - } - if (double.IsInfinity(availableSize.Width)) { desiredX = shapeBounds.Width; @@ -125,10 +119,21 @@ namespace Perspex.Shapes break; default: + sx = sy = 1; break; } - return new Size(shapeBounds.Width * sx, shapeBounds.Height * sy); + double finalX = (width > 0) ? width : shapeBounds.Width * sx; + double finalY = (height > 0) ? height : shapeBounds.Height * sy; + return new Size(finalX, finalY); + } + + public override void Render(IDrawingContext context) + { + if (this.RenderedGeometry != null && this.Visibility == Visibility.Visible) + { + context.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.RenderedGeometry); + } } } } diff --git a/Perspex/Themes/Default/CheckBoxStyle.cs b/Perspex/Themes/Default/CheckBoxStyle.cs index 682d9b2369..a1d50ac20f 100644 --- a/Perspex/Themes/Default/CheckBoxStyle.cs +++ b/Perspex/Themes/Default/CheckBoxStyle.cs @@ -53,19 +53,22 @@ namespace Perspex.Themes.Default Gap = 8, Children = new PerspexList { - new Border + new Rectangle { - BorderThickness = 2, - BorderBrush = Brushes.Black, - Padding = new Thickness(8), - Content = new Path - { - Id = "checkMark", - Data = StreamGeometry.Parse("M0,0 L10,10 M10,0 L0,10"), - Stroke = Brushes.Black, - StrokeThickness = 2, - VerticalAlignment = VerticalAlignment.Center, - }, + Id = "checkBorder", + Stroke = Brushes.Black, + StrokeThickness = 2, + Width = 16, + Height = 16, + VerticalAlignment = VerticalAlignment.Center, + }, + new Path + { + Id = "checkMark", + Data = StreamGeometry.Parse("M0,0 L10,10 M10,0 L0,10"), + Stroke = Brushes.Black, + StrokeThickness = 2, + VerticalAlignment = VerticalAlignment.Center, }, new ContentPresenter { @@ -76,7 +79,7 @@ namespace Perspex.Themes.Default result.TemplateBinding(control, Border.BackgroundProperty); StackPanel stack = (StackPanel)result.Content; - ContentPresenter cp = (ContentPresenter)stack.Children[1]; + ContentPresenter cp = (ContentPresenter)stack.Children[2]; cp.TemplateBinding(control, ContentPresenter.ContentProperty); return result; } diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index a7e342c78d..014a2e59ab 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -52,19 +52,6 @@ namespace TestApplication Gap = 6, Children = new PerspexList { - new Border - { - BorderBrush = Brushes.Black, - BorderThickness = 1, - Width = 10, - Height = 10, - }, - new Path - { - Data = StreamGeometry.Parse("M0,0 L10,0"), - Stroke = Brushes.Black, - StrokeThickness = 1, - }, new Button { Content = "Button",