示例#1
0
        private void FixOriginXIfRightToLeft(GuiWidget parent)
        {
            if (parent.HAnchorIsSet(HAnchor.FitToChildren) && FlowDirection == UI.FlowDirection.RightToLeft)
            {
                RectangleDouble encloseChildrenRect = parent.GetMinimumBoundsToEncloseChildren();

                for (int childIndex = 0; childIndex < parent.Children.Count; childIndex++)
                {
                    GuiWidget child = parent.Children[childIndex];
                    if (child.Visible == false)
                    {
                        continue;
                    }

                    child.OriginRelativeParent = new Vector2(child.OriginRelativeParent.x - encloseChildrenRect.Left, child.OriginRelativeParent.y);
                }
            }
        }
		public void DoFitToChildrenHorizontal(GuiWidget widgetToAdjust, ref bool sizeWasChanged)
		{
			if (widgetToAdjust.HAnchorIsSet(HAnchor.FitToChildren))
			{
				double widthToMatchParent = 0;
				// let's check if the parent would like to make this widget bigger
				if (widgetToAdjust.Parent != null)
				{
					Vector2 newOriginRelParent;
					if (!GetOriginAndWidthForChild(widgetToAdjust.Parent, widgetToAdjust, out newOriginRelParent, out widthToMatchParent))
					{
						// we don't need to adjust anything for the parent so make sure this is not applied below.
						widthToMatchParent = 0;
					}
				}

				// get the bounds
				RectangleDouble widgetToAdjustBounds = widgetToAdjust.LocalBounds;
				// get the bounds to enclose its childern
				RectangleDouble childrenEnclosingBounds = widgetToAdjust.GetMinimumBoundsToEncloseChildren(true);
				// fix the h size to enclose the children
				widgetToAdjustBounds.Left = childrenEnclosingBounds.Left;
				if (widgetToAdjust.Parent != null
					&& widgetToAdjust.Parent.LayoutEngine != null)
				{
					if(widgetToAdjust.Parent.LayoutEngine as LayoutEngineFlow != null)
					{
						// The parent is a flow layout widget but it will only adjust our size if we are HAnchor leftright
						if (widgetToAdjust.HAnchorIsSet(HAnchor.ParentLeftRight))
						{
							// We make the assumption that the parent has set the size correctly assuming flow layout and this can only be made bigger if fit needs to.
							widgetToAdjustBounds.Right = Math.Max(widgetToAdjustBounds.Right, childrenEnclosingBounds.Right);
						}
						else // we need to just do the fit to children
						{
							widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right);
						}
					}
					else if ((widgetToAdjust.Parent.LayoutEngine as LayoutEngineSimpleAlign) != null)
					{
						widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right);
					}
					else
					{
							throw new NotImplementedException();
					}
				}
				else
				{
					widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right);
				}
				if (widgetToAdjust.LocalBounds != widgetToAdjustBounds)
				{
					if (widgetToAdjust.HAnchorIsSet(HAnchor.ParentLeftRight))
					{
						if (widgetToAdjust.LocalBounds.Width < widgetToAdjustBounds.Width)
						{
							widgetToAdjust.LocalBounds = widgetToAdjustBounds;
							sizeWasChanged = true;
						}
					}
					else
					{
						// push the new size in
						widgetToAdjust.LocalBounds = widgetToAdjustBounds;
						sizeWasChanged = true;
					}
				}
			}
		}
示例#3
0
 protected override void ApplyHAnchorToChild(GuiWidget parent, GuiWidget child)
 {
     if (FlowDirection == UI.FlowDirection.BottomToTop || FlowDirection == UI.FlowDirection.TopToBottom)
     {
         base.ApplyHAnchorToChild(parent, child);
     }
     else
     {
         if (child.HAnchor == HAnchor.ParentLeftRight || child.HAnchorIsSet(HAnchor.FitToChildren))
         {
         }
         else if (child.HAnchor != HAnchor.None)
         {
             throw new Exception("HAnchor for a left right flow widget needs to be none or ParentLeftRight.");
         }
     }
 }
        public void DoFitToChildrenHorizontal(GuiWidget widgetToAdjust, ref bool sizeWasChanged)
        {
            if (widgetToAdjust.HAnchorIsSet(HAnchor.FitToChildren))
            {
                double widthToMatchParent = 0;
                // let's check if the parent would like to make this widget bigger
                if (widgetToAdjust.Parent != null)
                {
                    Vector2 newOriginRelParent;
                    if (!GetOriginAndWidthForChild(widgetToAdjust.Parent, widgetToAdjust, out newOriginRelParent, out widthToMatchParent))
                    {
                        // we don't need to adjust anything for the parent so make sure this is not applied below.
                        widthToMatchParent = 0;
                    }
                }

                // get the bounds
                RectangleDouble widgetToAdjustBounds = widgetToAdjust.LocalBounds;
                // get the bounds to enclose its childern
                RectangleDouble childrenEnclosingBounds = widgetToAdjust.GetMinimumBoundsToEncloseChildren(true);
                // fix the h size to enclose the children
                widgetToAdjustBounds.Left = childrenEnclosingBounds.Left;
                widgetToAdjustBounds.Right = Math.Max(childrenEnclosingBounds.Left + widthToMatchParent, childrenEnclosingBounds.Right);
                if (widgetToAdjust.LocalBounds != widgetToAdjustBounds)
                {
                    // push the new size in
                    widgetToAdjust.LocalBounds = widgetToAdjustBounds;
                    sizeWasChanged = true;
                }
            }
        }