コード例 #1
0
 public static Rectangle AlignAndStretch(
     Size fitThis,
     Rectangle withinThis,
     AnchorStyles anchorStyles)
 {
     return(LayoutUtils.Align(LayoutUtils.Stretch(fitThis, withinThis.Size, anchorStyles), withinThis, anchorStyles));
 }
コード例 #2
0
        public virtual Point TransformByAlignment(Size size, Rectangle withinBounds)
        {
            if (this.element.Alignment == ContentAlignment.TopLeft)
            {
                return(withinBounds.Location);
            }

            Rectangle alignedRectangle = LayoutUtils.Align(size, withinBounds, this.element.Alignment);

            // TODO: Test alignment!

            /*
             * if (alignedRectangle.Location.X < 0)
             *      alignedRectangle.Location = new Point(0, alignedRectangle.Location.Y);
             * if (alignedRectangle.Location.Y < 0)
             *      alignedRectangle.Location = new Point(alignedRectangle.Location.X, 0);
             */

            return(alignedRectangle.Location);
        }
コード例 #3
0
ファイル: StackLayoutPanel.cs プロジェクト: configare/hispeed
        /// <summary>
        /// ArrangeOverride
        /// </summary>
        /// <param name="arrangeSize"></param>
        /// <returns></returns>
        protected override SizeF ArrangeOverride(SizeF arrangeSize)
        {
            RadElementCollection children = this.Children;
            int count = children.Count;

            // Get desired children size if EqualChildrenHeight or EqualChildrenWidth is used
            // ********************************************************* //
            SizeF maxDesiredChildrenSize = SizeF.Empty;
            bool  equalChildrenHeight    = this.EqualChildrenHeight;
            bool  equalChildrenWidth     = this.EqualChildrenWidth;

            if (equalChildrenHeight || equalChildrenWidth)
            {
                for (int i = 0; i < count; i++)
                {
                    RadElement element = children[i];
                    if (equalChildrenHeight)
                    {
                        maxDesiredChildrenSize.Height = Math.Max(element.DesiredSize.Height, maxDesiredChildrenSize.Height);
                    }
                    if (equalChildrenWidth)
                    {
                        maxDesiredChildrenSize.Width = Math.Max(element.DesiredSize.Width, maxDesiredChildrenSize.Width);
                    }
                }
            }

            // Parameters
            // ********************************************************* //
            bool isHorizontal  = this.Orientation == Orientation.Horizontal;
            bool isRightToLeft = this.RightToLeft;

            float      length    = 0;
            RectangleF finalRect = new RectangleF(PointF.Empty, arrangeSize);

            if (isHorizontal && isRightToLeft)
            {
                finalRect.X = arrangeSize.Width;
            }

            // Main loop that does the actual arrangement of the children
            // ********************************************************* //
            for (int i = 0; i < count; i++)
            {
                RadElement element = children[i];

                SizeF childArea = element.DesiredSize;
                if (element.Visibility == ElementVisibility.Collapsed)
                {
                    element.Arrange(new RectangleF(PointF.Empty, childArea));
                    continue;
                }

                // ** 1. Calculate the ChildArea
                if (equalChildrenHeight)
                {
                    if (isHorizontal)
                    {
                        childArea.Height = Math.Max(arrangeSize.Height, maxDesiredChildrenSize.Height);
                    }
                    else
                    {
                        childArea.Height = maxDesiredChildrenSize.Height;
                    }
                }
                if (equalChildrenWidth)
                {
                    if (isHorizontal)
                    {
                        childArea.Width = maxDesiredChildrenSize.Width;
                    }
                    else
                    {
                        childArea.Width = Math.Max(arrangeSize.Width, maxDesiredChildrenSize.Width);
                    }
                }

                // ** 2. Calculate the location and size (finalRect) that will be passed to the child's Arrange
                if (isHorizontal)
                {
                    if (isRightToLeft)
                    {
                        length       = childArea.Width;
                        finalRect.X -= length;
                    }
                    else
                    {
                        finalRect.X += length;
                        length       = childArea.Width;
                    }

                    finalRect.Width = length;
                    if (equalChildrenHeight)
                    {
                        SizeF arrangeArea = finalRect.Size;
                        finalRect.Height = childArea.Height;

                        // Compensate the alignment for EqualChildrenHeight because the basic logic will be bypassed
                        // by the size forcing
                        // Note that the vertical alignment is not affected by RightToLeft...
                        RectangleF alignedRect = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, arrangeArea), this.Alignment);
                        finalRect.Y += alignedRect.Y;
                    }
                    else
                    {
                        finalRect.Height = arrangeSize.Height;// Math.Max(arrangeSize.Height, childArea.Height);
                    }
                }
                else
                {
                    finalRect.Y     += length;
                    length           = childArea.Height;
                    finalRect.Height = length;
                    if (equalChildrenWidth)
                    {
                        SizeF arrangeArea = finalRect.Size;
                        finalRect.Width = childArea.Width;

                        // Compensate the alignment for EqualChildrenHeight because the basic logic will be bypassed
                        // by the size forcing
                        // Note that the horizontal alignment is translated if RightToLeft is true.
                        ContentAlignment alignment   = isRightToLeft ? TelerikAlignHelper.RtlTranslateContent(this.Alignment) : this.Alignment;
                        RectangleF       alignedRect = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, arrangeArea), alignment);
                        finalRect.X += alignedRect.X;
                    }
                    else
                    {
                        finalRect.Width = arrangeSize.Width;// Math.Max(arrangeSize.Width, childArea.Width);
                    }
                }

                // ** 3. Arrange the child
                element.Arrange(finalRect);
            }

            return(arrangeSize);
        }
