Exemplo n.º 1
0
		public void NestedRowsLayout()
		{
			var styles = new AssembledStyles();
			var box1 = new LayoutInfoRecorderBox(styles, Color.Red, 72000, 36000);
			var box2 = new LayoutInfoRecorderBox(styles, Color.Blue, 108000, 18000);
			var box3 = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
			var box4 = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
			var widths = new FixedColumnWidths(new[] {34, 67, 99});
			// pass widths to RowBox constructor
			var row1 = new RowBox(styles, widths, false);
			var row2 = new RowBox(styles, widths, false);
			row1.AddBox(box1);
			row1.AddBox(box2);
			row2.AddBox(box3);
			row2.AddBox(box4);
			RootBox root = new RootBox(styles);
			root.AddBox(row1);
			root.AddBox(row2);
			LayoutInfo layoutArgs = MakeLayoutInfo();
			root.Layout(layoutArgs);
			Assert.That(box1.LastLayoutInfo.MaxWidth, Is.EqualTo(34));
			Assert.That(box1.Height, Is.EqualTo(48));
			Assert.That(box2.Height, Is.EqualTo(24));
			Assert.That(box3.Height, Is.EqualTo(24));
			Assert.That(box4.Height, Is.EqualTo(24));
			Assert.That(root.Height, Is.EqualTo(48 + 24));
			Assert.That(box1.Left, Is.EqualTo(0));
			Assert.That(box2.Left, Is.EqualTo(96));
			Assert.That(box3.Left, Is.EqualTo(0));
			Assert.That(box4.Left, Is.EqualTo(96));
			Assert.That(row1.Top, Is.EqualTo(0));
			Assert.That(box1.Top, Is.EqualTo(0));
			Assert.That(box2.Top, Is.EqualTo(0));
			Assert.That(row2.Top, Is.EqualTo(48));
			Assert.That(box3.Top, Is.EqualTo(0));
			Assert.That(box4.Top, Is.EqualTo(0));
			Assert.That(box1.Width, Is.EqualTo(96));
			Assert.That(box2.Width, Is.EqualTo(144));
			Assert.That(box3.Width, Is.EqualTo(96));
			Assert.That(box4.Width, Is.EqualTo(96));
			Assert.That(root.Width, Is.EqualTo(96 + 144));

			// Now try changing the size of a block.
			MockSite site = new MockSite();
			root.Site = site;
			PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);
			site.m_transform = ptrans;
			site.m_vwGraphics = m_gm.VwGraphics;
			box2.UpdateSize(144000, 36000);
			Assert.That(box2.Width, Is.EqualTo(96 * 2));
			Assert.That(box2.Height, Is.EqualTo(48));
			Assert.That(row1.Height, Is.EqualTo(48));
			Assert.That(root.Height, Is.EqualTo(72));
			Assert.That(root.Width, Is.EqualTo(96 * 3));
			// Since it got both wider and higher, we should invalidate at least the whole current size.
			var bigInvalidate = root.InvalidateRect;
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(108000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(96 + 144)); // narrower box2 still determines it
			// Got narrower, at least the whole old invalidate rectangle should be invalidated.
			Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

			site.RectsInvalidated.Clear();
			box2.UpdateSize(72000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); // unchanged this time
			Assert.That(root.Width, Is.EqualTo(144 + 48)); // new smaller value
			// It got thinner. We want an optimized invalidate rectangle that does not
			// include the left boxes. But it must include the space at the right that the root box used to occupy.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it's in the fixmap so its own Relayout does this);
			// the shrinkage area at the right of row2;
			// and the area computed because row2 moved.
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 48, 144); // old box2
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of row1
			// This is from the new left of div2 to its old right (old right was 48 + 48 + 24 + 24)
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

			site.RectsInvalidated.Clear();
			box2.UpdateSize(144000, 18000);
			Assert.That(root.Height, Is.EqualTo(48 + 24)); //  unchanged this time
			Assert.That(root.Width, Is.EqualTo(144 + 144)); // new larger value
			// It got wider. We want an optimized invalidate rectangle that does not
			// include the left boxes. But it must include the space at the right where the root box grew.
			// There are other possible implementations, but currently, we expect the old rectangle of box2
			// to be invalidated (it returns true from Relayout);
			// the growth area at the right of div2;
			// and the area computed because div2 moved.
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
			// This is from the old left of div2 to its new right (48 + 96 + 24 + 24)
			//VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
		}
