Skip to content

Commit

Permalink
Owner draw image link label for mono compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Jan 20, 2025
1 parent b7d08db commit 2c64e99
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
26 changes: 24 additions & 2 deletions Bonsai.NuGet.Design/ImageLinkLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Bonsai.NuGet.Design
{
internal class ImageLinkLabel : LinkLabel
{
private Image baseImage;

public ImageLinkLabel()
{
ImageAlign = ContentAlignment.MiddleLeft;
Expand All @@ -14,10 +16,13 @@ public ImageLinkLabel()

public new Image Image
{
get => base.Image;
get => baseImage;
set
{
base.Image = value;
baseImage = value;
if (!NativeMethods.IsRunningOnMono)
base.Image = baseImage;

if (AutoSize)
{
// force size calculation
Expand All @@ -39,5 +44,22 @@ public override Size GetPreferredSize(Size proposedSize)
}
return size;
}

protected override void OnPaint(PaintEventArgs e)
{
var rectangle = ClientRectangle;
base.OnPaintBackground(e);
if (Image != null)
{
var imageBounds = CalcImageRenderBounds(Image, rectangle, ImageAlign);
if (NativeMethods.IsRunningOnMono)
e.Graphics.DrawImage(Image, imageBounds.Location);
else
rectangle.X += imageBounds.Width / 2 - imageBounds.X;
rectangle.X += imageBounds.Width / 2;
}

TextRenderer.DrawText(e.Graphics, Text, Font, rectangle, LinkColor);
}
}
}
18 changes: 9 additions & 9 deletions Bonsai.NuGet.Design/PackageDetails.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2c64e99

Please sign in to comment.