Пример #1
0
        public override SizeF Arrange(RectangleF bounds)
        {
            SizeF size = bounds.Size;

            if (this.lastFinalSize != size || this.isDirty)
            {
                this.lastFinalSize = size;
                this.Measure(size);
            }
            SizeF             sizeF1           = size;
            RectangleF        rectangleF1      = new RectangleF(bounds.Location, size);
            RectangleF        empty1           = RectangleF.Empty;
            RectangleF        region2          = RectangleF.Empty;
            SizeF             empty2           = SizeF.Empty;
            SizeF             empty3           = SizeF.Empty;
            ContentAlignment  contentAlignment = this.Owner.ImageAlignment;
            TextImageRelation relation         = this.Owner.TextImageRelation;

            if (this.Owner.RightToLeft)
            {
                contentAlignment = TelerikAlignHelper.RtlTranslateContent(contentAlignment);
                relation         = TelerikAlignHelper.RtlTranslateRelation(relation);
            }
            if (this.left != null && this.Owner.Image == null)
            {
                this.left.Arrange(rectangleF1);
                if (this.right != null)
                {
                    this.right.Arrange(rectangleF1);
                }
                return(size);
            }
            if (this.right != null && (string.IsNullOrEmpty(this.Owner.Text) || !this.Owner.DrawText))
            {
                this.right.Arrange(rectangleF1);
                if (this.left != null)
                {
                    this.left.Arrange(rectangleF1);
                }
                return(size);
            }
            SizeF invariantLength1 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.left.DesiredSize), this.left.Margin);
            SizeF invariantLength2 = (SizeF)this.GetInvariantLength(Size.Ceiling(this.right.DesiredSize), this.right.Margin);

            LayoutUtils.SubAlignedRegion(sizeF1, invariantLength1, relation);
            SizeF      sizeF2 = LayoutUtils.AddAlignedRegion(invariantLength2, invariantLength1, relation);
            RectangleF empty4 = (RectangleF)Rectangle.Empty;

            empty4.Size = LayoutUtils.UnionSizes(sizeF1, sizeF2);
            empty4.X   += rectangleF1.X;
            empty4.Y   += rectangleF1.Y;
            bool flag1 = (TelerikAlignHelper.ImageAlignToRelation(contentAlignment) & relation) != TextImageRelation.Overlay;
            bool flag2 = (TelerikAlignHelper.TextAlignToRelation(this.Owner.TextAlignment) & relation) != TextImageRelation.Overlay;

            if (flag1)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength1, (AnchorStyles)relation, out empty1, out region2);
            }
            else if (flag2)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength2, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(relation), out region2, out empty1);
            }
            else if (relation == TextImageRelation.Overlay)
            {
                LayoutUtils.SplitRegion(empty4, invariantLength1, (AnchorStyles)relation, out empty1, out region2);
            }
            else
            {
                LayoutUtils.SplitRegion(LayoutUtils.Align(sizeF2, empty4, ContentAlignment.MiddleCenter), invariantLength1, (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, rectangleF1.Bottom);
                region2.Y      = Math.Max(Math.Min(region2.Y, rectangleF1.Y + (float)(((double)rectangleF1.Height - (double)region2.Height) / 2.0)), rectangleF1.Y);
                region2.Height = num - region2.Y;
            }
            if (relation == TextImageRelation.TextAboveImage || relation == TextImageRelation.ImageAboveText)
            {
                float num = Math.Min(region2.Right, rectangleF1.Right);
                region2.X     = Math.Max(Math.Min(region2.X, rectangleF1.X + (float)(((double)rectangleF1.Width - (double)region2.Width) / 2.0)), rectangleF1.X);
                region2.Width = num - region2.X;
            }
            if (relation == TextImageRelation.ImageBeforeText && (double)empty1.Size.Width != 0.0)
            {
                empty1.Width = Math.Max(0.0f, Math.Min(sizeF1.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(sizeF1.Height - region2.Height, empty1.Height));
                region2.Y     = empty1.Y + empty1.Height;
            }
            region2 = RectangleF.Intersect(region2, rectangleF1);
            RectangleF rectangleF2 = LayoutUtils.Align(invariantLength1, empty1, contentAlignment);

            if ((double)rectangleF2.Width > (double)empty1.Width)
            {
                rectangleF2.X = empty1.Width - invariantLength1.Width;
            }
            if ((double)rectangleF2.Height > (double)empty1.Height)
            {
                rectangleF2.Y = empty1.Height - invariantLength1.Height;
            }
            region2.Size = SizeF.Subtract(region2.Size, (SizeF)this.left.Margin.Size);
            empty1.Size  = SizeF.Subtract(empty1.Size, (SizeF)this.right.Margin.Size);
            this.left.Arrange(empty1);
            this.right.Arrange(region2);
            return(size);
        }
Пример #2
0
        public override SizeF Arrange(RectangleF bounds)
        {
            SizeF finalSize = bounds.Size;

            if (this.lastFinalSize != finalSize || this.isDirty)
            {
                this.lastFinalSize = finalSize;
                this.Measure(finalSize);
            }

            SizeF      fieldSize   = finalSize;
            RectangleF layoutField = new RectangleF(bounds.Location, finalSize);

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

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

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

            if ((this.left != null) && (this.owner.Image == null))
            {
                this.left.Arrange(layoutField);
                if (this.right != null)
                {
                    this.right.Arrange(layoutField);
                }
                return(finalSize);
            }
            if (this.right != null && (string.IsNullOrEmpty(this.owner.Text) || !this.owner.DrawText))
            {
                this.right.Arrange(layoutField);
                if (this.left != null)
                {
                    this.left.Arrange(layoutField);
                }
                return(finalSize);
            }

            imageSize = this.GetInvariantLength(Size.Ceiling(this.left.DesiredSize), this.left.Margin);
            textSize  = this.GetInvariantLength(Size.Ceiling(this.right.DesiredSize), this.right.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 = Rectangle.Empty;

            maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize);
            maxFieldRectangle.X   += layoutField.X;
            maxFieldRectangle.Y   += layoutField.Y;
            // 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);
                }
            }
            ///////////////////////////////////////////////////////////////////////////

            //set image and text bounds according the size of the field
            if ((textImageRelation == TextImageRelation.TextBeforeImage) || (textImageRelation == TextImageRelation.ImageBeforeText))
            {
                float 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))
            {
                float 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 = RectangleF.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
            RectangleF 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.Offset(layoutField.Location);
            //imageBounds.Offset(layoutField.Location);

            /////////////////////////////////////////////////////////////////////////
            textBounds.Size  = SizeF.Subtract(textBounds.Size, this.left.Margin.Size);
            imageBounds.Size = SizeF.Subtract(imageBounds.Size, this.right.Margin.Size);

            this.left.Arrange(imageBounds);
            this.right.Arrange(textBounds);

            return(finalSize);
        }