/// <summary> /// Gets the vertical relative alignment of the short text. /// </summary> /// <param name="style">Content style.</param> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>RelativeAlignment value.</returns> public override PaletteRelativeAlign GetContentShortTextV(PaletteContentStyle style, PaletteState state) { IPaletteContent inherit = GetInherit(state); return(inherit?.GetContentShortTextV(state) ?? Target.GetContentShortTextV(style, state)); }
private static void PositionAlignContent(StandardContentMemento memento, IPaletteContent paletteContent, PaletteState state, RightToLeft rtl, PaletteRelativeAlign alignH, PaletteRelativeAlign alignV, int cellX, int cellY, int cellWidth, int cellHeight, int spacingGap) { // Create client rectangle covering cell size Rectangle cellRect = new Rectangle(cellX, cellY, cellWidth, cellHeight); PaletteRelativeAlign drawHImage = paletteContent.GetContentImageH(state); PaletteRelativeAlign drawVImage = paletteContent.GetContentImageV(state); PaletteRelativeAlign drawHShort = paletteContent.GetContentShortTextH(state); PaletteRelativeAlign drawVShort = paletteContent.GetContentShortTextV(state); PaletteRelativeAlign drawHLong = paletteContent.GetContentLongTextH(state); PaletteRelativeAlign drawVLong = paletteContent.GetContentLongTextV(state); PaletteRelativeAlign posHImage = drawHImage; PaletteRelativeAlign posHShort = drawHShort; PaletteRelativeAlign posHLong = drawHLong; // If positioning in the center, then need extra processing if (alignH == PaletteRelativeAlign.Center) { // Find number of content and width of those in this cell int totalWidth = 0; int totalItems = 0; if (memento.DrawImage && (drawHImage == alignH) && (drawVImage == alignV)) { totalWidth += memento.ImageRect.Width; totalItems++; } if (memento.DrawShortText && (drawHShort == alignH) && (drawVShort == alignV)) { totalWidth += memento.ShortTextRect.Width; totalItems++; } if (memento.DrawLongText && (drawHLong == alignH) && (drawVLong == alignV)) { totalWidth += memento.LongTextRect.Width; totalItems++; } // If more than one item is to be positioned if (totalItems > 1) { // Add on required number of spacing gaps totalWidth += (totalItems - 1) * spacingGap; // Then center the space for the content int halfWidth = (cellRect.Width - totalWidth) / 2; cellRect.Width -= (halfWidth * 2); cellRect.X += halfWidth; // Ensure all content are placed near, so they fit exactly posHImage = posHShort = posHLong = PaletteRelativeAlign.Near; } } // Do we need to position the image? if (memento.DrawImage && (drawHImage == alignH) && (drawVImage == alignV)) memento.ImageRect.Location = PositionCellContent(rtl, posHImage, drawVImage, memento.ImageRect.Size, spacingGap, ref cellRect); // Do we need to position the short text? if (memento.DrawShortText && (drawHShort == alignH) && (drawVShort == alignV)) memento.ShortTextRect.Location = PositionCellContent(rtl, posHShort, drawVShort, memento.ShortTextRect.Size, spacingGap, ref cellRect); // Do we need to position the long text? if (memento.DrawLongText && (drawHLong == alignH) && (drawVLong == alignV)) memento.LongTextRect.Location = PositionCellContent(rtl, posHLong, drawVLong, memento.LongTextRect.Size, spacingGap, ref cellRect); }
/// <summary> /// Gets the vertical relative alignment of the short text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>RelativeAlignment value.</returns> public override PaletteRelativeAlign GetContentShortTextV(PaletteState state) { return(_inherit.GetContentShortTextV(state)); }
private static void AllocateShortTextSpace(ViewLayoutContext context, Graphics g, StandardContentMemento memento, IPaletteContent paletteContent, IContentValues contentValues, PaletteState state, Rectangle displayRect, RightToLeft rtl, int spacingGap, ref Size[,] allocation, bool composition, bool glowing) { // By default, we cannot draw the text memento.DrawShortText = false; // Get the defined text for display string shortText = contentValues.GetShortText(); // Is there any text to be drawn? if ((shortText != null) && (shortText.Length > 0)) { // If the text is not allowed to span multiple lines if (paletteContent.GetContentShortTextMultiLine(state) == InheritBool.False) { // Replace any carriage returns and newlines with just spaces shortText = shortText.Replace("\r\n", " "); shortText = shortText.Replace("\n", " "); shortText = shortText.Replace("\r", " "); } // Convert from alignment enums to integers int alignHIndex = RightToLeftIndex(rtl, paletteContent.GetContentShortTextH(state)); int alignVIndex = (int)paletteContent.GetContentShortTextV(state); // Cache the rendering hint used memento.ShortTextHint = CommonHelper.PaletteTextHintToRenderingHint(paletteContent.GetContentShortTextHint(state)); memento.ShortTextTrimming = paletteContent.GetContentShortTextTrim(state); bool fontChanged = false; Font textFont = paletteContent.GetContentShortTextFont(state); // Get the appropriate font to use in the caption area if (paletteContent.GetContentStyle() == PaletteContentStyle.HeaderForm) { Font captionFont = ContentFontForButtonForm(context, textFont); fontChanged = (captionFont != textFont); textFont = captionFont; } // Get a pixel accurate measure of text drawing space needed memento.ShortTextMemento = AccurateText.MeasureString(g, rtl, shortText, textFont, memento.ShortTextTrimming, paletteContent.GetContentShortTextMultiLineH(state), paletteContent.GetContentShortTextPrefix(state), memento.ShortTextHint, composition, glowing, fontChanged); // Space required for short text starts with the text width itself Size requiredSpace = memento.ShortTextMemento.Size; // Find the space available given our required alignment if (AllocateAlignmentSpace(alignHIndex, alignVIndex, allocation, displayRect, spacingGap, memento.ShortTextTrimming, ref requiredSpace)) { // Allocate the actual space used up // Cache the actual draw size of the text memento.ShortTextRect.Size = requiredSpace; // Mark the memento to draw the short text memento.DrawShortText = true; } } }
/// <summary> /// Gets the vertical relative alignment of the short text. /// </summary> /// <param name="state">Palette value should be applicable to this state.</param> /// <returns>RelativeAlignment value.</returns> public PaletteRelativeAlign GetContentShortTextV(PaletteState state) { return(_content.GetContentShortTextV(state)); }