Exemplo n.º 2
0
        public void NestedRowsLayout()
        {
            var styles = new AssembledStyles();
            var box1   = new LayoutInfoRecorderBox(styles, Color.Red, 72000, 36000);
            var box2   = new LayoutInfoRecorderBox(styles, Color.Blue, 108000, 18000);
            var box3   = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
            var box4   = new LayoutInfoRecorderBox(styles, Color.Orange, 72000, 18000);
            var widths = new FixedColumnWidths(new[] { 34, 67, 99 });
            // pass widths to RowBox constructor
            var row1 = new RowBox(styles, widths, false);
            var row2 = new RowBox(styles, widths, false);

            row1.AddBox(box1);
            row1.AddBox(box2);
            row2.AddBox(box3);
            row2.AddBox(box4);
            RootBox root = new RootBox(styles);

            root.AddBox(row1);
            root.AddBox(row2);
            LayoutInfo layoutArgs = MakeLayoutInfo();

            root.Layout(layoutArgs);
            Assert.That(box1.LastLayoutInfo.MaxWidth, Is.EqualTo(34));
            Assert.That(box1.Height, Is.EqualTo(48));
            Assert.That(box2.Height, Is.EqualTo(24));
            Assert.That(box3.Height, Is.EqualTo(24));
            Assert.That(box4.Height, Is.EqualTo(24));
            Assert.That(root.Height, Is.EqualTo(48 + 24));
            Assert.That(box1.Left, Is.EqualTo(0));
            Assert.That(box2.Left, Is.EqualTo(96));
            Assert.That(box3.Left, Is.EqualTo(0));
            Assert.That(box4.Left, Is.EqualTo(96));
            Assert.That(row1.Top, Is.EqualTo(0));
            Assert.That(box1.Top, Is.EqualTo(0));
            Assert.That(box2.Top, Is.EqualTo(0));
            Assert.That(row2.Top, Is.EqualTo(48));
            Assert.That(box3.Top, Is.EqualTo(0));
            Assert.That(box4.Top, Is.EqualTo(0));
            Assert.That(box1.Width, Is.EqualTo(96));
            Assert.That(box2.Width, Is.EqualTo(144));
            Assert.That(box3.Width, Is.EqualTo(96));
            Assert.That(box4.Width, Is.EqualTo(96));
            Assert.That(root.Width, Is.EqualTo(96 + 144));

            // Now try changing the size of a block.
            MockSite site = new MockSite();

            root.Site = site;
            PaintTransform ptrans = new PaintTransform(2, 4, 96, 96, 0, 10, 120, 128);

            site.m_transform  = ptrans;
            site.m_vwGraphics = m_gm.VwGraphics;
            box2.UpdateSize(144000, 36000);
            Assert.That(box2.Width, Is.EqualTo(96 * 2));
            Assert.That(box2.Height, Is.EqualTo(48));
            Assert.That(row1.Height, Is.EqualTo(48));
            Assert.That(root.Height, Is.EqualTo(72));
            Assert.That(root.Width, Is.EqualTo(96 * 3));
            // Since it got both wider and higher, we should invalidate at least the whole current size.
            var bigInvalidate = root.InvalidateRect;

            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(108000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             // unchanged this time
            Assert.That(root.Width, Is.EqualTo(96 + 144));             // narrower box2 still determines it
            // Got narrower, at least the whole old invalidate rectangle should be invalidated.
            Assert.That(site.RectsInvalidatedInRoot, Has.Member(bigInvalidate));

            site.RectsInvalidated.Clear();
            box2.UpdateSize(72000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             // unchanged this time
            Assert.That(root.Width, Is.EqualTo(144 + 48));             // new smaller value
            // It got thinner. We want an optimized invalidate rectangle that does not
            // include the left boxes. But it must include the space at the right that the root box used to occupy.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it's in the fixmap so its own Relayout does this);
            // the shrinkage area at the right of row2;
            // and the area computed because row2 moved.
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 48, 144); // old box2
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 24); // shrinkage of row1
            // This is from the new left of div2 to its old right (old right was 48 + 48 + 24 + 24)
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 48 + 24);

            site.RectsInvalidated.Clear();
            box2.UpdateSize(144000, 18000);
            Assert.That(root.Height, Is.EqualTo(48 + 24));             //  unchanged this time
            Assert.That(root.Width, Is.EqualTo(144 + 144));            // new larger value
            // It got wider. We want an optimized invalidate rectangle that does not
            // include the left boxes. But it must include the space at the right where the root box grew.
            // There are other possible implementations, but currently, we expect the old rectangle of box2
            // to be invalidated (it returns true from Relayout);
            // the growth area at the right of div2;
            // and the area computed because div2 moved.
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48, 144, 96); // new box2
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 - 24); // new part of div1 occupied by box2
            // This is from the old left of div2 to its new right (48 + 96 + 24 + 24)
            //VerifyExpectedRectangle(site.RectsInvalidatedInRoot, 0, 48 + 24, 144, 96 + 24);
        }