コード例 #4
0
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            RectangleF        clientRectangle   = this.GetClientRectangle(finalSize);
            RectangleF        empty1            = RectangleF.Empty;
            RectangleF        region2           = RectangleF.Empty;
            SizeF             empty2            = SizeF.Empty;
            SizeF             empty3            = SizeF.Empty;
            ContentAlignment  contentAlignment1 = this.ImageAlignment;
            ContentAlignment  contentAlignment2 = this.TextAlignment;
            TextImageRelation relation          = this.TextImageRelation;

            if (this.RightToLeft)
            {
                contentAlignment1 = TelerikAlignHelper.RtlTranslateContent(contentAlignment1);
                contentAlignment2 = TelerikAlignHelper.RtlTranslateContent(contentAlignment2);
                relation          = TelerikAlignHelper.RtlTranslateRelation(relation);
            }
            bool flag1 = this.IsPrimitiveNullOrEmpty(this.imageElement);
            bool flag2 = this.IsPrimitiveNullOrEmpty(this.textElement);

            if (this.imageElement != null && (this.DisplayStyle == DisplayStyle.Image || flag2))
            {
                this.imageElement.Arrange(clientRectangle);
                return(finalSize);
            }
            if (this.textElement != null && this.DisplayStyle == DisplayStyle.Text && flag1)
            {
                this.textElement.Arrange(clientRectangle);
                return(finalSize);
            }
            SizeF sizeF1 = SizeF.Empty;
            SizeF sizeF2 = SizeF.Empty;

            if (this.imageElement != null)
            {
                sizeF1 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.imageElement.DesiredSize), this.imageElement.Margin);
            }
            if (this.textElement != null)
            {
                sizeF2 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.textElement.DesiredSize), this.textElement.Margin);
            }
            LayoutUtils.SubAlignedRegion(finalSize, sizeF1, relation);
            SizeF      sizeF3 = LayoutUtils.AddAlignedRegion(sizeF2, sizeF1, relation);
            RectangleF empty4 = (RectangleF)Rectangle.Empty;

            empty4.Size = LayoutUtils.UnionSizes(finalSize, sizeF3);
            empty4.X   += clientRectangle.X;
            empty4.Y   += clientRectangle.Y;
            bool flag3 = (TelerikAlignHelper.ImageAlignToRelation(contentAlignment1) & relation) != TextImageRelation.Overlay;
            bool flag4 = (TelerikAlignHelper.TextAlignToRelation(contentAlignment2) & relation) != TextImageRelation.Overlay;

            if (flag3)
            {
                LayoutUtils.SplitRegion(empty4, sizeF1, (AnchorStyles)relation, out empty1, out region2);
            }
            else if (flag4)
            {
                LayoutUtils.SplitRegion(empty4, sizeF2, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(relation), out region2, out empty1);
            }
            else if (relation == TextImageRelation.Overlay)
            {
                LayoutUtils.SplitRegion(empty4, sizeF1, (AnchorStyles)relation, out empty1, out region2);
            }
            else
            {
                LayoutUtils.SplitRegion(LayoutUtils.Align(sizeF3, empty4, ContentAlignment.MiddleCenter), sizeF1, (AnchorStyles)relation, out empty1, out region2);
                LayoutUtils.ExpandRegionsToFillBounds(empty4, (AnchorStyles)relation, ref empty1, ref region2);
            }
            if (relation == TextImageRelation.TextBeforeImage || relation == TextImageRelation.ImageBeforeText)
            {
                float num = Math.Min(region2.Bottom, clientRectangle.Bottom);
                region2.Y      = Math.Max(Math.Min(region2.Y, clientRectangle.Y + (float)(((double)clientRectangle.Height - (double)region2.Height) / 2.0)), clientRectangle.Y);
                region2.Height = num - region2.Y;
            }
            if (relation == TextImageRelation.TextAboveImage || relation == TextImageRelation.ImageAboveText)
            {
                float num = Math.Min(region2.Right, clientRectangle.Right);
                region2.X     = Math.Max(Math.Min(region2.X, clientRectangle.X + (float)(((double)clientRectangle.Width - (double)region2.Width) / 2.0)), clientRectangle.X);
                region2.Width = num - region2.X;
            }
            if (relation == TextImageRelation.ImageBeforeText && (double)empty1.Size.Width != 0.0)
            {
                empty1.Width = Math.Max(0.0f, Math.Min(finalSize.Width - region2.Width, empty1.Width));
                region2.X    = empty1.X + empty1.Width;
            }
            if (relation == TextImageRelation.ImageAboveText && (double)empty1.Size.Height != 0.0)
            {
                empty1.Height = Math.Max(0.0f, Math.Min(finalSize.Height - region2.Height, empty1.Height));
                region2.Y     = empty1.Y + empty1.Height;
            }
            region2 = RectangleF.Intersect(region2, clientRectangle);
            RectangleF rectangleF = LayoutUtils.Align(sizeF1, empty1, contentAlignment1);

            if ((double)rectangleF.Width > (double)empty1.Width)
            {
                rectangleF.X = empty1.Width - sizeF1.Width;
            }
            if ((double)rectangleF.Height > (double)empty1.Height)
            {
                rectangleF.Y = empty1.Height - sizeF1.Height;
            }
            region2 = LayoutUtils.Align(sizeF2, region2, contentAlignment2);
            if (this.imageElement != null)
            {
                region2.Size = SizeF.Subtract(region2.Size, (SizeF)this.imageElement.Margin.Size);
                this.imageElement.Arrange(empty1);
            }
            if (this.textElement != null)
            {
                empty1.Size = SizeF.Subtract(empty1.Size, (SizeF)this.textElement.Margin.Size);
                this.textElement.Arrange(region2);
            }
            return(finalSize);
        }
