From b04bcf48a1ebf4a1ce294588f056a0bc73ea42db Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sat, 29 Nov 2014 12:58:23 +0100 Subject: [PATCH] Fixed layout again. Last commit actually ruined layout. Added a tab to the test app to test that shiz. --- Perspex.Controls/Button.cs | 10 ++++++++ Perspex.Layout/Layoutable.cs | 2 +- TestApplication/Program.cs | 48 +++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Perspex.Controls/Button.cs b/Perspex.Controls/Button.cs index c6ef99954f..4f92794c93 100644 --- a/Perspex.Controls/Button.cs +++ b/Perspex.Controls/Button.cs @@ -48,5 +48,15 @@ namespace Perspex.Controls add { this.AddHandler(ClickEvent, value); } remove { this.RemoveHandler(ClickEvent, value); } } + + protected override Size MeasureOverride(Size availableSize) + { + return base.MeasureOverride(availableSize); + } + + protected override Size ArrangeOverride(Size finalSize) + { + return base.ArrangeOverride(finalSize); + } } } diff --git a/Perspex.Layout/Layoutable.cs b/Perspex.Layout/Layoutable.cs index 561bc69c70..073501f79e 100644 --- a/Perspex.Layout/Layoutable.cs +++ b/Perspex.Layout/Layoutable.cs @@ -197,7 +197,7 @@ namespace Perspex.Layout size = size.WithHeight(Math.Min(size.Height, this.DesiredSize.Value.Height)); } - size = LayoutHelper.ApplyLayoutConstraints(this, finalRect.Size); + size = LayoutHelper.ApplyLayoutConstraints(this, size); size = this.ArrangeOverride(size).Constrain(size); switch (this.HorizontalAlignment) diff --git a/TestApplication/Program.cs b/TestApplication/Program.cs index 78abc41a3d..2cfa64ad23 100644 --- a/TestApplication/Program.cs +++ b/TestApplication/Program.cs @@ -117,6 +117,7 @@ namespace TestApplication TextTab(), ListsTab(), SlidersTab(), + LayoutTab(), } }, new TextBlock @@ -127,7 +128,7 @@ namespace TestApplication [Grid.RowProperty] = 1, } } - } + }, }; window.Show(); @@ -277,5 +278,50 @@ namespace TestApplication }; } + private static TabItem LayoutTab() + { + return new TabItem + { + Header = "Layout", + Content = new Grid + { + ColumnDefinitions = new ColumnDefinitions + { + new ColumnDefinition(1, GridUnitType.Star), + new ColumnDefinition(1, GridUnitType.Star), + }, + Margin = new Thickness(50), + Children = new Controls + { + new StackPanel + { + Orientation = Orientation.Vertical, + Gap = 8, + Children = new Controls + { + new Button { HorizontalAlignment = HorizontalAlignment.Left, Content = "Left Aligned" }, + new Button { HorizontalAlignment = HorizontalAlignment.Center, Content = "Center Aligned" }, + new Button { HorizontalAlignment = HorizontalAlignment.Right, Content = "Right Aligned" }, + new Button { HorizontalAlignment = HorizontalAlignment.Stretch, Content = "Stretch" }, + }, + [Grid.ColumnProperty] = 0, + }, + new StackPanel + { + Orientation = Orientation.Horizontal, + Gap = 8, + Children = new Controls + { + new Button { VerticalAlignment = VerticalAlignment.Top, Content = "Top Aligned" }, + new Button { VerticalAlignment = VerticalAlignment.Center, Content = "Center Aligned" }, + new Button { VerticalAlignment = VerticalAlignment.Bottom, Content = "Bottom Aligned" }, + new Button { VerticalAlignment = VerticalAlignment.Stretch, Content = "Stretch" }, + }, + [Grid.ColumnProperty] = 1, + }, + }, + } + }; + } } }