public void TopToBottomContainerAppliesExpectedMarginToToggleView()
		{
			TestContext.CurrentContext.SetCompatibleWorkingDirectory();

			int marginSize = 40;
			int dimensions = 300;

			GuiWidget outerContainer = new GuiWidget(dimensions, dimensions);

			FlowLayoutWidget topToBottomContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
			{
				HAnchor = HAnchor.ParentLeftRight,
				VAnchor = VAnchor.ParentBottomTop,
			};
			outerContainer.AddChild(topToBottomContainer);

			CheckBox toggleBox = new CheckBox("test");
			toggleBox.HAnchor = HAnchor.ParentLeftRight;
			toggleBox.VAnchor = VAnchor.ParentBottomTop;
			toggleBox.Margin = new BorderDouble(marginSize);
			toggleBox.BackgroundColor = RGBA_Bytes.Red;
			toggleBox.DebugShowBounds = true;

			topToBottomContainer.AddChild(toggleBox);
			topToBottomContainer.AnchorAll();
			topToBottomContainer.PerformLayout();

			outerContainer.DoubleBuffer = true;
			outerContainer.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
			outerContainer.OnDraw(outerContainer.NewGraphics2D());

			// For troubleshooting or visual validation
			OutputImages(outerContainer, outerContainer);

			var bounds = toggleBox.BoundsRelativeToParent;
			Assert.IsTrue(bounds.Left == marginSize, "Left margin is incorrect");
			Assert.IsTrue(bounds.Right == dimensions - marginSize, "Right margin is incorrect");
			Assert.IsTrue(bounds.Top == dimensions - marginSize, "Top margin is incorrect");
			Assert.IsTrue(bounds.Bottom == marginSize, "Bottom margin is incorrect");
		}
示例#2
0
        private void topLevelWindow_MouseMove(object sender, MouseEventArgs mouseEvent)
        {
            count++;
            if (count == 20)
            {
                RemoveAllChildren();

                ScrollableWidget allContainer = new ScrollableWidget(true);
                topToBottomTotal = new FlowLayoutWidget(FlowDirection.TopToBottom);

                topToBottomTotal.SuspendLayout();
                GuiWidget.DefaultEnforceIntegerBounds = true;
                AddInfoRecursive(topLevelWindow, topToBottomTotal);
                GuiWidget.DefaultEnforceIntegerBounds = false;
                topToBottomTotal.ResumeLayout();
                topToBottomTotal.PerformLayout();
                allContainer.AddChild(topToBottomTotal);

                AddChild(allContainer);
                allContainer.AnchorAll();
            }
        }
示例#3
0
        protected void DoWrappingLayout()
        {
            if (doingLayout)
            {
                needAnotherLayout = true;
                return;
            }

            using (this.LayoutLock())
            {
                doingLayout = true;
                // remove all the children we added
                foreach (var child in addedChildren)
                {
                    if (child.Parent != null)
                    {
                        using (child.Parent.LayoutLock())
                        {
                            child.Parent.RemoveChild(child);
                            child.ClearRemovedFlag();
                        }
                    }
                }

                // close all the row containers
                this.CloseChildren();

                // add in new row container
                FlowLayoutWidget childContainerRow = new FlowLayoutWidget()
                {
                    Margin  = RowMargin,
                    Padding = RowPadding,
                    HAnchor = HAnchor.Stretch,
                };
                base.AddChild(childContainerRow);

                double runningSize = 0;
                MaxLineWidth = 0;
                foreach (var child in addedChildren)
                {
                    if (Parent != null &&
                        (runningSize + child.Width > Parent.Width ||
                         child is IHardBreak))
                    {
                        MaxLineWidth = Math.Max(MaxLineWidth, runningSize);
                        runningSize  = 0;
                        if (childContainerRow != null)
                        {
                            childContainerRow.PerformLayout();
                        }

                        childContainerRow = new FlowLayoutWidget()
                        {
                            Margin  = RowMargin,
                            Padding = RowPadding,
                            HAnchor = HAnchor.Stretch,
                        };

                        base.AddChild(childContainerRow);
                    }

                    if (runningSize > 0 ||
                        !(child is ISkipIfFirst))
                    {
                        // add the new child to the current row
                        using (childContainerRow.LayoutLock())
                        {
                            childContainerRow.AddChild(child);
                        }

                        runningSize += child.Width;
                        MaxLineWidth = Math.Max(MaxLineWidth, runningSize);
                    }
                }

                if (childContainerRow != null)
                {
                    childContainerRow.PerformLayout();
                }

                doingLayout = false;
            }

            if (needAnotherLayout)
            {
                UiThread.RunOnIdle(DoWrappingLayout);
                needAnotherLayout = false;
            }

            this.PerformLayout();
        }