コード例 #5
0
        protected override SizeF ArrangeOverride(SizeF arrangeSize)
        {
            RadElementCollection children = this.Children;
            int   count = children.Count;
            SizeF empty = SizeF.Empty;
            bool  equalChildrenHeight = this.EqualChildrenHeight;
            bool  equalChildrenWidth  = this.EqualChildrenWidth;

            if (equalChildrenHeight || equalChildrenWidth)
            {
                for (int index = 0; index < count; ++index)
                {
                    RadElement radElement = children[index];
                    if (equalChildrenHeight)
                    {
                        empty.Height = Math.Max(radElement.DesiredSize.Height, empty.Height);
                    }
                    if (equalChildrenWidth)
                    {
                        empty.Width = Math.Max(radElement.DesiredSize.Width, empty.Width);
                    }
                }
            }
            bool       flag        = this.Orientation == Orientation.Horizontal;
            bool       rightToLeft = this.RightToLeft;
            float      num         = 0.0f;
            RectangleF finalRect   = new RectangleF(PointF.Empty, arrangeSize);

            if (flag && rightToLeft)
            {
                finalRect.X = arrangeSize.Width;
            }
            for (int index = 0; index < count; ++index)
            {
                RadElement radElement  = children[index];
                SizeF      desiredSize = radElement.DesiredSize;
                if (radElement.Visibility == ElementVisibility.Collapsed)
                {
                    radElement.Arrange(new RectangleF(PointF.Empty, desiredSize));
                }
                else
                {
                    if (equalChildrenHeight)
                    {
                        desiredSize.Height = !flag ? empty.Height : Math.Max(arrangeSize.Height, empty.Height);
                    }
                    if (equalChildrenWidth)
                    {
                        desiredSize.Width = !flag?Math.Max(arrangeSize.Width, empty.Width) : empty.Width;
                    }
                    if (flag)
                    {
                        if (rightToLeft)
                        {
                            num          = desiredSize.Width;
                            finalRect.X -= num;
                        }
                        else
                        {
                            finalRect.X += num;
                            num          = desiredSize.Width;
                        }
                        finalRect.Width = num;
                        if (equalChildrenHeight)
                        {
                            SizeF size = finalRect.Size;
                            finalRect.Height = desiredSize.Height;
                            RectangleF rectangleF = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, size), this.Alignment);
                            finalRect.Y += rectangleF.Y;
                        }
                        else
                        {
                            finalRect.Height = arrangeSize.Height;
                        }
                    }
                    else
                    {
                        finalRect.Y     += num;
                        num              = desiredSize.Height;
                        finalRect.Height = num;
                        if (equalChildrenWidth)
                        {
                            SizeF size = finalRect.Size;
                            finalRect.Width = desiredSize.Width;
                            ContentAlignment align      = rightToLeft ? TelerikAlignHelper.RtlTranslateContent(this.Alignment) : this.Alignment;
                            RectangleF       rectangleF = LayoutUtils.Align(finalRect.Size, new RectangleF(PointF.Empty, size), align);
                            finalRect.X += rectangleF.X;
                        }
                        else
                        {
                            finalRect.Width = arrangeSize.Width;
                        }
                    }
                    radElement.Arrange(finalRect);
                }
            }
            return(arrangeSize);
        }
