/// <summary>Clamps the specified point to be contained within the box.</summary> /// <param name="target">The target point.</param> /// <param name="clamped">The clamped point.</param> public void Clamp(ref Vector2 target, out Vector2 clamped) { Vector2Helper.Clamp(ref target, ref Min, ref Max, out clamped); }
public void Update(LayoutHints hints, bool useLayoutInfo, float backgroundDepth) { UseLayoutInfo = useLayoutInfo; // Calculate main dimensions Depth = hints.Depth; if (useLayoutInfo) { Position = _layoutPosition; Size = _layoutSize; DepthOffset = _layoutDepthOffset; } else { Position = Vector3.Zero; Size = DualityApp.WindowSize; DepthOffset = Depth - 1; } // Calculate background area dimensions // The background is inset by the Margins hint into the main element area. // Its DepthOffset is the same as that of the element - it lies behind the content BackgroundDepth = backgroundDepth; BackgroundDepthOffset = DepthOffset; var backgroundPosition = Position; var backgroundSize = Size; if (hints.BackgroundSize.UseX) { backgroundSize.X = hints.BackgroundSize.Value.X; } if (hints.BackgroundSize.UseY) { backgroundSize.Y = hints.BackgroundSize.Value.Y; } // Margins have already been checked for negatives in LayoutHints.Update() backgroundPosition.Xy += hints.Margin.BottomLeft; backgroundPosition.Xy = Vector2.Min(backgroundPosition.Xy, Position.Xy + Size); var maxBackgroundSize = Size - (backgroundPosition.Xy - Position.Xy); maxBackgroundSize -= hints.Margin.TopRight; backgroundSize = Vector2Helper.Clamp(backgroundSize, Vector2.Zero, maxBackgroundSize); BackgroundPosition = backgroundPosition; BackgroundSize = backgroundSize; // Calculate content dimensions ContentDepth = hints.ContentHints.Depth; ContentDepthOffset = BackgroundDepthOffset - BackgroundDepth; var maxSize = hints.ContentHints.MaxSize; var minSize = hints.ContentHints.MinSize; maxSize = Vector2.Max(Vector2.Zero, maxSize); if (!hints.ContentHints.Stretch) { var prefSize = hints.ContentHints.PreferredSize; prefSize = Vector2.Max(prefSize, Vector2.Zero); maxSize = Vector2.Min(prefSize, maxSize); } minSize = Vector2Helper.Clamp(minSize, Vector2.Zero, maxSize); var contentSize = BackgroundSize - hints.Padding.TotalSize; contentSize = Vector2Helper.Clamp(contentSize, minSize, maxSize); ContentSize = contentSize; // Calculate content area dimensions Vector3 contentAreaPosition = BackgroundPosition + new Vector3(hints.Padding.BottomLeft); Vector2 contentAreaSize = BackgroundSize - hints.Padding.TotalSize; // Align content within contentArea var alignment = hints.ContentHints.Alignment; var alignmentOffset = alignment.ApplyTo(Vector2.Zero, ContentSize) - alignment.ApplyTo(Vector2.Zero, contentAreaSize); ContentPosition = contentAreaPosition + new Vector3(alignmentOffset); }