Beispiel #1
0
            public void GetNormalRectAfterLayout()
            {
                var layout = new StackLayout(0, new Size(800, 600));

                layout.Begin();
                layout.GetRect(1, new Size(100, 30));
                layout.Layout();
                var rect = layout.GetRect(1, new Size(100, 30));

                Assert.Equal(0, rect.X);
                Assert.Equal(0, rect.Y);
                Assert.Equal(100, rect.Width);
                Assert.Equal(30, rect.Height);
            }
Beispiel #2
0
            public void GetRectWithExpandWidth(bool expandWidth, bool expandHeight)
            {
                var layout  = new StackLayout(0, new Size(800, 600));
                var size    = new Size(200, 300);
                var options = GUILayout.ExpandWidth(expandWidth).ExpandHeight(expandHeight);

                layout.Begin();
                layout.GetRect(1, size, options);
                layout.Layout();
                var rect = layout.GetRect(1, size, options);

                Assert.Equal(0, rect.X);
                Assert.Equal(0, rect.Y);
                Assert.Equal(expandWidth ? 800 : size.Width, rect.Width);
                Assert.Equal(expandHeight ? 600 : size.Height, rect.Height);
            }
Beispiel #3
0
            public void GetRectWithFixedWidthAndHeight()
            {
                var       layout      = new StackLayout(0, new Size(800, 600));
                var       size        = new Size(200, 300);
                const int fixedWidth  = 100;
                const int fixedHeight = 200;
                var       options     = GUILayout.Width(fixedWidth).Height(fixedHeight);

                layout.Begin();
                layout.GetRect(1, size, options);
                layout.Layout();
                var rect = layout.GetRect(1, size, options);

                Assert.Equal(0, rect.X);
                Assert.Equal(0, rect.Y);
                Assert.Equal(fixedWidth, rect.Width);
                Assert.Equal(fixedHeight, rect.Height);
            }
Beispiel #4
0
            public void GetRectWithBorder()
            {
                var layout = new StackLayout(0, new Size(800, 600));
                var size   = new Size(200, 300);
                var style  = new GUIStyle();

                style.Border = (1, 2, 3, 4);
                //FIXME per-entry style modification

                layout.Begin();
                layout.GetRect(1, size);
                layout.Layout();
                var rect = layout.GetRect(1, size);

                Assert.Equal(0, rect.X);
                Assert.Equal(0, rect.Y);
                Assert.Equal(size.Width + style.BorderHorizontal, rect.Width);
                Assert.Equal(size.Height + style.BorderVertical, rect.Height);
            }
            public void GetRectAfterRelayout2() //Add two group, then remove first group
            {
                var layout = new StackLayout(0, new Size(800, 600));
                var size   = new Size(200, 300);

                // Frame 0
                layout.Begin();
                {
                    layout.BeginLayoutGroup(1, true); //add group 1
                    layout.GetRect(1, size);          //add rect 1
                    layout.EndLayoutGroup();
                    layout.BeginLayoutGroup(2, true); //add group 2
                    layout.GetRect(2, size);          //add rect 2
                    layout.EndLayoutGroup();
                }
                layout.Layout();

                // Frame 1
                layout.Begin();
                {
                    //remove group 1
                    layout.BeginLayoutGroup(2, true); //get group 2
                    layout.GetRect(2, size);          //get rect 2
                    layout.EndLayoutGroup();
                }
                layout.Layout();

                // Frame 2
                layout.Begin();
                {
                    //group 1 removed
                    layout.BeginLayoutGroup(2, true);    //get group 2
                    var rect2 = layout.GetRect(2, size); //get rect 3
                    layout.EndLayoutGroup();

                    Assert.Equal(0, rect2.X);
                    Assert.Equal(0, rect2.Y);
                    Assert.Equal(size.Width, rect2.Width);
                    Assert.Equal(size.Height, rect2.Height);
                }
                layout.Layout();
            }
Beispiel #6
0
            public void CannotGetRectOfVerySmallSize()
            {
                var  layout    = new StackLayout(0, new Size(800, 600));
                Size zeroSize  = Size.Zero;
                Size smallSize = new Size(0.5, 0.6);

                layout.Begin();

                //TODO see the commented out code at the beginning of StackLayout.GetRect.

                Assert.Throws <ArgumentOutOfRangeException>("contentSize", () =>
                {
                    layout.GetRect(1, zeroSize);
                });

                Assert.Throws <ArgumentOutOfRangeException>("contentSize", () =>
                {
                    layout.GetRect(1, smallSize);
                });
            }