コード例 #6
0
        protected override SizeF ArrangeOverride(SizeF finalSize)
        {
            SizeF      fieldSize   = finalSize;
            RectangleF layoutField = new RectangleF(PointF.Empty, finalSize);

            RectangleF imageBounds = RectangleF.Empty;
            RectangleF textBounds  = RectangleF.Empty;
            SizeF      textSize    = SizeF.Empty;
            SizeF      imageSize   = SizeF.Empty;

            ContentAlignment  imageAlign        = this.ImageAlignment;
            ContentAlignment  textAlign         = this.TextAlignment;
            TextImageRelation textImageRelation = this.TextImageRelation;

            if (this.RightToLeft)
            {
                imageAlign        = TelerikAlignHelper.RtlTranslateContent(ImageAlignment);
                textAlign         = TelerikAlignHelper.RtlTranslateContent(TextAlignment);
                textImageRelation = TelerikAlignHelper.RtlTranslateRelation(TextImageRelation);
            }

            if ((this.textElement != null) && IsPrimitiveNullOrEmpty(this.imageElement))
            {
                this.textElement.Arrange(layoutField);
                if (this.imageElement != null)
                {
                    this.imageElement.Arrange(layoutField);
                }
                return(finalSize);
            }
            if ((this.imageElement != null) && IsPrimitiveNullOrEmpty(this.textElement))
            {
                this.imageElement.Arrange(layoutField);
                if (this.textElement != null)
                {
                    this.textElement.Arrange(layoutField);
                }
                return(finalSize);
            }

            textSize  = this.GetInvariantLength(textElement.DesiredSize, textElement.Margin);
            imageSize = this.GetInvariantLength(imageElement.DesiredSize, imageElement.Margin);

            // Subtract the image size from the whole field size
            SizeF textSizeLeft = LayoutUtils.SubAlignedRegion(fieldSize, imageSize, textImageRelation);
            // Create a new size based on the text size and the image size
            SizeF newSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation);
            // The new field which is a union of the new sizes
            RectangleF maxFieldRectangle = RectangleF.Empty;

            maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize);
            // Image doesn't overlay text
            bool imageAlignNoOverlay = (TelerikAlignHelper.ImageAlignToRelation(imageAlign) & textImageRelation) !=
                                       TextImageRelation.Overlay;
            // Text doesn't overlay image
            bool textAlignNoOverlay = (TelerikAlignHelper.TextAlignToRelation(textAlign) & textImageRelation) !=
                                      TextImageRelation.Overlay;

            if (imageAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
            }
            else if (textAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, textSize, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out textBounds, out imageBounds);
            }
            else
            {
                // Both image overlays text and text overlays image
                if (textImageRelation == TextImageRelation.Overlay)
                {
                    LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                }
                else
                {
                    RectangleF alignedField = LayoutUtils.Align(newSize, maxFieldRectangle, ContentAlignment.MiddleCenter);
                    LayoutUtils.SplitRegion(alignedField, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                    LayoutUtils.ExpandRegionsToFillBounds(maxFieldRectangle, (AnchorStyles)textImageRelation, ref imageBounds, ref textBounds);
                }
            }


            textBounds.Size  = SizeF.Subtract(textBounds.Size, this.textElement.Margin.Size);
            imageBounds.Size = SizeF.Subtract(imageBounds.Size, this.imageElement.Margin.Size);

            this.textElement.Arrange(textBounds);
            this.imageElement.Arrange(imageBounds);

            return(finalSize);
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fieldSize"></param>
        /// <param name="layoutField"></param>
        /// <param name="newLayouts"></param>
        public void LayoutTextAndImage(Size fieldSize, Rectangle layoutField, bool newLayouts)
        {
            Rectangle imageBounds = Rectangle.Empty;
            Rectangle textBounds  = Rectangle.Empty;
            Size      textSize    = Size.Empty;
            Size      imageSize   = Size.Empty;

            ContentAlignment  imageAlign        = ImageAlignment;
            ContentAlignment  textAlign         = TextAlignment;
            TextImageRelation textImageRelation = TextImageRelation;

            //DK_2006_07_28
            if (!newLayouts)
            {
                List <PreferredSizeData> prefSizelist = new List <PreferredSizeData>();
                FillList(prefSizelist, fieldSize);
            }

            if (this.RightToLeft)
            {
                imageAlign        = TelerikAlignHelper.RtlTranslateContent(ImageAlignment);
                textAlign         = TelerikAlignHelper.RtlTranslateContent(TextAlignment);
                textImageRelation = TelerikAlignHelper.RtlTranslateRelation(TextImageRelation);
            }

            if (textElement != null)
            {
                textSize = newLayouts ? Size.Ceiling(textElement.DesiredSize) : Size.Ceiling(textElement.GetPreferredSize(fieldSize));
                textSize = this.GetInvariantLength(textSize, textElement.Margin);
            }
            if (imageElement != null)
            {
                imageSize = newLayouts ? Size.Ceiling(imageElement.DesiredSize) : Size.Ceiling(imageElement.GetPreferredSize(fieldSize));
                imageSize = this.GetInvariantLength(imageSize, imageElement.Margin);
            }

            if ((textElement != null) && IsPrimitiveNullOrEmpty(this.imageElement))
            {
                Rectangle bounds = LayoutUtils.Align(textSize, new Rectangle(Point.Empty, fieldSize), textAlign);
                bounds.Size = Size.Subtract(textSize, textElement.Margin.Size);
                if (newLayouts)
                {
                    textElement.Arrange(bounds);
                }
                else
                {
                    textElement.Bounds = bounds;
                }
                return;
            }
            if ((imageElement != null) && IsPrimitiveNullOrEmpty(this.textElement))
            {
                Rectangle bounds = LayoutUtils.Align(imageSize, new Rectangle(Point.Empty, fieldSize), imageAlign);
                bounds.Size = Size.Subtract(imageSize, imageElement.Margin.Size);
                if (newLayouts)
                {
                    imageElement.Arrange(bounds);
                }
                else
                {
                    imageElement.Bounds = bounds;
                }
                return;
            }
            // Subtract the image size from the whole field size
            Size textSizeLeft = LayoutUtils.SubAlignedRegion(fieldSize, imageSize, textImageRelation);

            textSize = newLayouts ? Size.Ceiling(this.textElement.DesiredSize) : Size.Ceiling(this.textElement.GetPreferredSize(textSizeLeft));
            textSize = this.GetInvariantLength(textSize, textElement.Margin);

            // Create a new size based on the text size and the image size
            Size newSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation);
            // The new field which is a union of the new sizes
            Rectangle maxFieldRectangle = Rectangle.Empty;

            maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize);
            // Image doesn't overlay text
            bool imageAlignNoOverlay = (TelerikAlignHelper.ImageAlignToRelation(imageAlign) & textImageRelation) !=
                                       TextImageRelation.Overlay;
            // Text doesn't overlay image
            bool textAlignNoOverlay = (TelerikAlignHelper.TextAlignToRelation(textAlign) & textImageRelation) !=
                                      TextImageRelation.Overlay;

            if (imageAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
            }
            else if (textAlignNoOverlay)
            {
                LayoutUtils.SplitRegion(maxFieldRectangle, textSize, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out textBounds, out imageBounds);
            }
            else
            {
                // Both image overlays text and text overlays image
                if (textImageRelation == TextImageRelation.Overlay)
                {
                    LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                }
                else
                {
                    Rectangle alignedField = LayoutUtils.Align(newSize, maxFieldRectangle, ContentAlignment.MiddleCenter);
                    LayoutUtils.SplitRegion(alignedField, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds);
                    LayoutUtils.ExpandRegionsToFillBounds(maxFieldRectangle, (AnchorStyles)textImageRelation, ref imageBounds, ref textBounds);
                }
            }
            //set image and text bounds according the size of the field
            if ((textImageRelation == TextImageRelation.TextBeforeImage) || (textImageRelation == TextImageRelation.ImageBeforeText))
            {
                int num1 = Math.Min(textBounds.Bottom, layoutField.Bottom);
                textBounds.Y      = Math.Max(Math.Min(textBounds.Y, layoutField.Y + ((layoutField.Height - textBounds.Height) / 2)), layoutField.Y);
                textBounds.Height = num1 - textBounds.Y;
            }
            if ((textImageRelation == TextImageRelation.TextAboveImage) || (textImageRelation == TextImageRelation.ImageAboveText))
            {
                int num2 = Math.Min(textBounds.Right, layoutField.Right);
                textBounds.X     = Math.Max(Math.Min(textBounds.X, layoutField.X + ((layoutField.Width - textBounds.Width) / 2)), layoutField.X);
                textBounds.Width = num2 - textBounds.X;
            }
            if ((textImageRelation == TextImageRelation.ImageBeforeText) && (imageBounds.Size.Width != 0))
            {
                imageBounds.Width = Math.Max(0, Math.Min(fieldSize.Width - textBounds.Width, imageBounds.Width));
                textBounds.X      = imageBounds.X + imageBounds.Width;
            }
            if ((textImageRelation == TextImageRelation.ImageAboveText) && (imageBounds.Size.Height != 0))
            {
                imageBounds.Height = Math.Max(0, Math.Min(fieldSize.Height - textBounds.Height, imageBounds.Height));
                textBounds.Y       = imageBounds.Y + imageBounds.Height;
            }
            textBounds = Rectangle.Intersect(textBounds, layoutField);

            //align image and if its size is greater than the field's size it is become offseted as much as the difference
            Rectangle newImageBounds = LayoutUtils.Align(imageSize, imageBounds, imageAlign);

            if (newImageBounds.Width > imageBounds.Width)
            {
                newImageBounds.X = imageBounds.Width - imageSize.Width;
            }
            if (newImageBounds.Height > imageBounds.Height)
            {
                newImageBounds.Y = imageBounds.Height - imageSize.Height;
            }

            textBounds = LayoutUtils.Align(textSize, textBounds, textAlign);

            textBounds.Size  = Size.Subtract(textBounds.Size, this.textElement.Margin.Size);
            imageBounds.Size = Size.Subtract(newImageBounds.Size, this.imageElement.Margin.Size);

            if (newLayouts)
            {
                this.textElement.Arrange(textBounds);
                this.imageElement.Arrange(newImageBounds);
            }
            else
            {
                this.textElement.Bounds  = textBounds;
                this.imageElement.Bounds = newImageBounds;
            }
        }