Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #1347 from ermshiperete/ImproveEllipsisHandling
[MWF] Improve ellipsis handling
  • Loading branch information
migueldeicaza committed Nov 2, 2014
2 parents 57feaca + 5d869be commit 0930889
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Expand Up @@ -492,9 +492,6 @@ private static Rectangle PadDrawStringRectangle (Rectangle r, TextFormatFlags fl
r.X += 2;
r.Width -= 2;
}
if ((flags & TextFormatFlags.WordEllipsis) == TextFormatFlags.WordEllipsis || (flags & TextFormatFlags.EndEllipsis) == TextFormatFlags.EndEllipsis || (flags & TextFormatFlags.WordBreak) == TextFormatFlags.WordBreak) {
r.Width -= 4;
}
if ((flags & TextFormatFlags.VerticalCenter) == TextFormatFlags.VerticalCenter && XplatUI.RunningOnUnix) {
r.Y -= 1;
}
Expand Down
Expand Up @@ -375,16 +375,18 @@ public override void CalculateButtonTextAndImageLayout (Graphics g, ButtonBase b
textRectangle = Rectangle.Inflate (content_rect, -4, -4);
imageRectangle = Rectangle.Empty;

bool displayEllipsis = (button.TextFormatFlags & (TextFormatFlags.EndEllipsis | TextFormatFlags.PathEllipsis | TextFormatFlags.WordEllipsis)) != 0;

switch (button.TextImageRelation) {
case TextImageRelation.Overlay:
// Overlay is easy, text always goes here

// Image is dependent on ImageAlign
if (image == null) {
if (button.Pressed)
textRectangle.Offset (1, 1);

// Image is dependent on ImageAlign
if (image == null)
return;
}

int image_x = 0;
int image_y = 0;
Expand Down Expand Up @@ -437,10 +439,10 @@ public override void CalculateButtonTextAndImageLayout (Graphics g, ButtonBase b
imageRectangle = new Rectangle (image_x, image_y, image_width, image_height);
break;
case TextImageRelation.ImageAboveText:
LayoutTextAboveOrBelowImage (textRectangle, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
LayoutTextAboveOrBelowImage (textRectangle, false, text_size, image_size, button.TextAlign, button.ImageAlign, displayEllipsis, out textRectangle, out imageRectangle);
break;
case TextImageRelation.TextAboveImage:
LayoutTextAboveOrBelowImage (textRectangle, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
LayoutTextAboveOrBelowImage (textRectangle, true, text_size, image_size, button.TextAlign, button.ImageAlign, displayEllipsis, out textRectangle, out imageRectangle);
break;
case TextImageRelation.ImageBeforeText:
LayoutTextBeforeOrAfterImage (textRectangle, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
Expand All @@ -449,6 +451,8 @@ public override void CalculateButtonTextAndImageLayout (Graphics g, ButtonBase b
LayoutTextBeforeOrAfterImage (textRectangle, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
break;
}
if (button.Pressed)
textRectangle.Offset (1, 1);
}

private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
Expand Down Expand Up @@ -496,7 +500,7 @@ private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst,
imageRect = final_image_rect;
}

private void LayoutTextAboveOrBelowImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
private void LayoutTextAboveOrBelowImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, bool displayEllipsis, out Rectangle textRect, out Rectangle imageRect)
{
int element_spacing = 0; // Spacing between the Text and the Image
int total_height = textSize.Height + element_spacing + imageSize.Height;
Expand Down Expand Up @@ -545,6 +549,12 @@ private void LayoutTextAboveOrBelowImage (Rectangle totalArea, bool textFirst, S
final_text_rect.Y = totalArea.Top;
}

if (displayEllipsis) {
// Don't use more space than is available otherwise ellipsis won't show
if (final_text_rect.Height > totalArea.Bottom)
final_text_rect.Height = totalArea.Bottom - final_text_rect.Top;
}

textRect = final_text_rect;
imageRect = final_image_rect;
}
Expand Down Expand Up @@ -1092,11 +1102,11 @@ public override void CalculateCheckBoxTextAndImageLayout (ButtonBase button, Poi
break;
case TextImageRelation.ImageAboveText:
content_rect.Inflate (-4, -4);
LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, false, out textRectangle, out imageRectangle);
break;
case TextImageRelation.TextAboveImage:
content_rect.Inflate (-4, -4);
LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, false, out textRectangle, out imageRectangle);
break;
case TextImageRelation.ImageBeforeText:
content_rect.Inflate (-4, -4);
Expand Down

0 comments on commit 0930889

Please sign in to comment.