Skip to content

Commit

Permalink
Merge pull request #2270 from unoplatform/dev/cdb/bugs/layouter-min-size
Browse files Browse the repository at this point in the history
Remove "min size" constrains to available size in layouter
  • Loading branch information
mergify[bot] authored Dec 10, 2019
2 parents b5610ec + 784fce7 commit f471952
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\UIElement_Layout_Constrains.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\VisualStateTests\VisualState_AdaptiveTrigger_Storyboard.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -2932,11 +2936,14 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\TouchEventsTests\TouchViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\TransformToVisual_ScrollViewer.xaml.cs">
<DependentUpon>$fileinputname$.xaml</DependentUpon>
<DependentUpon>TransformToVisual_ScrollViewer.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\TransformToVisual_Transform.xaml.cs">
<DependentUpon>TransformToVisual_Transform.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\UIElementTests\UIElement_Layout_Constrains.xaml.cs">
<DependentUpon>UIElement_Layout_Constrains.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml\VisualStateTests\VisualState_AdaptiveTrigger_UsingOneStateOnly.xaml.cs">
<DependentUpon>VisualState_AdaptiveTrigger_UsingOneStateOnly.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<Page
x:Class="UITests.Shared.Windows_UI_Xaml.UIElementTests.UIElement_Layout_Constrains"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:toolkit="using:Uno.UI.Toolkit"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<ScrollViewer>
<StackPanel Spacing="12" toolkit:VisibleBoundsPadding.PaddingMask="All">
<TextBlock FontSize="18">Following controls should be of same look:</TextBlock>

<Border Height="40" Background="Aquamarine">

<StackPanel Orientation="Horizontal" Spacing="10">
<Button Width="80" VerticalAlignment="Stretch" Padding="5">BUTTON</Button>
<Button Width="80" Height="60" VerticalAlignment="Center" Padding="5">BUTTON</Button>
<Button Width="80" Height="80" Padding="5">BUTTON</Button>
</StackPanel>
</Border>

<TextBlock FontSize="18">Following controls should be of same look:</TextBlock>

<Border Background="Orange" Height="28">
<StackPanel Orientation="Horizontal" Spacing="10">
<Button Width="65" Padding="0" VerticalAlignment="Stretch">
<Border BorderThickness="2" BorderBrush="Blue">
<TextBlock FontSize="8" Padding="0">
BUTTON
</TextBlock>
</Border>
</Button>
<Button Width="65" Padding="0" Height="36">
<Border BorderThickness="2" BorderBrush="Blue">
<TextBlock FontSize="8" Padding="0">
BUTTON
</TextBlock>
</Border>
</Button>
<Button Width="65" Padding="0" Height="36" VerticalAlignment="Center">
<Border BorderThickness="2" BorderBrush="Blue">
<TextBlock FontSize="8" Padding="0">
BUTTON
</TextBlock>
</Border>
</Button>
</StackPanel>
</Border>

<Grid ColumnSpacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Rectangle Width="100" HorizontalAlignment="Left" Fill="DarkSeaGreen"></Rectangle>
<StackPanel Spacing="3">
<TextBlock>green width is 100</TextBlock>
<Border BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" MaxWidth="100">
<TextBlock>Max=100</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" MaxWidth="100">
<TextBlock TextWrapping="NoWrap">Max=100 + very long text</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" MaxWidth="40" MinWidth="80">
<TextBlock TextWrapping="NoWrap">Max=40<LineBreak />Min=80</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" Width="100">
<TextBlock>Width=100</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" MinWidth="80" MaxWidth="120">
<TextBlock>min/max<LineBreak />80/120</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" MinWidth="80" MaxWidth="40">
<TextBlock>min/max<LineBreak />80/40</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" HorizontalAlignment="Left" MinWidth="80" MaxWidth="120">
<TextBlock TextWrapping="NoWrap">min/max<LineBreak />80/120 + very very very long text</TextBlock>
</Border>
</StackPanel>
<Rectangle Height="100" VerticalAlignment="Top" Fill="LightPink" Grid.Column="1"></Rectangle>
<StackPanel Orientation="Horizontal" Grid.Column="1" Spacing="3">
<TextBlock>pink height is 100</TextBlock>
<Border BorderBrush="Blue" BorderThickness="2" VerticalAlignment="Top" MaxHeight="100">
<TextBlock>MaxH=100<LineBreak />+<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />long<LineBreak />text</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" VerticalAlignment="Top" MaxHeight="100">
<TextBlock>MaxH=100</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" VerticalAlignment="Top" MaxHeight="10" MinHeight="50">
<TextBlock>MaxH=100, MinH=50<LineBreak />+<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />long<LineBreak />text</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" VerticalAlignment="Top" Height="100">
<TextBlock>H=100</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" VerticalAlignment="Top" MinHeight="80" MaxHeight="120">
<TextBlock>min/max<LineBreak />80/120</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" VerticalAlignment="Top" MinHeight="80" MaxHeight="40">
<TextBlock>min/max<LineBreak />80/40</TextBlock>
</Border>
<Border BorderBrush="Blue" BorderThickness="2" VerticalAlignment="Top" MinHeight="80" MaxHeight="120">
<TextBlock>min/max<LineBreak />80/120<LineBreak />+<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />very<LineBreak />long<LineBreak />text</TextBlock>
</Border>
</StackPanel>
</Grid>