Beispiel #7
0
            public void GetRectInsideGroup()
            {
                var layout = new StackLayout(0, new Size(800, 600));
                var size   = new Size(200, 300);

                layout.Begin();
                layout.BeginLayoutGroup(1, true);
                layout.GetRect(2, size);
                layout.EndLayoutGroup();
                layout.Layout();

                layout.Begin();
                layout.BeginLayoutGroup(1, true);
                var rect = layout.GetRect(2, size);

                layout.EndLayoutGroup();

                Assert.Equal(0, rect.X);
                Assert.Equal(0, rect.Y);
                Assert.Equal(size.Width, rect.Width);
                Assert.Equal(size.Height, rect.Height);
            }
Beispiel #8
0
        /// <summary>
        /// Get the rect for an automatic-layout control
        /// </summary>
        /// <param name="id">id of the control</param>
        /// <param name="size">size of content, border and padding NOT included</param>
        /// <param name="style">style that will apply to requested rect</param>
        /// <returns></returns>
        public Rect GetRect(int id, Size size, LayoutOptions?options = null, string str_id = null)
        {
            var rect = StackLayout.GetRect(id, size, options, str_id);

            if (rect != StackLayout.DummyRect)
            {
                Rect newContentRect = ContentRect;
                newContentRect.Union(rect);
                ContentRect = newContentRect;

                // Apply window position, style(border and padding) and titlebar
                rect.Offset(this.Position.X + this.Style.BorderLeft + this.Style.PaddingLeft, this.Position.Y + this.TitleBarHeight + this.Style.BorderTop + this.Style.PaddingTop);
                rect.Offset(-this.Scroll);
            }

            return(rect);
        }
            public void GetRectAfterRelayout4()
            {
                var layout = new StackLayout(0, new Size(800, 600));
                var size   = new Size(200, 300);

                // Frame 0
                layout.Begin();
                {
                    layout.GetRect(1, size);

                    layout.BeginLayoutGroup(1, true);
                    layout.GetRect(2, size);
                    layout.EndLayoutGroup();

                    layout.GetRect(3, size);

                    layout.BeginLayoutGroup(2, true);
                    layout.GetRect(4, size);
                    layout.EndLayoutGroup();
                }
                layout.Layout();

                layout.Begin();
                {
                    layout.GetRect(1, size);

                    layout.BeginLayoutGroup(1, true);
                    layout.GetRect(2, size);
                    layout.EndLayoutGroup();

                    layout.GetRect(3, size);

                    layout.BeginLayoutGroup(2, true);
                    layout.GetRect(4, size);
                    layout.EndLayoutGroup();
                }
                layout.Layout();
            }
            public void GetRectAfterRelayout1() // Add rect; Add rect then remove rect
            {
                var layout = new StackLayout(0, new Size(800, 600));
                var size   = new Size(200, 300);

                // Frame 0
                layout.Begin();
                {
                    layout.GetRect(1, size, null, null); //add rect 1
                    //entry 1 active
                }
                layout.Layout();

                // Frame 1
                layout.Begin();
                {
                    var rect1 = layout.GetRect(1, size, null, null); //get rect 1

                    Assert.Equal(0, rect1.X);
                    Assert.Equal(0, rect1.Y);
                    Assert.Equal(size.Width, rect1.Width);
                    Assert.Equal(size.Height, rect1.Height);

                    layout.GetRect(2, size, null, null); //add rect 2
                    //entry 1 active
                    //entry 2 active
                    //layout dirty
                }
                layout.Layout();

                // Frame 2
                layout.Begin();
                {
                    // remove rect 1 (works on next frame)
                    var rect2 = layout.GetRect(2, size, null, null); //get rect 2

                    Assert.Equal(0, rect2.X);
                    Assert.Equal(300 + GUIStyle.Default.CellSpacingVertical, rect2.Y);
                    Assert.Equal(size.Width, rect2.Width);
                    Assert.Equal(size.Height, rect2.Height);

                    //entry 1 active
                    //entry 2 active
                }
                layout.Layout();

                // Frame 3
                layout.Begin();
                {
                    // rect 1 removed
                    var rect2 = layout.GetRect(2, size, null, null); //get rect 2

                    Assert.Equal(0, rect2.X);
                    Assert.Equal(0, rect2.Y);
                    Assert.Equal(size.Width, rect2.Width);
                    Assert.Equal(size.Height, rect2.Height);

                    //entry 2 active
                }
                layout.Layout();
            }