Beispiel #1
0
		public void TestSizeRequestWithPadding ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid {Platform = platform, IsPlatformEnabled = true, Padding = new Thickness(20, 10, 15, 5)};
			layout.Children.AddVertical (new[] {
				new View {Platform = platform, IsPlatformEnabled = true},
				new View {Platform = platform, IsPlatformEnabled = true},
				new View {Platform = platform, IsPlatformEnabled = true}
			});

			var result = layout.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity).Request;
			Assert.AreEqual (new Size (135, 87), result);
		}
Beispiel #2
0
		public void TestStarLayout ()
		{
			var platform = new UnitPlatform ();
			var layout = new Grid ();
			layout.Platform = platform;

			var label1 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label2 = new Label {Platform = platform, IsPlatformEnabled = true};
			var label3 = new Label {Platform = platform, IsPlatformEnabled = true};

			layout.ColumnDefinitions = new ColumnDefinitionCollection { 
				new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)},
				new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)},
				new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)},
			};
			layout.RowDefinitions = new RowDefinitionCollection {
				new RowDefinition {Height = new GridLength (1, GridUnitType.Star)},
				new RowDefinition {Height = new GridLength (1, GridUnitType.Star)},
				new RowDefinition {Height = new GridLength (1, GridUnitType.Star)},
			};
			layout.Children.Add (label1, 0, 0);
			layout.Children.Add (label2, 1, 1);
			layout.Children.Add (label3, 2, 2);

			var request = layout.GetSizeRequest (1002, 462);
			Assert.AreEqual (312, request.Request.Width);
			Assert.AreEqual (72, request.Request.Height);

			layout.Layout (new Rectangle (0, 0, 1002, 462));
			Assert.AreEqual (1002, layout.Width);
			Assert.AreEqual (462, layout.Height);

			Assert.AreEqual (new Rectangle (0, 0, 330, 150), label1.Bounds);
			Assert.AreEqual (new Rectangle (336, 156, 330, 150), label2.Bounds);
			Assert.AreEqual (new Rectangle (672, 312, 330, 150), label3.Bounds);
		}
Beispiel #3
0
		public void TestLimitedHeightSizeRequest ()
		{

			var platform = new UnitPlatform ();
			var layout = new Grid {Platform = platform, IsPlatformEnabled = true};
			layout.Children.AddVertical (new[] {
				new View {Platform = platform, IsPlatformEnabled = true},
				new View {Platform = platform, IsPlatformEnabled = true},
				new View {Platform = platform, IsPlatformEnabled = true}
			});

			var result = layout.GetSizeRequest (double.PositiveInfinity, 10).Request;
			Assert.AreEqual (new Size (100, 72), result);
		}
Beispiel #4
0
		public void TestZeroSizeConstraints ()
		{
			var layout = new Grid {Platform = new UnitPlatform ()};

			Assert.AreEqual (new Size (0, 0), layout.GetSizeRequest (0, 0).Request);
			Assert.AreEqual (new Size (0, 0), layout.GetSizeRequest (0, 10).Request);
			Assert.AreEqual (new Size (0, 0), layout.GetSizeRequest (10, 0).Request);
		}
Beispiel #5
0
		//https://bugzilla.xamarin.com/show_bug.cgi?id=31967
		public void ChangingRowHeightViaBindingTriggersRedraw ()
		{
			var rowdef = new RowDefinition ();
			rowdef.SetBinding (RowDefinition.HeightProperty, "Height");
			var grid = new Grid {
//				RowDefinitions = new RowDefinitionCollection {
//					new RowDefinition { Height = GridLength.Auto },
//					rowdef
//				},
				RowSpacing = 0,
				Platform = new UnitPlatform (),
				IsPlatformEnabled = true,
			};
			grid.RowDefinitions.Add (new RowDefinition { Height = GridLength.Auto });
			grid.RowDefinitions.Add (rowdef);

			var label0 = new Label { IsPlatformEnabled = true };
			Grid.SetRow (label0, 0);
			var label1 = new Label { IsPlatformEnabled = true };
			Grid.SetRow (label1, 1);

			grid.BindingContext = new {Height = 0};
			grid.Children.Add (label0);
			grid.Children.Add (label1);

			Assert.AreEqual (new SizeRequest (new Size (100, 20), new Size (0, 20)), grid.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity));
			grid.BindingContext = new {Height = 42};
			Assert.AreEqual (new SizeRequest (new Size (100, 62), new Size (0, 62)), grid.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity));
		}
Beispiel #6
0
		public void WidthBoundRequestRespected ()
		{
			var grid = new Grid {
				ColumnDefinitions = {
					new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
					new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
				},
				RowDefinitions = {
					new RowDefinition { Height = GridLength.Auto },
					new RowDefinition { Height = GridLength.Auto },
				},
				Platform = new UnitPlatform (GetResizableSize),
				IsPlatformEnabled = true,
				RowSpacing = 0,
				ColumnSpacing = 0,
			};

			var topLabel = new Editor {IsPlatformEnabled = true};
			var leftLabel = new Label {IsPlatformEnabled = true, WidthRequest = 10};
			var rightLabel = new Label {IsPlatformEnabled = true, WidthRequest = 10};

			grid.Children.Add (topLabel, 0, 2, 0, 1);
			grid.Children.Add (leftLabel, 0, 1);
			grid.Children.Add (rightLabel, 1, 1);

			var unboundRequest = grid.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity);
			var widthBoundRequest = grid.GetSizeRequest (50, double.PositiveInfinity);

			Assert.AreEqual (new SizeRequest (new Size (20, 120), new Size (0, 120)), unboundRequest);
			Assert.AreEqual (new SizeRequest (new Size (50, 60), new Size (0, 60)), widthBoundRequest);
		}
Beispiel #7
0
		public void SizeRequestForStar ()
		{
			var platform = new UnitPlatform ();

			var grid = new Grid{ 
				RowDefinitions = new RowDefinitionCollection {
					new RowDefinition {Height = new GridLength (1, GridUnitType.Star)},
					new RowDefinition {Height = GridLength.Auto},
				},
				ColumnDefinitions = new ColumnDefinitionCollection {
					new ColumnDefinition {Width = new GridLength (1, GridUnitType.Star)},
					new ColumnDefinition {Width = GridLength.Auto},
				}
			};
			grid.Children.Add (new Label {BackgroundColor = Color.Lime, Text="Foo", Platform = platform, IsPlatformEnabled = true});
			grid.Children.Add (new Label {Text = "Bar", Platform = platform, IsPlatformEnabled = true},0,1);
			grid.Children.Add (new Label {Text="Baz",XAlign = TextAlignment.End, Platform = platform, IsPlatformEnabled = true},1,0);
			grid.Children.Add (new Label {Text="Qux", XAlign = TextAlignment.End, Platform = platform, IsPlatformEnabled = true},1,1);

			var request = grid.GetSizeRequest (double.PositiveInfinity, double.PositiveInfinity);
			Assert.AreEqual (206, request.Request.Width);
			Assert.AreEqual (46, request.Request.Height);

			Assert.AreEqual (106, request.Minimum.Width);
			Assert.AreEqual (26, request.Minimum.Height);
			//
		}