public void StarRows5 () { GridLength oneStar = new GridLength (1, GridUnitType.Star); MyGrid grid = new MyGrid { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center }; grid.AddRows (oneStar, oneStar, oneStar); grid.AddColumns (oneStar, oneStar, oneStar); grid.AddChild (new MyContentControl (240, 240), 0, 0, 3, 3); grid.AddChild (new MyContentControl (150, 150), 0, 0, 1, 1); TestPanel.Children.Add (grid); grid.Measure (new Size (240, 240)); grid.Arrange (new Rect (0, 0, 120, 120)); grid.CheckRowHeights ("#1", 80, 80, 80); grid.CheckMeasureArgs ("#2", new Size (240, 240), new Size (80, 80)); grid.CheckMeasureResult ("#3", new Size (240, 240), new Size (80, 80)); grid.CheckDesired ("#4", new Size (240, 240), new Size (80, 80)); grid.CheckMeasureOrder ("#5", 0, 1); }
public void ExpandInArrange_OutsideTree_GridParent_UnfixedSize () { // We always expand star rows if we're not in the live tree // with a parent var parent = new Grid (); // Measure with infinity and check results. MyGrid grid = new MyGrid (); grid.AddRows (Star); grid.AddColumns (Star); grid.AddChild (ContentControlWithChild (), 0, 0, 1, 1); parent.Children.Add (grid); parent.Measure (Infinity); grid.CheckMeasureArgs ("#1", Infinity); grid.CheckMeasureResult ("#2", new Size (50, 50)); Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#3"); // When we pass in the desired size as the arrange arg, // the rows/cols use that as their height/width parent.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height)); grid.CheckArrangeArgs ("#4", grid.DesiredSize); grid.CheckArrangeResult ("#5", grid.DesiredSize); grid.CheckRowHeights ("#6", grid.DesiredSize.Height); grid.CheckColWidths ("#7", grid.DesiredSize.Width); // If we pass in twice the desired size, the rows/cols consume that too grid.Reset (); parent.Arrange (new Rect (0, 0, 100, 100)); grid.CheckMeasureArgs ("#8"); // No remeasures grid.CheckArrangeArgs ("#9", new Size (100, 100)); grid.CheckArrangeResult ("#10", new Size (100, 100)); grid.CheckRowHeights ("#11", 100); grid.CheckColWidths ("#12", 100); // If we measure with a finite size, the rows/cols still expand // to consume the available space grid.Reset (); parent.Measure (new Size (1000, 1000)); grid.CheckMeasureArgs ("#13", new Size (1000, 1000)); grid.CheckMeasureResult ("#14", new Size (50, 50)); Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#15"); // When we pass in the desired size as the arrange arg, // the rows/cols use that as their height/width parent.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height)); grid.CheckArrangeArgs ("#16", grid.DesiredSize); grid.CheckArrangeResult ("#17", grid.DesiredSize); grid.CheckRowHeights ("#18", grid.DesiredSize.Height); grid.CheckColWidths ("#19", grid.DesiredSize.Width); // If we pass in twice the desired size, the rows/cols consume that too grid.Reset (); parent.Arrange (new Rect (0, 0, 100, 100)); grid.CheckMeasureArgs ("#20"); // No remeasures grid.CheckArrangeArgs ("#21", new Size (100, 100)); grid.CheckArrangeResult ("#22", new Size (100, 100)); grid.CheckRowHeights ("#23", 100); grid.CheckColWidths ("#24", 100); }
public void StarRows3 () { GridLength oneStar = new GridLength (1, GridUnitType.Star); MyGrid grid = new MyGrid (); grid.AddRows (oneStar, oneStar, oneStar); grid.AddColumns (oneStar, oneStar, oneStar); Canvas canvas = new Canvas { Width = 120, Height = 120 }; canvas.Children.Add (grid); grid.AddChild (new MyContentControl (100, 100), 1, 1, 1, 1); CreateAsyncTest (canvas, () => { }, () => { grid.CheckRowHeights ("#3", 0, 100, 0); grid.CheckMeasureArgs ("#1", Infinity); grid.CheckMeasureResult ("#2", new Size (100, 100)); grid.CheckRowHeights ("#3", 0, 100, 0); grid.CheckArrangeArgs ("#4", new Size (100, 100)); grid.CheckArrangeResult ("#5", new Size (100, 100)); } ); }
public void StarRows3b () { var canvas = new Canvas { Width = 120, Height = 120 }; PanelPoker poker = new PanelPoker (); MyGrid grid = new MyGrid (); grid.AddRows (Star, Star, Star); grid.AddColumns (Star, Star, Star); canvas.Children.Add (poker); poker.Grid = grid; grid.AddChild (new MyContentControl (100, 100), 1, 1, 1, 1); CreateAsyncTest (canvas, () => { }, () => { Assert.AreEqual (Infinity, poker.MeasureArgs [0], "#1"); Assert.AreEqual (new Size (100, 100), poker.MeasureResults [0], "#2"); Assert.AreEqual (new Size (100, 100), poker.ArrangeArgs [0], "#3"); Assert.AreEqual (new Size (100, 100), poker.ArrangeResults [0], "#4"); grid.CheckRowHeights ("#5", 0, 100, 0); grid.CheckColWidths ("#6", 0, 100, 0); grid.CheckMeasureArgs ("#7", Infinity); grid.CheckMeasureResult ("#8", new Size (100, 100)); grid.CheckArrangeArgs ("#9", new Size (100, 100)); grid.CheckArrangeResult ("#10", new Size (100, 100)); } ); }
public void AutoStarInfiniteChildren () { Grid holder = new Grid { Width = 500, Height = 500 }; MyGrid g = new MyGrid { Name = "Ted!" }; g.AddRows (new GridLength (1, GridUnitType.Star), GridLength.Auto); g.AddColumns (new GridLength (1, GridUnitType.Star), GridLength.Auto); g.AddChild (CreateInfiniteChild (), 0, 0, 1, 1); g.AddChild (CreateInfiniteChild (), 0, 1, 1, 1); g.AddChild (CreateInfiniteChild (), 1, 0, 1, 1); g.AddChild (CreateInfiniteChild (), 1, 1, 1, 1); // FIXME: I think this fails because the first time the ScrollViewer measures it calculates // the visibility of the Horizontal/Vertical scroll bar incorrectly. It's desired size on the // first measure is (327, 327) whereas it should be (327, 310). A few measure cycles later and // it will be correct, but chews up much more CPU than it should. holder.Children.Add (g); CreateAsyncTest (holder, () => { g.CheckMeasureOrder ("#1", 3, 1, 2, 1, 0); g.CheckMeasureArgs ("#2", Infinity, Infinity, new Size (173, inf), new Size (inf, 190), new Size (173, 190)); g.CheckMeasureResult ("#3", new Size (173, 190), new Size (327, 190), new Size (173, 310), new Size (327, 310), new Size (173, 310)); g.CheckRowHeights ("#4", 190, 310); g.CheckColWidths ("#5", 173, 327); Assert.AreEqual (new Size (500, 500), g.DesiredSize, "#5"); }); }
public void ExpandStarsInStackPanel2 () { Grid grid = new Grid (); grid.AddRows (Auto); grid.AddColumns (Auto); var parent = new StackPanel (); for (int i = 0; i < 4; i++) { MyGrid g = new MyGrid { Name = "Grid" + i }; g.AddRows (Star); g.AddColumns (Star); g.Children.Add (new MyContentControl { Content = new Rectangle { RadiusX = 4, RadiusY = 4, StrokeThickness = 2, Fill = new SolidColorBrush (Colors.Red), Stroke = new SolidColorBrush (Colors.Black) } }); g.Children.Add (new MyContentControl { Content = new Rectangle { Fill = new SolidColorBrush (Colors.Blue), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Height = 17, Width = 20 + i * 20 } }); parent.Children.Add (g); } grid.Children.Add (parent); CreateAsyncTest (grid, () => { for (int i = 0 ;i < parent.Children.Count; i++) { MyGrid g = (MyGrid)parent.Children[i]; Assert.AreEqual (new Size (20 + i * 20, 17), g.DesiredSize, "#1." + i); Assert.AreEqual (new Size (80, 17), g.RenderSize, "#2." + i); g.CheckMeasureArgs ("#3", Infinity, Infinity); g.CheckMeasureResult ("#4", new Size (0, 0), new Size (20 + i * 20, 17)); g.CheckRowHeights ("#5", 17); g.CheckColWidths ("#6", 80); g.CheckArrangeArgs ("#7", new Size (80, 17), new Size (80, 17)); g.CheckArrangeResult ("#8", new Size (80, 17), new Size (80, 17)); } }); }
public void ExpandInArrange () { // Measure with infinity and check results. MyGrid grid = new MyGrid (); grid.AddRows (Star); grid.AddColumns (Star); grid.AddChild (ContentControlWithChild (), 0, 0, 1, 1); grid.Measure (Infinity); grid.CheckMeasureArgs ("#1", Infinity); grid.CheckMeasureResult ("#2", new Size (50, 50)); Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#3"); // Check that everything is as expected when we pass in DesiredSize as the argument to Arrange grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height)); grid.CheckArrangeArgs ("#4", grid.DesiredSize); grid.CheckArrangeResult ("#5", grid.DesiredSize); grid.CheckRowHeights ("#6", grid.DesiredSize.Height); grid.CheckColWidths ("#7", grid.DesiredSize.Width); grid.Reset (); grid.Arrange (new Rect (0, 0, 100, 100)); grid.CheckMeasureArgs ("#8"); // No remeasures grid.CheckArrangeArgs ("#9", new Size (100, 100)); grid.CheckArrangeResult ("#10", new Size (100, 100)); grid.CheckRowHeights ("#11", 100); grid.CheckColWidths ("#12", 100); }
public void StarRows3d () { var poker = new MyContentControl { Width = 120, Height = 120 }; MyGrid grid = new MyGrid (); grid.AddRows (Star, Star, Star); grid.AddColumns (Star, Star, Star); poker.Content = grid; grid.AddChild (new MyContentControl (100, 100), 1, 1, 1, 1); CreateAsyncTest (poker, () => { }, () => { Assert.AreEqual (new Size (120, 120), poker.MeasureOverrideArg, "#1"); Assert.AreEqual (new Size (40, 40), poker.MeasureOverrideResult, "#2"); Assert.AreEqual (new Size (40, 40), grid.DesiredSize, "#2b"); Assert.AreEqual (new Size (120, 120), poker.DesiredSize, "#2c"); Assert.AreEqual (new Size (120, 120), poker.ArrangeOverrideArg, "#3"); Assert.AreEqual (new Size (120, 120), poker.ArrangeOverrideResult, "#4"); grid.CheckColWidths ("#5", 0, 40, 0); grid.CheckRowHeights ("#6", 0, 40, 0); grid.CheckMeasureArgs ("#7", new Size (40, 40)); grid.CheckMeasureResult ("#8", new Size (40, 40)); grid.CheckArrangeArgs ("#9", new Size (40, 40)); grid.CheckArrangeResult ("#10", new Size (40, 40)); } ); }
public void ExpandStars_FixedSize () { // If a width/height is set on the grid, it expands stars. var canvas = new Canvas { Width = 120, Height = 120 }; PanelPoker poker = new PanelPoker { Width = 120, Height = 120 }; MyGrid grid = new MyGrid { Name = "Griddy" }; grid.AddRows (Star, Star, Star); grid.AddColumns (Star, Star, Star); canvas.Children.Add (poker); poker.Grid = grid; grid.AddChild (new MyContentControl (100, 100), 1, 1, 1, 1); CreateAsyncTest (canvas, () => { Assert.AreEqual (new Size (120, 120), poker.MeasureArgs [0], "#1"); Assert.AreEqual (new Size (40, 40), poker.MeasureResults [0], "#2"); Assert.AreEqual (new Size (120, 120), poker.ArrangeArgs [0], "#3"); Assert.AreEqual (new Size (120, 120), poker.ArrangeResults [0], "#4"); grid.CheckRowHeights ("#5", 40, 40, 40); grid.CheckColWidths ("#6", 40, 40, 40); grid.CheckMeasureArgs ("#7", new Size (40, 40)); grid.CheckMeasureResult ("#8", new Size (40, 40)); grid.CheckArrangeArgs ("#9", new Size (40, 40)); grid.CheckArrangeResult ("#10", new Size (40, 40)); } ); }
public void ExpandStars_UnfixedSize () { // If a width/height is *not* set on the grid, it doesn't expand stars. var canvas = new Canvas { Width = 120, Height = 120 }; PanelPoker poker = new PanelPoker (); MyGrid grid = new MyGrid { Name = "TEDDY" }; grid.AddRows (Star, Star, Star); grid.AddColumns (Star, Star, Star); canvas.Children.Add (poker); poker.Grid = grid; grid.AddChild (new MyContentControl (100, 100), 1, 1, 1, 1); CreateAsyncTest (canvas, () => { Assert.AreEqual (Infinity, poker.MeasureArgs [0], "#1"); Assert.AreEqual (new Size (100, 100), poker.MeasureResults [0], "#2"); Assert.AreEqual (new Size (100, 100), poker.ArrangeArgs [0], "#3"); Assert.AreEqual (new Size (100, 100), poker.ArrangeResults [0], "#4"); grid.CheckRowHeights ("#5", 0, 100, 0); grid.CheckColWidths ("#6", 0, 100, 0); grid.CheckMeasureArgs ("#7", Infinity); grid.CheckMeasureResult ("#8", new Size (100, 100)); grid.CheckArrangeArgs ("#9", new Size (100, 100)); grid.CheckArrangeResult ("#10", new Size (100, 100)); // Do not expand if we already consume 100 px grid.Reset (); grid.Arrange (new Rect (0, 0, 100, 100)); grid.CheckArrangeArgs ("#11"); // If we give extra space, we expand the rows. grid.Arrange (new Rect (0, 0, 500, 500)); grid.CheckRowHeights ("#12", 167, 167, 166); grid.CheckColWidths ("#13", 167, 167, 166); grid.CheckArrangeArgs ("#14", new Size (167, 167)); grid.CheckArrangeResult ("#15", new Size (167, 167)); } ); }
public void ExpandInArrange_CanvasParent () { // Measure with infinity and check results. MyGrid grid = new MyGrid (); grid.AddRows (Star); grid.AddColumns (Star); grid.AddChild (ContentControlWithChild (), 0, 0, 1, 1); var parent = new Canvas (); parent.Children.Add (grid); CreateAsyncTest (parent, () => { grid.Reset (); TestPanel.Measure (Infinity); // Nothing is measured as the grid always uses (Inf, Inf) to measure children. grid.CheckMeasureArgs ("#1"); Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#3"); grid.Reset (); grid.Arrange (new Rect (0, 0, 100, 100)); grid.CheckMeasureArgs ("#8"); // No remeasures grid.CheckArrangeArgs ("#9", new Size (100, 100)); grid.CheckArrangeResult ("#10", new Size (100, 100)); grid.CheckRowHeights ("#11", 100); grid.CheckColWidths ("#12", 100); // If we measure with a finite size, the rows/cols still expand // to consume the available space grid.Reset (); grid.Measure (new Size (1000, 1000)); grid.CheckMeasureArgs ("#13", new Size (1000, 1000)); grid.CheckMeasureResult ("#14", new Size (50, 50)); Assert.AreEqual (new Size (50, 50), grid.DesiredSize, "#15"); // When we pass in the desired size as the arrange arg, // the rows/cols use that as their height/width grid.Arrange (new Rect (0, 0, grid.DesiredSize.Width, grid.DesiredSize.Height)); grid.CheckArrangeArgs ("#16", grid.DesiredSize); grid.CheckArrangeResult ("#17", grid.DesiredSize); grid.CheckRowHeights ("#18", grid.DesiredSize.Height); grid.CheckColWidths ("#19", grid.DesiredSize.Width); // If we pass in twice the desired size, the rows/cols consume that too grid.Reset (); grid.Arrange (new Rect (0, 0, 100, 100)); grid.CheckMeasureArgs ("#20"); // No remeasures grid.CheckArrangeArgs ("#21", new Size (100, 100)); grid.CheckArrangeResult ("#22", new Size (100, 100)); grid.CheckRowHeights ("#23", 100); grid.CheckColWidths ("#24", 100); }); }