示例#4
0
		private void topLevelWindow_MouseMove(object sender, MouseEventArgs mouseEvent)
		{
			count++;
			if (count == 20)
			{
				RemoveAllChildren();

				ScrollableWidget allContainer = new ScrollableWidget(true);
				topToBottomTotal = new FlowLayoutWidget(FlowDirection.TopToBottom);

				topToBottomTotal.SuspendLayout();
				GuiWidget.DefaultEnforceIntegerBounds = true;
				AddInfoRecursive(topLevelWindow, topToBottomTotal);
				GuiWidget.DefaultEnforceIntegerBounds = false;
				topToBottomTotal.ResumeLayout();
				topToBottomTotal.PerformLayout();
				allContainer.AddChild(topToBottomTotal);

				AddChild(allContainer);
				allContainer.AnchorAll();
			}
		}
        protected void DoWrappingLayout()
        {
            if (doingLayout)
            {
                needAnotherLayout = true;
                return;
            }

            using (this.LayoutLock())
            {
                doingLayout = true;
                // remove all the children we added
                foreach (var child in addedChildren)
                {
                    if (child.Parent != null)
                    {
                        using (child.Parent.LayoutLock())
                        {
                            child.Parent.RemoveChild(child);
                            child.ClearRemovedFlag();
                        }
                    }
                }

                // close all the row containers
                this.CloseChildren();

                // add in new row container
                FlowLayoutWidget childContainerRow = new FlowLayoutWidget()
                {
                    Margin  = RowMargin,
                    Padding = RowPadding,
                    HAnchor = HAnchor.Stretch,
                };
                base.AddChild(childContainerRow);
                var rowPaddingWidth = RowPadding.Width + RowMargin.Width + this.Margin.Width + this.Padding.Width;

                double runningSize = 0;
                MaxLineWidth = 0;
                foreach (var child in addedChildren)
                {
                    var childWidth = child.Width + child.DeviceMarginAndBorder.Width;
                    if (child.HAnchor == HAnchor.Stretch)
                    {
                        childWidth = child.MinimumSize.X + child.DeviceMarginAndBorder.Width;
                    }

                    if (runningSize + childWidth > this.Width - rowPaddingWidth ||
                        child is IHardBreak)
                    {
                        MaxLineWidth = Math.Max(MaxLineWidth, runningSize);
                        runningSize  = 0;
                        var lastItemWasHorizontalSpacer = false;
                        if (childContainerRow != null)
                        {
                            childContainerRow.PerformLayout();
                            if (childContainerRow.Children.LastOrDefault() is HorizontalSpacer)
                            {
                                lastItemWasHorizontalSpacer = true;
                            }
                        }

                        childContainerRow = new FlowLayoutWidget()
                        {
                            Margin      = RowMargin,
                            Padding     = RowPadding,
                            HAnchor     = HAnchor.Stretch,
                            Border      = RowBoarder,
                            BorderColor = RowBoarderColor,
                        };

                        if (lastItemWasHorizontalSpacer)
                        {
                            childContainerRow.AddChild(new HorizontalSpacer());
                        }

                        base.AddChild(childContainerRow);
                    }

                    if (runningSize > 0 ||
                        !(child is ISkipIfFirst))
                    {
                        // add the new child to the current row
                        using (childContainerRow.LayoutLock())
                        {
                            childContainerRow.AddChild(child);
                        }

                        runningSize += childWidth;
                        MaxLineWidth = Math.Max(MaxLineWidth, runningSize);
                    }
                }

                if (childContainerRow != null)
                {
                    childContainerRow.PerformLayout();
                }

                MakeProportionalIfRequired();
                MakeCenterIfRequired();

                doingLayout = false;
            }

            if (needAnotherLayout)
            {
                UiThread.RunOnIdle(DoWrappingLayout);
                needAnotherLayout = false;
            }

            // change the size to force a recursive layout event
            this.Height--;
            this.Height++;
            this.PerformLayout();
        }