private void LayoutCheckmark(RectangleF fieldRectangle, bool newLayout) { float checkWidth = newLayout ? this.checkElement.DesiredSize.Width : checkSize.Width; if (newLayout) { checkBounds = new RectangleF(Point.Empty, checkElement.DesiredSize); } else { checkBounds = new Rectangle(Point.Empty, checkSize); } if (this.RightToLeft) { contentAlignment = TelerikAlignHelper.RtlTranslateContent(CheckAlignment); } else { contentAlignment = CheckAlignment; } if (checkWidth <= 0) { return; } RectangleF rectangle1 = fieldRectangle; RectangleF field = rectangle1; //setting the check at the right, horizontally if ((contentAlignment & (ContentAlignment.BottomRight | (ContentAlignment.MiddleRight | ContentAlignment.TopRight))) != ((ContentAlignment)0)) { checkBounds.X = (rectangle1.X + rectangle1.Width) - checkBounds.Width; } //setting the check at the center, horizontally else if ((contentAlignment & (ContentAlignment.BottomCenter | (ContentAlignment.MiddleCenter | ContentAlignment.TopCenter))) != ((ContentAlignment)0)) { checkBounds.X = rectangle1.X + ((rectangle1.Width - checkBounds.Width) / 2); } //setting the check at the bottom, vertically if ((contentAlignment & (ContentAlignment.BottomRight | (ContentAlignment.BottomCenter | ContentAlignment.BottomLeft))) != ((ContentAlignment)0)) { checkBounds.Y = (rectangle1.Y + rectangle1.Height) - checkBounds.Height; } //setting the check in the center, vertically else if ((contentAlignment & (ContentAlignment.MiddleRight | (ContentAlignment.MiddleCenter | ContentAlignment.MiddleLeft))) != ((ContentAlignment)0)) { checkBounds.Y = rectangle1.Y + ((rectangle1.Height - checkBounds.Height) / 2); } ContentAlignment alignment2 = contentAlignment; switch (alignment2) { //check is aligned on the left size case ContentAlignment.TopLeft: case ContentAlignment.MiddleLeft: case ContentAlignment.BottomLeft: { field.X += checkWidth + this.CheckMarkOffset; field.Width -= checkWidth + this.CheckMarkOffset; break; } case ContentAlignment.TopCenter: { field.Y += checkWidth; field.Height -= checkWidth; break; } case ContentAlignment.TopCenter | ContentAlignment.TopLeft: { break; } case ContentAlignment.TopRight: case ContentAlignment.BottomRight: case ContentAlignment.MiddleRight: { field.Width -= checkWidth + this.CheckMarkOffset; break; } case ContentAlignment.BottomCenter: { field.Height -= checkWidth; break; } case ContentAlignment.MiddleCenter: { break; } } if (newLayout) { this.checkElement.Arrange(checkBounds); this.bodyElement.Arrange(field); } else { this.checkElement.Bounds = Rectangle.Round(checkBounds); this.bodyElement.Bounds = Rectangle.Round(field); } }
/// <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); }
public virtual void PaintImage( IGraphics graphics, Image image, RectangleF rect, ImageLayout imageLayout, ContentAlignment imageAlignment, float opacity, bool rtl) { SizeF size = rect.Size; if (image == null || size == SizeF.Empty) { return; } if (rtl) { imageAlignment = TelerikAlignHelper.RtlTranslateContent(imageAlignment); } switch (imageLayout) { case ImageLayout.None: RectangleF rectangleF = LayoutUtils.Align(new SizeF(Math.Min(rect.Width, (float)image.Size.Width), Math.Min(rect.Height, (float)image.Size.Height)), rect, imageAlignment); ((Graphics)graphics.UnderlayGraphics).DrawImageUnscaledAndClipped(image, new Rectangle(new Point((int)rectangleF.Location.X, (int)rectangleF.Location.Y), rectangleF.Size.ToSize())); break; case ImageLayout.Tile: float num1 = rect.Y - (float)image.Height; do { num1 += (float)image.Height; float num2 = rect.X - (float)image.Width; do { num2 += (float)image.Width; if ((double)opacity == 1.0) { graphics.DrawBitmap(image, (int)num2, (int)num1); } else { graphics.DrawBitmap(image, (int)num2, (int)num1, (double)opacity); } }while ((double)num2 < (double)rect.X + (double)rect.Width - (double)image.Width); }while ((double)num1 <= (double)rect.Y + (double)rect.Height - (double)image.Height); break; case ImageLayout.Center: PointF pointF = new PointF(Math.Max(0.0f, rect.X + Math.Max(0.0f, (float)(((double)size.Width - (double)image.Width) / 2.0))), Math.Max(0.0f, rect.Y + Math.Max(0.0f, (float)(((double)size.Height - (double)image.Height) / 2.0)))); pointF.X = Math.Min(pointF.X, rect.Right); pointF.Y = Math.Min(pointF.Y, rect.Bottom); SizeF sizeF = new SizeF(Math.Min(rect.Width, (float)image.Size.Width), Math.Min(rect.Height, (float)image.Size.Height)); if ((double)opacity == 1.0) { ((Graphics)graphics.UnderlayGraphics).DrawImageUnscaledAndClipped(image, new Rectangle(new Point((int)pointF.X, (int)pointF.Y), sizeF.ToSize())); break; } graphics.DrawBitmap(image, (int)pointF.X, (int)pointF.Y, (double)opacity); break; case ImageLayout.Stretch: if ((double)opacity == 1.0) { graphics.DrawBitmap(image, (int)rect.X, (int)rect.Y, (int)size.Width, (int)size.Height); break; } graphics.DrawBitmap(image, 0, 0, (int)size.Width, (int)size.Height, (double)opacity); break; case ImageLayout.Zoom: if (image.Width == 0 || image.Height == 0) { break; } float num3 = Math.Min(size.Width / (float)image.Width, size.Height / (float)image.Height); if ((double)num3 <= 0.0) { break; } int width = (int)Math.Round((double)image.Width * (double)num3); int height = (int)Math.Round((double)image.Height * (double)num3); int x = (int)rect.X + (int)(((double)size.Width - (double)width) / 2.0); int y = (int)rect.Y + (int)(((double)size.Height - (double)height) / 2.0); if ((double)opacity == 1.0) { graphics.DrawBitmap(image, x, y, width, height); break; } graphics.DrawBitmap(image, x, y, width, height, (double)opacity); break; } }
private void LayoutCheckmark(RectangleF fieldRectangle, bool newLayout) { float num = newLayout ? this.checkElement.DesiredSize.Width : (float)this.checkSize.Width; this.checkBounds = !newLayout ? (RectangleF) new Rectangle(Point.Empty, this.checkSize) : new RectangleF((PointF)Point.Empty, this.checkElement.DesiredSize); this.contentAlignment = !this.RightToLeft ? this.CheckAlignment : TelerikAlignHelper.RtlTranslateContent(this.CheckAlignment); if ((double)num <= 0.0) { return; } RectangleF rectangleF = fieldRectangle; RectangleF finalRect = rectangleF; if ((this.contentAlignment & (ContentAlignment.TopRight | ContentAlignment.MiddleRight | ContentAlignment.BottomRight)) != (ContentAlignment)0) { this.checkBounds.X = rectangleF.X + rectangleF.Width - this.checkBounds.Width; } else if ((this.contentAlignment & (ContentAlignment.TopCenter | ContentAlignment.MiddleCenter | ContentAlignment.BottomCenter)) != (ContentAlignment)0) { this.checkBounds.X = rectangleF.X + (float)(((double)rectangleF.Width - (double)this.checkBounds.Width) / 2.0); } if ((this.contentAlignment & (ContentAlignment.BottomLeft | ContentAlignment.BottomCenter | ContentAlignment.BottomRight)) != (ContentAlignment)0) { this.checkBounds.Y = rectangleF.Y + rectangleF.Height - this.checkBounds.Height; } else if ((this.contentAlignment & (ContentAlignment.MiddleLeft | ContentAlignment.MiddleCenter | ContentAlignment.MiddleRight)) != (ContentAlignment)0) { this.checkBounds.Y = rectangleF.Y + (float)(((double)rectangleF.Height - (double)this.checkBounds.Height) / 2.0); } switch (this.contentAlignment) { case ContentAlignment.TopLeft: case ContentAlignment.MiddleLeft: case ContentAlignment.BottomLeft: finalRect.X += num + (float)this.CheckMarkOffset; finalRect.Width -= num + (float)this.CheckMarkOffset; break; case ContentAlignment.TopCenter: finalRect.Y += num; finalRect.Height -= num; break; case ContentAlignment.TopRight: case ContentAlignment.MiddleRight: case ContentAlignment.BottomRight: finalRect.Width -= num + (float)this.CheckMarkOffset; break; case ContentAlignment.BottomCenter: finalRect.Height -= num; break; } if (newLayout) { this.checkElement.Arrange(this.checkBounds); this.bodyElement.Arrange(finalRect); } else { this.checkElement.Bounds = Rectangle.Round(this.checkBounds); this.bodyElement.Bounds = Rectangle.Round(finalRect); } }
public virtual StringFormat CreateStringFormat() { StringFormat stringFormat = TelerikHelper.StringFormatForAlignment(this.alignment); if (this.rightToLeft) { stringFormat.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } if (this.autoEllipsis) { stringFormat.Trimming = StringTrimming.EllipsisCharacter; } if (this.lineLimit) { stringFormat.FormatFlags |= StringFormatFlags.LineLimit; } stringFormat.HotkeyPrefix = this.useMnemonic ? (!this.showKeyboardCues ? HotkeyPrefix.Hide : HotkeyPrefix.Show) : HotkeyPrefix.None; if (this.measureTrailingSpaces) { stringFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; } if (!this.textWrap) { stringFormat.FormatFlags |= StringFormatFlags.NoWrap; } if (this.ClipText) { stringFormat.FormatFlags &= ~StringFormatFlags.NoClip; } else { stringFormat.FormatFlags |= StringFormatFlags.NoClip; } stringFormat.Alignment = !this.rightToLeft ? TelerikAlignHelper.TranslateAlignment(this.alignment) : TelerikAlignHelper.TranslateAlignment(TelerikAlignHelper.RtlTranslateContent(this.alignment)); stringFormat.LineAlignment = TelerikAlignHelper.TranslateLineAlignment(this.alignment); return(stringFormat); }
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); }
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); }
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); }
/// <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; } }
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); }
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); }
protected override SizeF ArrangeOverride(SizeF arrangeSize) { RadCommandBarBaseItemCollection items = this.items; int count = items.Count; SizeF empty = SizeF.Empty; bool flag1 = false; bool flag2 = false; if (flag1 || flag2) { for (int index = 0; index < count; ++index) { RadElement radElement = (RadElement)items[index]; if (flag1) { empty.Height = Math.Max(radElement.DesiredSize.Height, empty.Height); } if (flag2) { empty.Width = Math.Max(radElement.DesiredSize.Width, empty.Width); } } } bool flag3 = this.Orientation == Orientation.Horizontal; bool rightToLeft = this.RightToLeft; float num = 0.0f; RectangleF finalRect = new RectangleF(PointF.Empty, arrangeSize); if (flag3 && rightToLeft) { finalRect.X = arrangeSize.Width; } float f = this.ArrangeStretchedItems(arrangeSize); for (int index = 0; index < count; ++index) { RadElement radElement = (RadElement)items[index]; SizeF desiredSize = radElement.DesiredSize; if (radElement.Visibility == ElementVisibility.Collapsed) { radElement.Arrange(new RectangleF(PointF.Empty, desiredSize)); } else { if (flag1) { desiredSize.Height = !flag3 ? empty.Height : Math.Max(arrangeSize.Height, empty.Height); } if (flag2) { desiredSize.Width = !flag3?Math.Max(arrangeSize.Width, empty.Width) : empty.Width; } if (radElement.StretchHorizontally && flag3 && !float.IsInfinity(f)) { desiredSize.Width = f; } if (radElement.StretchVertically && !flag3 && !float.IsInfinity(f)) { desiredSize.Height = f; } if (flag3) { if (rightToLeft) { num = desiredSize.Width; finalRect.X -= num; } else { finalRect.X += num; num = desiredSize.Width; } finalRect.Width = num; if (flag1) { 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 (flag2) { 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; } } if (radElement.StretchVertically && flag3) { finalRect.Height = arrangeSize.Height; } else if (radElement.StretchHorizontally && !flag3) { finalRect.Width = arrangeSize.Width; } radElement.Arrange(finalRect); } } return(arrangeSize); }