Example #1
0
        public void PositionShouldNotChange(Orientation orient, SplitterFixedPanel fix)
        {
            bool replay = false;

            Shown(
                form => new Splitter()
            {
                Size        = new Size(300, 300),
                Orientation = orient,
                FixedPanel  = fix,
                Position    = 50,
                Panel1      = new Panel
                {
                    BackgroundColor = Colors.White
                },
                Panel2 = new Panel
                {
                    BackgroundColor = Colors.Black
                }
            },
                it =>
            {
                Assert.AreEqual(50, it.Position, "Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                if (ReplayTests)
                {
                    replay = !replay;
                }
            }, replay: ReplayTests);
        }
Example #2
0
        public void RelativePositionShouldNotChange(Orientation orient, SplitterFixedPanel fix)
        {
            bool   replay = false;
            double pos    = fix == SplitterFixedPanel.None ? (1 / 3.0) : 50;

            Shown(
                form => new Splitter()
            {
                Size             = new Size(300, 300),
                Orientation      = orient,
                FixedPanel       = fix,
                RelativePosition = pos,
                Panel1           = new Panel
                {
                    BackgroundColor = Colors.White
                },
                Panel2 = new Panel
                {
                    BackgroundColor = Colors.Black
                }
            },
                it =>
            {
                Assert.AreEqual(pos, it.RelativePosition, 1e-2, "Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                if (ReplayTests)
                {
                    replay = !replay;
                }
            },
                replay: ReplayTests);
        }
Example #3
0
		public void NoPositionShouldAutoSizeBasic(Orientation orient, SplitterFixedPanel fix)
		{
			bool replay = false;
			var sz = new Size(50, 50);
			TestUtils.Shown(
				form => new Splitter
				{
					Orientation = orient,
					FixedPanel = fix,
					Panel1 = new Panel
					{
						Size = sz,
						BackgroundColor = Colors.White
					},
					Panel2 = new Panel
					{
						Size = sz,
						BackgroundColor = Colors.Black
					}
				},
				it =>
				{
					if (orient == Orientation.Horizontal)
						Assert.AreEqual(it.Panel1.Height, it.Panel2.Height,
							"Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
					else
						Assert.AreEqual(it.Panel1.Width, it.Panel2.Width,
							"Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
					switch (fix)
					{
						case SplitterFixedPanel.Panel1:
							if (orient == Orientation.Horizontal)
								Assert.AreEqual(sz.Width, it.Panel1.Width,
									"P1.Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
							else
								Assert.AreEqual(sz.Height, it.Panel1.Height,
									"P1.Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
							break;
						case SplitterFixedPanel.Panel2:
							if (orient == Orientation.Horizontal)
								Assert.AreEqual(sz.Width, it.Panel2.Width,
									"P2.Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
							else
								Assert.AreEqual(sz.Height, it.Panel2.Height,
									"P2.Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
							break;
						case SplitterFixedPanel.None:
							if (orient == Orientation.Horizontal)
								Assert.AreEqual(it.Panel1.Width, it.Panel2.Width, 1,
									"Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
							else
								Assert.AreEqual(it.Panel1.Height, it.Panel2.Height, 1,
									"Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
							break;
					}
					if (ReplayTests)
						replay = !replay;
				},
				replay: ReplayTests);
		}
Example #4
0
		public void RelativePositionShouldNotChange(Orientation orient, SplitterFixedPanel fix)
		{
			bool replay = false;
			double pos = fix == SplitterFixedPanel.None ? (1 / 3.0) : 50;
			TestUtils.Shown(
				form => new Splitter()
				{
					Size = new Size(300, 300),
					Orientation = orient,
					FixedPanel = fix,
					RelativePosition = pos,
					Panel1 = new Panel
					{
						BackgroundColor = Colors.White
					},
					Panel2 = new Panel
					{
						BackgroundColor = Colors.Black
					}
				},
				it =>
				{
					Assert.AreEqual(pos, it.RelativePosition, 1e-2, "Fix: {0}; {1} [replay={2}]", fix, orient, replay);
					if (ReplayTests)
						replay = !replay;
				},
				replay: ReplayTests);
		}
Example #5
0
		public void PositionShouldNotChange(Orientation orient, SplitterFixedPanel fix)
		{
			bool replay = false;
			TestUtils.Shown(
				form => new Splitter()
				{
					Size = new Size(300, 300),
					Orientation = orient,
					FixedPanel = fix,
					Position = 50,
					Panel1 = new Panel
					{
						BackgroundColor = Colors.White
					},
					Panel2 = new Panel
					{
						BackgroundColor = Colors.Black
					}
				}, 
				it =>
				{
					Assert.AreEqual(50, it.Position, "Fix: {0}; {1} [replay={2}]", fix, orient, replay);
					if (ReplayTests)
						replay = !replay;
				}, replay: ReplayTests);
		}
Example #6
0
        public void NoPositionShouldAutoSizeComplexTest1(Orientation orient, SplitterFixedPanel fix)
        {
            bool replay = false;

            Shown(
                form =>
            {
                form.WindowStyle = WindowStyle.Utility;
                // +====test 1====+
                // |        |     |
                // | tested |     |   Tested splitter is placed inside two other splitters
                // |        |     |   to overcome minimal window/form size problems
                // +--------+     |   ...or non-desktop plaforms
                // |        |     |
                // +--------+-----+
                var it = new Splitter
                {
                    ID          = "main.panel1.panel1",
                    Orientation = orient,
                    FixedPanel  = fix,
                    Panel1      = new Panel
                    {
                        Size            = new Size(40, 40),
                        BackgroundColor = Colors.White
                    },
                    Panel2 = new Panel
                    {
                        Size            = new Size(60, 60),
                        BackgroundColor = Colors.Black
                    }
                };
                form.Content = new Splitter
                {
                    ID     = "main",
                    Panel1 = new Splitter
                    {
                        ID          = "main.panel1",
                        Orientation = Orientation.Vertical,
                        Panel1      = it,
                        Panel2      = new Panel()
                    },
                    Panel2 = new Panel()
                };
                return(it);
            },
                it =>
            {
                Assert.AreEqual(40, it.Position, $"#1 {fix}; {orient}; Replay:{replay}");
                Assert.AreEqual(fix == SplitterFixedPanel.Panel1 ? 40 : fix == SplitterFixedPanel.Panel2 ? 60 : 0.4, it.RelativePosition, "{0}; {1}", $"#2 {fix}; {orient}; Replay:{replay}");
                var sz = orient == Orientation.Horizontal ? new Size(100 + it.SplitterWidth, 60) : new Size(60, 100 + it.SplitterWidth);
                Assert.AreEqual(sz, it.Size, $"#3 {fix}; {orient}; Replay:{replay}");
                if (ReplayTests)
                {
                    replay = !replay;
                }
            }, replay: ReplayTests);
        }
Example #7
0
        private void UpdateRelativePosition(SplitterFixedPanel newFixedPanel)
        {
            if (double.IsNaN(relative))
            {
                return;
            }

            // translate relative position from old fixed panel to new fixed panel
            var width = orientation == Orientation.Horizontal ? Control.ActualWidth : Control.ActualHeight;

            switch (fixedPanel)
            {
            case SplitterFixedPanel.Panel1:
                switch (newFixedPanel)
                {
                case SplitterFixedPanel.Panel2:
                    relative = width - relative - SplitterWidth;
                    break;

                case SplitterFixedPanel.None:
                    relative = relative / width;
                    break;
                }
                break;

            case SplitterFixedPanel.Panel2:
                switch (newFixedPanel)
                {
                case SplitterFixedPanel.Panel1:
                    relative = width - relative - SplitterWidth;
                    break;

                case SplitterFixedPanel.None:
                    relative = (width - relative) / width;
                    break;
                }
                break;

            case SplitterFixedPanel.None:
                switch (newFixedPanel)
                {
                case SplitterFixedPanel.Panel1:
                    relative = width * relative;
                    break;

                case SplitterFixedPanel.Panel2:
                    relative = width - (width * relative);
                    break;
                }
                break;
            }
        }
Example #8
0
 public void NoPositionShouldAutoSizeComplexTest2(Orientation orient, SplitterFixedPanel fix)
 {
     Shown(
         form =>
     {
         // +====test 2====+
         // |              |
         // |-----+--------|  Tested splitter is placed inside two other splitters
         // |     |        |  to overcome minimal window/form size problems
         // |     | tested |  ...or non-desktop plaforms
         // |     |        |
         // +-----+--------+
         var it = new Splitter
         {
             Orientation = orient,
             FixedPanel  = fix,
             Panel1      = new Panel
             {
                 Size            = new Size(40, 40),
                 BackgroundColor = Colors.White
             },
             Panel2 = new Panel
             {
                 Size            = new Size(60, 60),
                 BackgroundColor = Colors.Black
             }
         };
         form.Content = new Splitter
         {
             Orientation = Orientation.Vertical,
             FixedPanel  = SplitterFixedPanel.Panel2,
             Panel1      = new Panel(),
             Panel2      = new Splitter
             {
                 FixedPanel = SplitterFixedPanel.Panel2,
                 Panel1     = new Panel(),
                 Panel2     = it
             }
         };
         return(it);
     },
         it =>
     {
         Assert.AreEqual(40, it.Position, "{0}; {1}", fix, orient);
         Assert.AreEqual(fix == SplitterFixedPanel.Panel1 ? 40 : fix == SplitterFixedPanel.Panel2 ? 60 : 0.4, it.RelativePosition, "{0}; {1}", fix, orient);
         var sz = orient == Orientation.Horizontal ? new Size(100 + it.SplitterWidth, 60) : new Size(60, 100 + it.SplitterWidth);
         Assert.AreEqual(sz, it.Size, "{0}; {1}", fix, orient);
     }, replay: ReplayTests);
 }
Example #9
0
        // Issue #309
        public void PositionShouldTrackInitialResize(Orientation orient, SplitterFixedPanel fix)
        {
            bool replay = false;

            Shown(
                form =>
            {
                var it = new Splitter()
                {
                    Orientation = orient,
                    FixedPanel  = fix,
                    Position    = 50,
                    Panel1      = new Panel
                    {
                        BackgroundColor = Colors.White
                    },
                    Panel2 = new Panel
                    {
                        BackgroundColor = Colors.Black
                    }
                };
                it.Size         = new Size(100, 100) + it.SplitterWidth;
                form.ClientSize = new Size(150, 150) + it.SplitterWidth;
                return(it);
            },
                it =>
            {
                double pos = fix == SplitterFixedPanel.None ? 0.5 : 50.0;
                Assert.AreEqual(pos, it.RelativePosition, 1e-2, "Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                if (ReplayTests)
                {
                    replay = !replay;
                }
            },
                replay: ReplayTests);
        }
Example #10
0
        public void NoPositionShouldAutoSizeBasic(Orientation orient, SplitterFixedPanel fix)
        {
            bool replay = false;
            var  sz     = new Size(50, 50);

            Shown(
                form => new Splitter
            {
                Orientation = orient,
                FixedPanel  = fix,
                Panel1      = new Panel
                {
                    Size            = sz,
                    BackgroundColor = Colors.White
                },
                Panel2 = new Panel
                {
                    Size            = sz,
                    BackgroundColor = Colors.Black
                }
            },
                it =>
            {
                if (orient == Orientation.Horizontal)
                {
                    Assert.AreEqual(it.Panel1.Height, it.Panel2.Height,
                                    "Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                }
                else
                {
                    Assert.AreEqual(it.Panel1.Width, it.Panel2.Width,
                                    "Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                }
                switch (fix)
                {
                case SplitterFixedPanel.Panel1:
                    if (orient == Orientation.Horizontal)
                    {
                        Assert.AreEqual(sz.Width, it.Panel1.Width,
                                        "P1.Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                    }
                    else
                    {
                        Assert.AreEqual(sz.Height, it.Panel1.Height,
                                        "P1.Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                    }
                    break;

                case SplitterFixedPanel.Panel2:
                    if (orient == Orientation.Horizontal)
                    {
                        Assert.AreEqual(sz.Width, it.Panel2.Width,
                                        "P2.Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                    }
                    else
                    {
                        Assert.AreEqual(sz.Height, it.Panel2.Height,
                                        "P2.Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                    }
                    break;

                case SplitterFixedPanel.None:
                    if (orient == Orientation.Horizontal)
                    {
                        Assert.AreEqual(it.Panel1.Width, it.Panel2.Width, 1,
                                        "Width! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                    }
                    else
                    {
                        Assert.AreEqual(it.Panel1.Height, it.Panel2.Height, 1,
                                        "Height! Fix: {0}; {1} [replay={2}]", fix, orient, replay);
                    }
                    break;
                }
                if (ReplayTests)
                {
                    replay = !replay;
                }
            },
                replay: ReplayTests);
        }
Example #11
0
		// Issue #309
		public void PositionShouldTrackInitialResize(Orientation orient, SplitterFixedPanel fix)
		{
			bool replay = false;
			TestUtils.Shown(
				form =>
				{
					var it = new Splitter()
					{
						Orientation = orient,
						FixedPanel	= fix,
						Position	= 50,
						Panel1 = new Panel
						{
							BackgroundColor = Colors.White
						},
						Panel2 = new Panel
						{
							BackgroundColor = Colors.Black
						}
					};
					it.Size = new Size(100, 100) + it.SplitterWidth;
					form.ClientSize = new Size(150, 150) + it.SplitterWidth;
					return it;
				},
				it =>
				{
					double pos = fix == SplitterFixedPanel.None ? 0.5 : 50.0;
					Assert.AreEqual(pos, it.RelativePosition, 1e-2, "Fix: {0}; {1} [replay={2}]", fix, orient, replay);
					if (ReplayTests)
						replay = !replay;
				},
				replay: ReplayTests);
		}
Example #12
0
		public void NoPositionShouldAutoSizeComplexTest2(Orientation orient, SplitterFixedPanel fix)
		{
			TestUtils.Shown(
				form =>
				{
					// +====test 2====+
					// |              |
					// |-----+--------|  Tested splitter is placed inside two other splitters
					// |     |        |  to overcome minimal window/form size problems
					// |     | tested |  ...or non-desktop plaforms
					// |     |        |
					// +-----+--------+
					var it = new Splitter
					{
						Orientation = orient,
						FixedPanel = fix,
						Panel1 = new Panel
						{
							Size = new Size(40, 40),
							BackgroundColor = Colors.White
						},
						Panel2 = new Panel
						{
							Size = new Size(60, 60),
							BackgroundColor = Colors.Black
						}
					};
					form.Content = new Splitter
					{
						Orientation = Orientation.Vertical,
						FixedPanel = SplitterFixedPanel.Panel2,
						Panel1 = new Panel(),
						Panel2 = new Splitter
						{
							FixedPanel = SplitterFixedPanel.Panel2,
							Panel1 = new Panel(),
							Panel2 = it
						}
					};
					return it;
				}, 
				it =>
				{
					Assert.AreEqual(40, it.Position, "{0}; {1}", fix, orient);
					Assert.AreEqual(fix == SplitterFixedPanel.Panel1 ? 40 : fix == SplitterFixedPanel.Panel2 ? 60 : 0.4, it.RelativePosition, "{0}; {1}", fix, orient);
					var sz = orient == Orientation.Horizontal ? new Size(100 + it.SplitterWidth, 60) : new Size(60, 100 + it.SplitterWidth);
					Assert.AreEqual(sz, it.Size, "{0}; {1}", fix, orient);
				}, replay: ReplayTests);
		}