Skip to content

Commit

Permalink
Restyle package details to show title and button
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Aug 14, 2024
1 parent 5033d18 commit 69aa3a9
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 568 deletions.
216 changes: 105 additions & 111 deletions Bonsai.NuGet.Design/GalleryDialog.Designer.cs

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions Bonsai.NuGet.Design/ImageLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,34 @@ public ImageLabel()
}
}

public new ImageList ImageList { get; set; }

public new int ImageIndex { get; set; }

public override Size GetPreferredSize(Size proposedSize)
{
var size = base.GetPreferredSize(proposedSize);
if (Image != null)
var image = ImageList != null ? ImageList.Images[ImageIndex] : Image;
if (image != null)
{
using var graphics = CreateGraphics();
var imageSize = graphics.GetImageSize(Image);
size.Width += (int)Math.Ceiling(imageSize.Width);
var imageSize = Size.Ceiling(graphics.GetImageSize(image));
size.Width += imageSize.Width;
size.Height = Math.Max(size.Height, imageSize.Height);
}
return size;
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (ImageList != null)
{
var rectangle = ClientRectangle;
var image = ImageList.Images[ImageIndex];
var imageBounds = CalcImageRenderBounds(image, rectangle, ImageAlign);
ImageList.Draw(e.Graphics, imageBounds.Location, ImageIndex);
}
}
}
}
43 changes: 43 additions & 0 deletions Bonsai.NuGet.Design/ImageLinkLabel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Drawing;
using System.Windows.Forms;

namespace Bonsai.NuGet.Design
{
internal class ImageLinkLabel : LinkLabel
{
public ImageLinkLabel()
{
ImageAlign = ContentAlignment.MiddleLeft;
TextAlign = ContentAlignment.MiddleRight;
}

public new Image Image
{
get => base.Image;
set
{
base.Image = value;
if (AutoSize)
{
// force size calculation
AutoSize = false;
AutoSize = true;
}
}
}

public override Size GetPreferredSize(Size proposedSize)
{
var size = base.GetPreferredSize(proposedSize);
if (Image != null)
{
using var graphics = CreateGraphics();
var imageSize = Size.Ceiling(graphics.GetImageSize(Image));
size.Width += imageSize.Width;
size.Height = Math.Max(size.Height, imageSize.Height);
}
return size;
}
}
}
578 changes: 303 additions & 275 deletions Bonsai.NuGet.Design/PackageDetails.Designer.cs

Large diffs are not rendered by default.

74 changes: 61 additions & 13 deletions Bonsai.NuGet.Design/PackageDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
using System.IO;
using NuGet.Frameworks;
using NuGet.Packaging.Core;
using System.Drawing;
using System.ComponentModel;

namespace Bonsai.NuGet.Design
{
public partial class PackageDetails : UserControl
internal partial class PackageDetails : UserControl
{
PackageViewItem selectedItem;
PackageOperationType operation;
const int TextHeightMargin = 7;
static readonly Uri NugetPackageRepository = new Uri("https://packages.nuget.org/packages/");
static readonly object OperationClickEvent = new();

public PackageDetails()
{
Expand All @@ -25,24 +27,53 @@ public PackageDetails()
SetPackage(null);
}

public PackageOperationType Operation
{
get => operation;
set
{
operation = value;
operationButton.Text = value.ToString();
}
}

[Category("Action")]
public event PackageViewEventHandler OperationClick
{
add { Events.AddHandler(OperationClickEvent, value); }
remove { Events.RemoveHandler(OperationClickEvent, value); }
}

public NuGetFramework ProjectFramework { get; set; }

public PackagePathResolver PathResolver { get; set; }

public void SetPackage(IPackageSearchMetadata package)
private void OnOperationClick(PackageViewEventArgs e)
{
(Events[OperationClickEvent] as PackageViewEventHandler)?.Invoke(this, e);
}

public void SetPackage(PackageViewItem item)
{
SuspendLayout();
detailsLayoutPanel.Visible = package != null;
if (package == null) return;
selectedItem = item;
detailsLayoutPanel.Visible = item != null;
if (item == null)
{
packageIdLabel.ImageList = null;
packageIdLabel.ImageIndex = 0;
ResumeLayout();
return;
}

var package = item.Package;
packageIdLabel.Text = package.Identity.Id;
packageIdLabel.ImageList = item.ImageList;
packageIdLabel.ImageIndex = item.ImageIndex;

createdByLabel.Text = string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, package.Authors);
idLinkLabel.Text = package.Identity.Id;
var packageUri = package.PackageDetailsUrl ?? new Uri(NugetPackageRepository, package.Identity.Id + "/" + package.Identity.Version.ToString());
SetLinkLabelUri(idLinkLabel, packageUri, false);
versionLabel.Text = string.Format(
"{0}{1}",
package.Identity.Version.ToString(),
package.Identity.Version.IsPrerelease ? Resources.PrereleaseLabel : string.Empty);
SetLinkLabelUri(detailsLinkLabel, package.PackageDetailsUrl, true);
versionLabel.Text = package.Identity.Version.ToString();
lastPublishedLabel.Text = package.Published.HasValue ? package.Published.Value.Date.ToShortDateString() : Resources.UnpublishedLabel;
downloadsLabel.Text = package.DownloadCount.ToString();
SetLinkLabelLicense(licenseLinkLabel, package, true);
Expand Down Expand Up @@ -113,11 +144,28 @@ private void linkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
}
}

private void linkLabel_MouseEnter(object sender, EventArgs e)
{
var linkLabel = (LinkLabel)sender;
linkLabel.LinkColor = ControlPaint.Light(linkLabel.ForeColor);
}

private void linkLabel_MouseLeave(object sender, EventArgs e)
{
var linkLabel = (LinkLabel)sender;
linkLabel.LinkColor = linkLabel.ForeColor;
}

private void dependenciesTextBox_TextChanged(object sender, EventArgs e)
{
var textSize = TextRenderer.MeasureText(dependenciesTextBox.Text, dependenciesTextBox.Font);
textSize.Height += TextHeightMargin;
dependenciesTextBox.Size = textSize;
}

private void operationButton_Click(object sender, EventArgs e)
{
OnOperationClick(new PackageViewEventArgs(selectedItem.Package, Operation));
}
}
}
Loading

0 comments on commit 69aa3a9

Please sign in to comment.