Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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;
            }
        }