</StackPanel>
</ScrollViewer>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Windows.UI.Xaml.Controls;
using Uno.UI.Samples.Controls;

namespace UITests.Shared.Windows_UI_Xaml.UIElementTests
{
[SampleControlInfo("UIElement")]
public sealed partial class UIElement_Layout_Constrains : Page
{
public UIElement_Layout_Constrains()
{
this.InitializeComponent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using Windows.UI.Core;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Private.Infrastructure;

namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls
{
Expand Down Expand Up @@ -140,6 +142,52 @@ await Dispatch(() =>
}
#endif

[TestMethod]
public async Task When_MinWidth_SmallerThan_AvailableSize()
{
Border content = null;
ContentControl contentCtl = null;
Grid grid = null;

await Dispatch(() =>
{
content = new Border { Width = 100, Height = 15 };

contentCtl = new ContentControl { MinWidth = 110, Content = content };

grid = new Grid() { MinWidth = 120 };

grid.Children.Add(contentCtl);

grid.Measure(new Size(50, 50));
#if NETFX_CORE || __WASM__ // TODO: align all platforms with Windows here
Assert.AreEqual(new Size(50, 15), grid.DesiredSize);
Assert.AreEqual(new Size(110, 15), contentCtl.DesiredSize);
Assert.AreEqual(new Size(100, 15), content.DesiredSize);
#endif

grid.Arrange(new Rect(default, new Size(50, 50)));

TestServices.WindowHelper.WindowContent = new Border { Child = grid, Width = 50, Height = 50 };
});

await TestServices.WindowHelper.WaitForIdle();
await Dispatch(() => { });
await TestServices.WindowHelper.WaitForIdle();

await Dispatch(() =>
{
var ls1 = LayoutInformation.GetLayoutSlot(grid);
Assert.AreEqual(new Rect(0, 0, 50, 50), ls1);
#if NETFX_CORE || __WASM__ // TODO: align all platforms with Windows here
var ls2 = LayoutInformation.GetLayoutSlot(contentCtl);
Assert.AreEqual(new Rect(0, 0, 120, 50), ls2);
var ls3 = LayoutInformation.GetLayoutSlot(content);
Assert.AreEqual(new Rect(0, 0, 100, 15), ls3);
#endif
});
}

[TestMethod]
[RunsOnUIThread]
public void Check_ActualWidth_After_Measure()
Expand Down
10 changes: 4 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/Layouter/Layouter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #define LOG_LAYOUT
// #define LOG_LAYOUT

using Microsoft.Extensions.Logging;
using Uno.UI;
Expand Down Expand Up @@ -98,8 +98,7 @@ public Size Measure(Size availableSize)
.NumberOrDefault(MaxSize)
.Subtract(marginSize)
.AtLeast(default) // 0.0,0.0
.AtMost(maxSize)
.AtLeast(minSize);
.AtMost(maxSize);

var desiredSize = MeasureOverride(frameworkAvailableSize);

Expand Down Expand Up @@ -204,7 +203,6 @@ public void Arrange(Rect finalRect)
var (minSize, maxSize) = this.Panel.GetMinMax();

arrangeSize = arrangeSize
.AtLeast(minSize)
.AtLeast(default); // 0.0,0.0

// We have to choose max between _unclippedDesiredSize and maxSize here, because
Expand Down Expand Up @@ -405,7 +403,7 @@ protected Size MeasureChild(View view, Size slotSize)
// Report the size to the parent without the margin, only if the
// size has changed or that the control required a measure
//
// This condition is required because of the measure caching that
// This condition is required because of the measure caching that
// some systems apply (Like android UI).
ret = new Size(
ret.Width + margin.Left + margin.Right,
Expand Down Expand Up @@ -475,7 +473,7 @@ private Rect ApplyMarginAndAlignments(View view, Rect frame)
{
// In this implementation, since we do not have the ability to intercept proprely the measure and arrange
// because of the type of hierarchy (inheriting from native views), we must apply the margins and alignements
// from within the panel to its children. This makes the authoring of custom panels that do not inherit from
// from within the panel to its children. This makes the authoring of custom panels that do not inherit from
// Panel that do not use this helper a bit more complex, but for all other panels that use this
// layouter, the logic is implied.

Expand Down
5 changes: 2 additions & 3 deletions src/Uno.UI/UI/Xaml/FrameworkElement.Layout.wasm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Globalization;
using System.Linq;
using Uno.Diagnostics.Eventing;
Expand Down Expand Up @@ -75,8 +75,7 @@ private Size InnerMeasureCore(Size availableSize)
.NumberOrDefault(MaxSize)
.Subtract(marginSize)
.AtLeast(new Size(0, 0))
.AtMost(maxSize)
.AtLeast(minSize);
.AtMost(maxSize);

var desiredSize = MeasureOverride(frameworkAvailableSize);

Expand Down

0 comments on commit f471952

Please sign in to comment.