public void TestMarginWithSiblingRow() { var platform = new UnitPlatform((visual, width, height) => new SizeRequest(new Size(0, 0))); var view0 = new View { Platform = platform, IsPlatformEnabled = true, Margin = new Thickness(0, 0, 10, 0) }; FlexLayout.SetGrow(view0, 1); var view1 = new View { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(view1, 1); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { view0, view1, }, Direction = FlexDirection.Row, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 45, 100))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(55, 0, 45, 100))); }
public void TestFlexDirectionColumnWithoutHeight() { var platform = new UnitPlatform(); var view0 = new View { Platform = platform, IsPlatformEnabled = true, HeightRequest = 10 }; var view1 = new View { Platform = platform, IsPlatformEnabled = true, HeightRequest = 10 }; var view2 = new View { Platform = platform, IsPlatformEnabled = true, HeightRequest = 10 }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { view0, view1, view2, }, Direction = FlexDirection.Column, }; var sizeRequest = layout.Measure(100, double.PositiveInfinity); layout.Layout(new Rectangle(0, 0, sizeRequest.Request.Width, sizeRequest.Request.Height)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 30))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 10))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(0, 10, 100, 10))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(0, 20, 100, 10))); }
public void TestMarginWithSiblingColumn() { var platform = new UnitPlatform(); var view0 = new View { Platform = platform, IsPlatformEnabled = true, Margin = new Thickness(0, 0, 0, 10) }; FlexLayout.SetGrow(view0, 1); var view1 = new View { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(view1, 1); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { view0, view1, }, Direction = FlexDirection.Column, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 45))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(0, 55, 100, 45))); }
public void TestFlexDirectionRowNoWidth() { var platform = new UnitPlatform(); var view0 = new View { Platform = platform, IsPlatformEnabled = true, WidthRequest = 10, }; var view1 = new View { Platform = platform, IsPlatformEnabled = true, WidthRequest = 10, }; var view2 = new View { Platform = platform, IsPlatformEnabled = true, WidthRequest = 10, }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { view0, view1, view2, }, Direction = FlexDirection.Row, }; var measure = layout.Measure(double.PositiveInfinity, 100); layout.Layout(new Rectangle(0, 0, measure.Request.Width, measure.Request.Height)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 30, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 10, 100))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(10, 0, 10, 100))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(20, 0, 10, 100))); }
public void TestFlexDirectionRowReverse() { var platform = new UnitPlatform(); var view0 = new View { Platform = platform, IsPlatformEnabled = true, WidthRequest = 10, }; var view1 = new View { Platform = platform, IsPlatformEnabled = true, WidthRequest = 10, }; var view2 = new View { Platform = platform, IsPlatformEnabled = true, WidthRequest = 10, }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { view0, view1, view2, }, Direction = FlexDirection.RowReverse, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(90, 0, 10, 100))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(80, 0, 10, 100))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(70, 0, 10, 100))); }
public void NativeSizedChildBehavior() { var plat = new UnitPlatform(); var child = new Label { Platform = plat, IsPlatformEnabled = true, HorizontalOptions = LayoutOptions.Center }; var root = new ContentPage { Platform = plat, IsPlatformEnabled = true, Content = child }; root.Layout(new Rectangle(0, 0, 200, 500)); Assert.AreEqual(50, child.X); Assert.AreEqual(100, child.Width); Assert.AreEqual(500, child.Height); child = new Label() { Platform = plat, IsPlatformEnabled = true, VerticalOptions = LayoutOptions.Center }; root = new ContentPage { Platform = plat, IsPlatformEnabled = true, Content = child }; root.Layout(new Rectangle(0, 0, 200, 500)); Assert.AreEqual(0, child.X); Assert.AreEqual(240, child.Y); Assert.AreEqual(200, child.Width); Assert.AreEqual(20, child.Height); }
public void TestFlexDirectionColumn() { var platform = new UnitPlatform(); var view0 = new View { Platform = platform, IsPlatformEnabled = true, HeightRequest = 10 }; var view1 = new View { Platform = platform, IsPlatformEnabled = true, HeightRequest = 10 }; var view2 = new View { Platform = platform, IsPlatformEnabled = true, HeightRequest = 10 }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { view0, view1, view2, }, Direction = FlexDirection.Column, }; layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 10))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(0, 10, 100, 10))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(0, 20, 100, 10))); }
public void TestBasicLayoutWithElementsWidth() { var platform = new UnitPlatform(); var label1 = new Label { Platform = platform, IsPlatformEnabled = true, WidthRequest = 120 }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true, WidthRequest = 120 }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { label1, label2, } }; layout.Layout(new Rectangle(0, 0, 912, 912)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 912, 912))); Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(0, 0, 120, 912))); Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(120, 0, 120, 912))); }
public void TestMeasuring() { var platform = new UnitPlatform(); var label = new Label { Platform = platform, IsPlatformEnabled = true, }; var Layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, Children = { label, } }; //measure sith +inf as main-axis var measure = Layout.Measure(double.PositiveInfinity, 40); Assert.That(measure.Request, Is.EqualTo(new Size(100, 40))); //measure sith +inf as cross-axis measure = Layout.Measure(200, double.PositiveInfinity); Assert.That(measure.Request, Is.EqualTo(new Size(200, 20))); //measure with +inf as both axis measure = Layout.Measure(double.PositiveInfinity, double.PositiveInfinity); Assert.That(measure.Request, Is.EqualTo(new Size(100, 20))); }
public void TestBasicLayoutWithElementsWidthAndMargin() { var platform = new UnitPlatform(); var label1 = new Label { Platform = platform, IsPlatformEnabled = true, WidthRequest = 100, Margin = new Thickness(5, 0, 0, 0) }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true, WidthRequest = 100, Margin = new Thickness(5, 0, 0, 0) }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { label1, label2, } }; layout.Layout(new Rectangle(0, 0, 912, 912)); Assert.AreEqual(912, layout.Width); Assert.AreEqual(912, layout.Height); Assert.AreEqual(new Rectangle(5, 0, 100, 912), label1.Bounds); Assert.AreEqual(new Rectangle(110, 0, 100, 912), label2.Bounds); }
public void TestBasicHorizontalLayout () { 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.Children.AddHorizontal (new View[] { label1, label2, label3 }); layout.Layout (new Rectangle (0, 0, 912, 912)); Assert.AreEqual (912, layout.Width); Assert.AreEqual (912, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 300, 912), label1.Bounds); Assert.AreEqual (new Rectangle (306, 0, 300, 912), label2.Bounds); Assert.AreEqual (new Rectangle (612, 0, 300, 912), label3.Bounds); }
public void TestNesting() { var platform = new UnitPlatform(); var header = new View { HeightRequest = 50, IsPlatformEnabled = true, }; var footer = new View { HeightRequest = 50, IsPlatformEnabled = true, }; Func <View> createItem = () => { var v = new View { WidthRequest = 50, Margin = 5, IsPlatformEnabled = true, }; FlexLayout.SetGrow(v, 1); return(v); }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Children = { header, new FlexLayout { Direction = FlexDirection.Row, IsPlatformEnabled = true, Children = { createItem(), createItem(), createItem(), createItem(), createItem(), } }, footer, }, Direction = FlexDirection.Column, }; var inner = layout.Children[1] as FlexLayout; FlexLayout.SetGrow(inner, 1); layout.Layout(new Rectangle(0, 0, 300, 600)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 600))); Assert.That(header.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 50))); Assert.That(inner.Bounds, Is.EqualTo(new Rectangle(0, 50, 300, 500))); Assert.That(inner.Children[0].Bounds, Is.EqualTo(new Rectangle(5, 5, 50, 490))); Assert.That(inner.Children[1].Bounds, Is.EqualTo(new Rectangle(65, 5, 50, 490))); Assert.That(inner.Children[2].Bounds, Is.EqualTo(new Rectangle(125, 5, 50, 490))); Assert.That(inner.Children[3].Bounds, Is.EqualTo(new Rectangle(185, 5, 50, 490))); Assert.That(inner.Children[4].Bounds, Is.EqualTo(new Rectangle(245, 5, 50, 490))); Assert.That(footer.Bounds, Is.EqualTo(new Rectangle(0, 550, 300, 50))); }
public void TestAlignContentStretchRowWithFlex() { var platform = new UnitPlatform(); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, AlignContent = FlexAlignContent.Stretch, Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, }; var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view0); var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; FlexLayout.SetGrow(view1, 1); FlexLayout.SetShrink(view1, 1); FlexLayout.SetBasis(view1, 0); layout.Children.Add(view1); var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view2); var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; FlexLayout.SetGrow(view3, 1); FlexLayout.SetShrink(view3, 1); FlexLayout.SetBasis(view3, 0); layout.Children.Add(view3); var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50 }; layout.Children.Add(view4); layout.Layout(new Rectangle(0, 0, 150, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 150, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 50, 100))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(50, 0, 0, 100))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(50, 0, 50, 100))); Assert.That(view3.Bounds, Is.EqualTo(new Rectangle(100, 0, 0, 100))); Assert.That(view4.Bounds, Is.EqualTo(new Rectangle(100, 0, 50, 100))); }
public void TemplateInflates() { var platform = new UnitPlatform(); var contentView = new ContentView(); contentView.ControlTemplate = new ControlTemplate(typeof(SimpleTemplate)); contentView.Platform = platform; Assert.That(contentView.LogicalChildren[0], Is.TypeOf <SimpleTemplate> ()); }
public void TestAlignContentFlexStart() { var platform = new UnitPlatform((visual, width, height) => new SizeRequest(new Size(50, 10))); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, WidthRequest = 130, HeightRequest = 100, AlignContent = FlexAlignContent.Start, AlignItems = FlexAlignItems.Start, Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, }; var view0 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; layout.Children.Add(view0); var view1 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; layout.Children.Add(view1); var view2 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; layout.Children.Add(view2); var view3 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; layout.Children.Add(view3); var view4 = new View { IsPlatformEnabled = true, WidthRequest = 50, HeightRequest = 10, }; layout.Children.Add(view4); layout.Layout(new Rectangle(0, 0, 130, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 130, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 50, 10))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(50, 0, 50, 10))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(0, 10, 50, 10))); Assert.That(view3.Bounds, Is.EqualTo(new Rectangle(50, 10, 50, 10))); Assert.That(view4.Bounds, Is.EqualTo(new Rectangle(0, 20, 50, 10))); }
// fixed at https://github.com/xamarin/flex/commit/0ccb9f1625abdc5400def29651373937bf6610cd public void TestSwapChildrenOrder() { var layoutSize = new Size(300, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Direction = FlexDirection.Row, Platform = platform, IsPlatformEnabled = true, }; var label0 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "Label0" }; FlexLayout.SetGrow(label0, 1); layout.Children.Add(label0); var label1 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "Label1" }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "Label2" }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(new Rectangle(0, 0, 100, 50), label0.Bounds); Assert.AreEqual(new Rectangle(100, 0, 100, 50), label1.Bounds); Assert.AreEqual(new Rectangle(200, 0, 100, 50), label2.Bounds); var lastItem = layout.Children[2]; Assert.That(lastItem, Is.SameAs(label2)); layout.Children.Remove(lastItem); Assert.AreEqual(new Rectangle(0, 0, 150, 50), label0.Bounds); Assert.AreEqual(new Rectangle(150, 0, 150, 50), label1.Bounds); layout.Children.Insert(0, lastItem); Assert.AreEqual(new Rectangle(0, 0, 100, 50), label2.Bounds); Assert.AreEqual(new Rectangle(100, 0, 100, 50), label0.Bounds); Assert.AreEqual(new Rectangle(200, 0, 100, 50), label1.Bounds); }
public void TestAlignContentFlexEnd() { var platform = new UnitPlatform((visual, width, height) => new SizeRequest(new Size(50, 10))); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, WidthRequest = 100, HeightRequest = 100, Direction = FlexDirection.Column, AlignContent = FlexAlignContent.End, AlignItems = FlexAlignItems.Start, Wrap = FlexWrap.Wrap, }; Func <View> createView = () => new View { IsPlatformEnabled = true, Platform = platform, WidthRequest = 50, HeightRequest = 10, }; var view0 = createView(); layout.Children.Add(view0); var view1 = createView(); layout.Children.Add(view1); var view2 = createView(); layout.Children.Add(view2); var view3 = createView(); layout.Children.Add(view3); var view4 = createView(); layout.Children.Add(view4); var measure = layout.Measure(100, 100); layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(50, 0, 50, 10))); Assert.That(view1.Bounds, Is.EqualTo(new Rectangle(50, 10, 50, 10))); Assert.That(view2.Bounds, Is.EqualTo(new Rectangle(50, 20, 50, 10))); Assert.That(view3.Bounds, Is.EqualTo(new Rectangle(50, 30, 50, 10))); Assert.That(view4.Bounds, Is.EqualTo(new Rectangle(50, 40, 50, 10))); }
public void NonTemplatedContentInheritsBindingContext() { var platform = new UnitPlatform(); var contentView = new ContentView(); var child = new View(); contentView.Content = child; contentView.Platform = platform; contentView.BindingContext = "Foo"; Assert.AreEqual("Foo", child.BindingContext); }
public void ContentParentIsNotInsideTempalte() { var platform = new UnitPlatform(); var contentView = new ContentView(); var child = new View(); contentView.ControlTemplate = new ControlTemplate(typeof(SimpleTemplate)); contentView.Content = child; contentView.Platform = platform; Assert.AreEqual(contentView, child.Parent); }
public void NullTemplateDirectlyHosts() { // order of setting properties carefully picked to emulate running on real backend var platform = new UnitPlatform(); var contentView = new ContentView(); var child = new View(); contentView.Content = child; contentView.Platform = platform; Assert.AreEqual(child, contentView.LogicalChildren[0]); }
public void PacksContent() { var platform = new UnitPlatform(); var contentView = new ContentView(); var child = new View(); contentView.ControlTemplate = new ControlTemplate(typeof(SimpleTemplate)); contentView.Content = child; contentView.Platform = platform; Assume.That(contentView.LogicalChildren[0], Is.TypeOf <SimpleTemplate> ()); Assert.That(contentView.Descendants(), Contains.Item(child)); }
public void TestMarginsWithWrap() { var platform = new UnitPlatform(); var label0 = new Label { Platform = platform, IsPlatformEnabled = true, Margin = 6, }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true, Margin = 6, }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true, }; FlexLayout.SetGrow(label0, 0); FlexLayout.SetBasis(label0, new FlexBasis(.5f, true)); FlexLayout.SetGrow(label1, 0); FlexLayout.SetBasis(label1, new FlexBasis(.5f, true)); FlexLayout.SetGrow(label2, 0); FlexLayout.SetBasis(label2, new FlexBasis(1f, true)); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Row, Wrap = FlexWrap.Wrap, AlignItems = FlexAlignItems.Start, AlignContent = FlexAlignContent.Start, Children = { label0, label1, label2, } }; var measure = layout.Measure(300, double.PositiveInfinity); Assert.That(measure.Request, Is.EqualTo(new Size(300, 52))); layout.Layout(new Rectangle(0, 0, 300, 300)); Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(6, 6, 138, 20))); Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(156, 6, 138, 20))); Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 32, 300, 20))); }
public void TestSetBounds() { var layoutSize = new Size(320, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Direction = FlexDirection.Row, AlignItems = FlexAlignItems.Start, Platform = platform, IsPlatformEnabled = true }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); var label3 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label3, 1); layout.Children.Add(label3); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(label2.Bounds.Left, Math.Max(label1.Bounds.Left, label1.Bounds.Right), 1); Assert.AreEqual(label3.Bounds.Left, Math.Max(label2.Bounds.Left, label2.Bounds.Right), 1); double totalWidth = 0; foreach (var view in layout.Children) { totalWidth += view.Bounds.Width; } Assert.AreEqual(layoutSize.Width, totalWidth, 2); }
public void ContentDoesGetBindingContext() { var platform = new UnitPlatform(); var contentView = new ContentView(); var child = new View(); contentView.ControlTemplate = new ControlTemplate(typeof(SimpleTemplate)); contentView.Content = child; contentView.Platform = platform; var bc = "Test"; contentView.BindingContext = bc; Assert.AreEqual(bc, child.BindingContext); }
public void TestRelayoutOnChildrenRemoved() { var layoutSize = new Size(300, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Row }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); var label3 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label3, 1); layout.Children.Add(label3); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); foreach (var view in layout.Children) { Assert.That(view.Bounds.Width, Is.EqualTo(100)); } layout.Children.Remove(label3); Assert.That(label1.Bounds.Width, Is.EqualTo(150)); Assert.That(label2.Bounds.Width, Is.EqualTo(150)); Assert.That(label3.Bounds.Width, Is.EqualTo(100)); }
public void TestSizedChildBehavior () { var plat = new UnitPlatform (); var child = new Label {Platform = plat, IsPlatformEnabled = true, WidthRequest = 100, HorizontalOptions = LayoutOptions.Center}; var root = new ContentPage {Platform = plat, IsPlatformEnabled = true, Content = child}; root.Layout (new Rectangle (0, 0, 200, 500)); Assert.AreEqual (50, child.X); Assert.AreEqual (100, child.Width); Assert.AreEqual (500, child.Height); child = new Label () { Platform = plat, IsPlatformEnabled = true, HeightRequest = 100, VerticalOptions = LayoutOptions.Center }; root = new ContentPage { Platform = plat, IsPlatformEnabled = true, Content = child }; root.Layout (new Rectangle (0, 0, 200, 500)); Assert.AreEqual (0, child.X); Assert.AreEqual (200, child.Y); Assert.AreEqual (200, child.Width); Assert.AreEqual (100, child.Height); child = new Label (); child.IsPlatformEnabled = true; child.HeightRequest = 100; root = new ContentPage { Content = child, Platform = plat, IsPlatformEnabled = true }; root.Layout (new Rectangle (0, 0, 200, 500)); Assert.AreEqual (0, child.X); Assert.AreEqual (0, child.Y); Assert.AreEqual (200, child.Width); Assert.AreEqual (500, child.Height); }
public void DoesNotInheritBindingContextToTemplate() { var platform = new UnitPlatform(); var contentView = new ContentView(); var child = new View(); contentView.ControlTemplate = new ControlTemplate(typeof(SimpleTemplate)); contentView.Content = child; contentView.Platform = platform; var bc = "Test"; contentView.BindingContext = bc; Assert.AreNotEqual(bc, contentView.LogicalChildren[0].BindingContext); Assert.IsNull(contentView.LogicalChildren[0].BindingContext); }
public void TestAlignItemsStretch() { var platform = new UnitPlatform(); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Column, }; var view0 = new View { IsPlatformEnabled = true, HeightRequest = 10, }; layout.Children.Add(view0); layout.Layout(new Rectangle(0, 0, 100, 100)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 100))); Assert.That(view0.Bounds, Is.EqualTo(new Rectangle(0, 0, 100, 10))); }
public void TestAlignContentStretchRowWithSingleRow() { var platform = new UnitPlatform(); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Row, AlignContent = FlexAlignContent.Stretch, Wrap = FlexWrap.Wrap, WidthRequest = 150, HeightRequest = 100 }; var view0 = new View { IsPlatformEnabled = true }; view0.WidthRequest = 50; layout.Children.Add(view0); var view1 = new View { IsPlatformEnabled = true }; view1.WidthRequest = 50; layout.Children.Add(view1); layout.Layout(new Rectangle(0, 0, 150, 100)); Assert.AreEqual(0f, layout.X); Assert.AreEqual(0f, layout.Y); Assert.AreEqual(150f, layout.Width); Assert.AreEqual(100f, layout.Height); Assert.AreEqual(0f, view0.X); Assert.AreEqual(0f, view0.Y); Assert.AreEqual(50f, view0.Width); Assert.AreEqual(100f, view0.Height); Assert.AreEqual(50f, view1.X); Assert.AreEqual(0f, view1.Y); Assert.AreEqual(50f, view1.Width); Assert.AreEqual(100f, view1.Height); }
public void TestFlexLayoutIsIncludeChangeWorksOnSecondPass() { var layoutSize = new Size(300, 50); var platform = new UnitPlatform(); var layout = new FlexLayout { Direction = FlexDirection.Row, Platform = platform, IsPlatformEnabled = true, }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label1, 1); layout.Children.Add(label1); var label2 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label2, 1); layout.Children.Add(label2); var label3 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetGrow(label3, 1); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(150, label1.Bounds.Width); Assert.AreEqual(150, label2.Bounds.Width); Assert.AreEqual(-1, label3.Bounds.Width); layout.Children.Add(label3); layout.Layout(new Rectangle(0, 0, layoutSize.Width, layoutSize.Height)); Assert.AreEqual(100, label1.Bounds.Width); Assert.AreEqual(100, label2.Bounds.Width); Assert.AreEqual(100, label3.Bounds.Width); }
public void TestOrderingElements() { var platform = new UnitPlatform(); var label0 = new Label { Platform = platform, IsPlatformEnabled = true }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true }; var label3 = new Label { Platform = platform, IsPlatformEnabled = true }; FlexLayout.SetOrder(label3, 0); FlexLayout.SetOrder(label2, 1); FlexLayout.SetOrder(label1, 2); FlexLayout.SetOrder(label0, 3); var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Column, Children = { label0, label1, label2, label3 } }; layout.Layout(new Rectangle(0, 0, 912, 912)); Assert.That(layout.Bounds, Is.EqualTo(new Rectangle(0, 0, 912, 912))); Assert.That(label3.Bounds, Is.EqualTo(new Rectangle(0, 0, 912, 20))); Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 20, 912, 20))); Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(0, 40, 912, 20))); Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(0, 60, 912, 20))); }
public void TestIsVisible() //https://github.com/xamarin/Xamarin.Forms/issues/2593 { var platform = new UnitPlatform(); var label0 = new Label { Platform = platform, IsPlatformEnabled = true, }; var label1 = new Label { Platform = platform, IsPlatformEnabled = true, }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true, }; var layout = new FlexLayout { Platform = platform, IsPlatformEnabled = true, Direction = FlexDirection.Column, Children = { label0, label1, label2, } }; layout.Layout(new Rectangle(0, 0, 300, 300)); Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 20))); Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(0, 20, 300, 20))); Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 40, 300, 20))); label1.IsVisible = false; Assert.That(label0.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 20))); Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 20, 300, 20))); label0.IsVisible = false; label1.IsVisible = true; Assert.That(label1.Bounds, Is.EqualTo(new Rectangle(0, 0, 300, 20))); Assert.That(label2.Bounds, Is.EqualTo(new Rectangle(0, 20, 300, 20))); }
public void GetSizeRequestIncludesMargins () { var platform = new UnitPlatform ((b, d, e) => new SizeRequest(new Size(100,50))); var parent = new ContentView { Platform = platform, IsPlatformEnabled = true, }; var child = new Button { Text = "Test", Platform = platform, IsPlatformEnabled = true, }; child.Margin = new Thickness (10, 20, 30, 40); parent.Content = child; var result = parent.Measure (double.PositiveInfinity, double.PositiveInfinity, MeasureFlags.IncludeMargins); Assert.AreEqual (new Size (140, 110), result.Request); }
public void MarginsAffectPositionInContentView () { var platform = new UnitPlatform ((b, d, e) => new SizeRequest(new Size(100,50))); var parent = new ContentView { Platform = platform, IsPlatformEnabled = true, }; var child = new Button { Text = "Test", Platform = platform, IsPlatformEnabled = true, }; child.Margin = new Thickness (10, 20, 30, 40); parent.Content = child; parent.Layout (new Rectangle (0, 0, 140, 110)); Assert.AreEqual (new Rectangle (10, 20, 100, 50), child.Bounds); }
public void ChangingMarginCausesRelayout () { var platform = new UnitPlatform ((b, d, e) => new SizeRequest(new Size(100,50))); var parent = new ContentView { Platform = platform, IsPlatformEnabled = true, }; var child = new Button { Text = "Test", VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Start, Platform = platform, IsPlatformEnabled = true, }; child.Margin = new Thickness (10, 20, 30, 40); parent.Content = child; parent.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (new Rectangle (10, 20, 100, 50), child.Bounds); }
public void TestEnd () { var platform = new UnitPlatform (); var layout = new Grid (); layout.Platform = platform; var label1 = new Label { Platform = platform, IsPlatformEnabled = true, HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.EndAndExpand }; layout.Children.AddVertical (label1); layout.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition () {Width = new GridLength (1, GridUnitType.Star)}, }; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition () {Height = new GridLength (1,GridUnitType.Star)}, }; layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (new Rectangle (900, 980, 100, 20), label1.Bounds); }
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); }
public void IntegrationTest () { var platform = new UnitPlatform ((b, d, e) => new SizeRequest(new Size(100,50))); var parent = new StackLayout { Platform = platform, Spacing = 0, IsPlatformEnabled = true, }; var child1 = new Button { Text = "Test", VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Start, Platform = platform, IsPlatformEnabled = true, }; var child2 = new Button { Text = "Test", Platform = platform, IsPlatformEnabled = true, }; child2.Margin = new Thickness (5, 10, 15, 20); parent.Children.Add (child1); parent.Children.Add (child2); parent.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (new Rectangle (0, 0, 100, 50), child1.Bounds); Assert.AreEqual (new Rectangle (5, 60, 980, 50), child2.Bounds); child1.Margin = new Thickness (10, 20, 30, 40); Assert.AreEqual (new Rectangle (10, 20, 100, 50), child1.Bounds); Assert.AreEqual (new Rectangle (5, 120, 980, 50), child2.Bounds); }
public void ChildrenLayoutRespectAlignment () { var platform = new UnitPlatform (); var grid = new Grid { ColumnDefinitions = { new ColumnDefinition { Width = new GridLength (300) } }, RowDefinitions = { new RowDefinition { Height = new GridLength (100) } }, Platform = platform, }; var label = new Label { Platform = platform, IsPlatformEnabled = true, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.End, }; grid.Children.Add (label); grid.Layout (new Rectangle (0, 0, 500, 500)); Assert.AreEqual (new Rectangle (200, 40, 100, 20), label.Bounds); }
public void TestHorizontalExpandMiddle () { 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 = GridLength.Auto }, new ColumnDefinition { Width = new GridLength (1, GridUnitType.Star) }, new ColumnDefinition { Width = GridLength.Auto }, }; layout.Children.Add (label1, 0, 0); layout.Children.Add (label2, 1, 0); layout.Children.Add (label3, 2, 0); layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (1000, layout.Width); Assert.AreEqual (1000, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 100, 1000), label1.Bounds); Assert.AreEqual (new Rectangle (106, 0, 1000 - 212, 1000), label2.Bounds); Assert.AreEqual (new Rectangle (900, 0, 100, 1000), label3.Bounds); }
public void TestTableExpandedSpan () { 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) }, }; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto}, new RowDefinition { Height = GridLength.Auto} }; layout.Children.Add (label1, 0, 2, 0, 1); layout.Children.Add (label2, 0, 1, 1, 2); layout.Children.Add (label3, 1, 2, 1, 2); layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (1000, layout.Width); Assert.AreEqual (1000, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 1000, 20), label1.Bounds); Assert.AreEqual (new Rectangle (0, 26, 497, 20), label2.Bounds); Assert.AreEqual (new Rectangle (503, 26, 497, 20), label3.Bounds); }
public void TestAddedBP () { var platform = new UnitPlatform (); var labela0 = new Label {Platform = platform, IsPlatformEnabled = true}; var labela1 = new Label { Platform = platform, IsPlatformEnabled = true }; Grid.SetColumn (labela1, 1); var labelb1 = new Label {Platform = platform, IsPlatformEnabled = true}; Grid.SetRow (labelb1, 1); Grid.SetColumn (labelb1, 1); var labelc = new Label {Platform = platform, IsPlatformEnabled = true}; Grid.SetRow (labelc, 2); Grid.SetColumnSpan (labelc, 2); var layout = new Grid { Platform = platform, Children = { labela0, labela1, labelb1, labelc } }; layout.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = GridLength.Auto }, }; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto}, new RowDefinition { Height = GridLength.Auto}, new RowDefinition { Height = GridLength.Auto}, }; layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (1000, layout.Width); Assert.AreEqual (1000, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 100, 20), labela0.Bounds); Assert.AreEqual (new Rectangle (106, 0, 100, 20), labela1.Bounds); Assert.AreEqual (new Rectangle (106, 26, 100, 20), labelb1.Bounds); Assert.AreEqual (new Rectangle (0, 52, 206, 20), labelc.Bounds); }
//Issue 1384 public void ImageInAutoCellIsProperlyConstrained () { var platform = new UnitPlatform (); var content = new Image { Aspect= Aspect.AspectFit, Platform = platform, IsPlatformEnabled = true }; var grid = new Grid { Platform = platform, IsPlatformEnabled = true, BackgroundColor = Color.Red, VerticalOptions=LayoutOptions.Start, Children = { content }, RowDefinitions = { new RowDefinition { Height = GridLength.Auto} }, ColumnDefinitions = { new ColumnDefinition { Width = GridLength.Auto } } }; var view = new ContentView { Platform = platform, IsPlatformEnabled = true, Content = grid, }; view.Layout (new Rectangle (0, 0, 100, 100)); Assert.AreEqual (100, grid.Width); Assert.AreEqual (20, grid.Height); view.Layout (new Rectangle (0, 0, 50, 50)); Assert.AreEqual (50, grid.Width); Assert.AreEqual (10, grid.Height); }
public void TestVerticalExpandStart () { 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}; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = new GridLength (1, GridUnitType.Star) }, new RowDefinition { Height = GridLength.Auto}, }; layout.Children.Add (label1, 0, 0); layout.Children.Add (label2, 0, 1); layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (1000, layout.Width); Assert.AreEqual (1000, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 1000, 1000 - 20 - layout.RowSpacing), label1.Bounds); Assert.AreEqual (new Rectangle (0, 1000 - 20, 1000, 20), label2.Bounds); }
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); // }
public void Remove () { var platform = new UnitPlatform(); var labela0 = new Label { Platform = platform, IsPlatformEnabled = true }; var labela1 = new Label { Platform = platform, IsPlatformEnabled = true }; Grid.SetColumn(labela1, 1); var labelb1 = new Label { Platform = platform, IsPlatformEnabled = true }; Grid.SetRow(labelb1, 1); Grid.SetColumn(labelb1, 1); var labelc = new Label { Platform = platform, IsPlatformEnabled = true }; Grid.SetRow(labelc, 2); Grid.SetColumnSpan(labelc, 2); var layout = new Grid { Platform = platform, Children = { labela0, labela1, labelb1, labelc } }; layout.Children.Remove (labela0); Assert.False (layout.LogicalChildren.Contains (labela0)); }
public void ContentParentIsNotInsideTempalte () { var platform = new UnitPlatform (); var contentView = new ContentView (); var child = new View (); contentView.ControlTemplate = new ControlTemplate (typeof (SimpleTemplate)); contentView.Content = child; contentView.Platform = platform; Assert.AreEqual (contentView, child.Parent); }
//Issue 1497 public void StarRowsShouldOccupyTheSpace () { var platform = new UnitPlatform (); var label = new Label { Platform = platform, IsPlatformEnabled = true, }; var Button = new Button { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.EndAndExpand, Platform = platform, IsPlatformEnabled = true, }; var grid = new Grid { RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto }, new RowDefinition { Height = new GridLength (1, GridUnitType.Star) }, }, ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)}, }, Platform = platform, IsPlatformEnabled = true, }; grid.Children.Add (label); grid.Children.Add (Button, 0, 1); grid.Layout (new Rectangle (0, 0, 300, 300)); Assert.AreEqual (new Rectangle (0, 280, 300, 20), Button.Bounds); }
public void TestInvalidSet () { var platform = new UnitPlatform (); var layout = new Grid (); layout.Platform = platform; var label1 = new Label {Platform = platform, IsPlatformEnabled = true}; bool thrown = false; try { layout.Children.Add (label1, 2, 1, 0, 1); } catch (ArgumentOutOfRangeException) { thrown = true; } Assert.True (thrown); }
public void TestAutoLayoutWithSpans () { var platform = new UnitPlatform (); var layout = new Grid (); layout.Platform = platform; var label1 = new Label { Platform = platform, IsPlatformEnabled = true, WidthRequest = 150, Text = "label1" }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true, HeightRequest = 50, Text = "label2" }; var label3 = new Label { Platform = platform, IsPlatformEnabled = true, Text = "label3" }; layout.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition {Width = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, }; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition {Height = GridLength.Auto}, new RowDefinition {Height = GridLength.Auto}, new RowDefinition {Height = GridLength.Auto}, }; layout.Children.Add (label1, 0, 2, 0, 1); layout.Children.Add (label2, 2, 3, 0, 2); layout.Children.Add (label3, 1, 2); layout.Layout (new Rectangle (0, 0, 1002, 462)); Assert.AreEqual (1002, layout.Width); Assert.AreEqual (462, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 150, 20), label1.Bounds); Assert.AreEqual (new Rectangle (156, 0, 100, 50), label2.Bounds); Assert.AreEqual (new Rectangle (50, 56, 100, 20), label3.Bounds); }
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); }
public void AutoLayoutWithComplexSpans () { 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}; var label4 = new Label {Platform = platform, IsPlatformEnabled = true, WidthRequest = 206}; var label5 = new Label {Platform = platform, IsPlatformEnabled = true, WidthRequest = 312}; var label6 = new Label {Platform = platform, IsPlatformEnabled = true, WidthRequest = 312}; layout.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition {Width = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, }; layout.Children.Add (label1, 0, 0); layout.Children.Add (label2, 1, 0); layout.Children.Add (label3, 4, 0); layout.Children.Add (label4, 2, 4, 0, 1); layout.Children.Add (label5, 0, 3, 0, 1); layout.Children.Add (label6, 2, 6, 0, 1); layout.Layout (new Rectangle (0, 0, 1000, 500)); Assert.AreEqual (100, layout.ColumnDefinitions [0].ActualWidth); Assert.AreEqual (100, layout.ColumnDefinitions [1].ActualWidth); Assert.AreEqual (100, layout.ColumnDefinitions [2].ActualWidth); Assert.AreEqual (100, layout.ColumnDefinitions [3].ActualWidth); Assert.AreEqual (100, layout.ColumnDefinitions [4].ActualWidth); }
public void NonTemplatedContentInheritsBindingContext () { var platform = new UnitPlatform (); var contentView = new ContentView (); var child = new View (); contentView.Content = child; contentView.Platform = platform; contentView.BindingContext = "Foo"; Assert.AreEqual ("Foo", child.BindingContext); }
public void IgnoresInvisibleChildren () { var platform = new UnitPlatform (); var layout = new Grid {Platform = platform}; var label1 = new Label { Platform = platform, IsVisible = false, IsPlatformEnabled = true, VerticalOptions = LayoutOptions.FillAndExpand }; var label2 = new Label { Platform = platform, IsPlatformEnabled = true}; layout.Children.AddVertical (label1); layout.Children.AddVertical (label2); layout.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Auto }, }; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = GridLength.Auto}, new RowDefinition { Height = GridLength.Auto}, }; layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (1000, layout.Width); Assert.AreEqual (1000, layout.Height); Assert.AreEqual (new Rectangle (0, 0, -1, -1), label1.Bounds); Assert.AreEqual (new Rectangle (0, 6, 100, 20), label2.Bounds); }
public void AutoLayoutExpandColumns () { 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, WidthRequest = 300}; layout.ColumnDefinitions = new ColumnDefinitionCollection { new ColumnDefinition { Width = GridLength.Auto }, new ColumnDefinition { Width = GridLength.Auto }, }; layout.Children.Add (label1, 0, 0); layout.Children.Add (label2, 1, 0); layout.Children.Add (label3, 0, 2, 0, 1); layout.Layout (new Rectangle (0, 0, 1000, 500)); Assert.AreEqual (100, layout.ColumnDefinitions [0].ActualWidth); Assert.AreEqual (194, layout.ColumnDefinitions [1].ActualWidth); }
public void TestAbsoluteLayoutWithSpans () { 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 (150)}, new ColumnDefinition {Width = new GridLength (150)}, new ColumnDefinition {Width = new GridLength (150)}, }; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition {Height = new GridLength (30)}, new RowDefinition {Height = new GridLength (30)}, new RowDefinition {Height = new GridLength (30)}, }; layout.Children.Add (label1, 0, 2, 0, 1); layout.Children.Add (label2, 2, 3, 0, 2); layout.Children.Add (label3, 1, 2); layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (1000, layout.Width); Assert.AreEqual (1000, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 306, 30), label1.Bounds); Assert.AreEqual (new Rectangle (312, 0, 150, 66), label2.Bounds); Assert.AreEqual (new Rectangle (156, 72, 150, 30), label3.Bounds); }
public void TestStarLayoutWithSpans () { 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, 2, 0, 1); layout.Children.Add (label2, 2, 3, 0, 2); layout.Children.Add (label3, 1, 2); layout.Layout (new Rectangle (0, 0, 1002, 462)); Assert.AreEqual (1002, layout.Width); Assert.AreEqual (462, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 666, 150), label1.Bounds); Assert.AreEqual (new Rectangle (672, 0, 330, 306), label2.Bounds); Assert.AreEqual (new Rectangle (336, 312, 330, 150), label3.Bounds); }
//Issue 1384 public void ImageInStarCellIsProperlyConstrained () { var platform = new UnitPlatform (); var content = new Image { Aspect= Aspect.AspectFit, Platform = platform, MinimumHeightRequest = 10, MinimumWidthRequest = 50, IsPlatformEnabled = true }; var grid = new Grid { Platform = platform, IsPlatformEnabled = true, BackgroundColor = Color.Red, VerticalOptions=LayoutOptions.Start, Children = { content } }; var view = new ContentView { Platform = platform, IsPlatformEnabled = true, Content = grid, }; view.Layout (new Rectangle (0, 0, 100, 100)); Assert.AreEqual (100, grid.Width); Assert.AreEqual (20, grid.Height); view.Layout (new Rectangle (0, 0, 50, 50)); Assert.AreEqual (50, grid.Width); Assert.AreEqual (10, grid.Height); }
public void TestAutoLayout () { 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 = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, new ColumnDefinition {Width = GridLength.Auto}, }; layout.RowDefinitions = new RowDefinitionCollection { new RowDefinition {Height = GridLength.Auto}, new RowDefinition {Height = GridLength.Auto}, new RowDefinition {Height = GridLength.Auto}, }; layout.Children.Add (label1, 0, 0); layout.Children.Add (label2, 1, 1); layout.Children.Add (label3, 2, 2); layout.Layout (new Rectangle (0, 0, 1000, 1000)); Assert.AreEqual (1000, layout.Width); Assert.AreEqual (1000, layout.Height); Assert.AreEqual (new Rectangle (0, 0, 100, 20), label1.Bounds); Assert.AreEqual (new Rectangle (106, 26, 100, 20), label2.Bounds); Assert.AreEqual (new Rectangle (212, 52, 100, 20), label3.Bounds); }
public void ContentDoesGetBindingContext () { var platform = new UnitPlatform (); var contentView = new ContentView (); var child = new View (); contentView.ControlTemplate = new ControlTemplate (typeof (SimpleTemplate)); contentView.Content = child; contentView.Platform = platform; var bc = "Test"; contentView.BindingContext = bc; Assert.AreEqual (bc, child.BindingContext); }