Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GUI of NuGet for Unity window #617

Merged
merged 39 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5fd8017
Fix: an issue where editor styles would be overwritten
AnnulusGames Jan 20, 2024
d3fd962
Changed header buttons to toolbar-like GUI
AnnulusGames Jan 20, 2024
fd0f130
Changed tab size to ToolbarButtonSize.FitToContents.
AnnulusGames Jan 20, 2024
78086c3
Improved appearance of search field
AnnulusGames Jan 20, 2024
45e75aa
Improved appearance of package view elements
AnnulusGames Jan 21, 2024
a223db2
Moved GUIStyle caches to Styles class
AnnulusGames Jan 21, 2024
95875fb
Improved the appearance around the 'Show More' button.
AnnulusGames Jan 21, 2024
f4764b5
Improved the appearance of the "Show License" button
AnnulusGames Jan 21, 2024
fe9acbe
Improved the appearance of the Project URL section
AnnulusGames Jan 21, 2024
2fbe033
Changed toggleOnLabelClick in Details foldout to true
AnnulusGames Jan 21, 2024
c2f3b89
Improved appearance of 'Update Selected' button
AnnulusGames Jan 21, 2024
c44d85b
Adjusted layout and font size
AnnulusGames Jan 21, 2024
8573e5a
Reverted unnecessary changes
AnnulusGames Jan 21, 2024
790a7c5
Fixed issue with Show Downgrades toggle not working
AnnulusGames Jan 21, 2024
d3765a2
Improved appearance of `Installed Packages` section
AnnulusGames Jan 21, 2024
8736dcb
Improved the appearance of the package selection screen
AnnulusGames Jan 21, 2024
3fcd778
Improved foldout appearance
AnnulusGames Jan 21, 2024
c717ce1
Improved appearance of package view elements
AnnulusGames Jan 21, 2024
3147aa7
Fixed issue where 'Collection was modified' error was displayed
AnnulusGames Jan 21, 2024
b0c5e72
Changed the default string in the search field to an empty string
AnnulusGames Jan 21, 2024
14758c7
Removed unnecessary fields
AnnulusGames Jan 21, 2024
7dbc5c5
Adjusted the color tone for dark theme
AnnulusGames Jan 21, 2024
8a566e6
Improved appearance of Dependencies item in Details section
AnnulusGames Jan 21, 2024
01d6ec3
Improved the appearance of Clone Window
AnnulusGames Jan 21, 2024
bbd0113
Fixed issue with Show Prerelease toggle not working
AnnulusGames Jan 21, 2024
7b2f39a
Changed EditorGUILayout.Space to GUILayout.Space
AnnulusGames Jan 21, 2024
6434f77
Made GUIStyle acquisition compatible with older editor versions
AnnulusGames Jan 21, 2024
82f7950
Adjusted button width
AnnulusGames Jan 21, 2024
bed4a7e
Fixed an issue where the description was not displayed correctly
AnnulusGames Jan 21, 2024
cd8b10b
Changed TextAnchor of description label to UpperLeft
AnnulusGames Jan 21, 2024
a68a81d
run autoformatter
JoC0de Jan 21, 2024
b7e8983
add documentation
JoC0de Jan 21, 2024
2491277
Updated images in docs
AnnulusGames Jan 21, 2024
834d1ea
Cached GUI styles
AnnulusGames Jan 22, 2024
fdb204e
Removed unnecessary GUI.FocusControl
AnnulusGames Jan 22, 2024
fce6dee
Changed some BeginHorizontal/Vertical to code using Scope
AnnulusGames Jan 22, 2024
315f50f
Cached StringBuilder
AnnulusGames Jan 22, 2024
3f5a193
Adjusted the width so that the summary label is not hidden by the scr…
AnnulusGames Jan 22, 2024
501c25a
format code
JoC0de Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/screenshots/installed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/online.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/updates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/updates_showdowngrades.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
731 changes: 312 additions & 419 deletions src/NuGetForUnity/Editor/Ui/NugetWindow.cs

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions src/NuGetForUnity/Editor/Ui/RectHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using UnityEngine;

namespace NugetForUnity
{
/// <summary>
/// Extension methods for manipulating Rect objects.
/// </summary>
internal static class RectHelper
{
/// <summary>
/// Expands the boundaries of the Rect by a specified value in all directions.
/// </summary>
/// <param name="rect">The rect to update.</param>
/// <param name="value">The value to add.</param>
/// <returns>The updated Rect.</returns>
public static Rect Expand(this Rect rect, float value)
{
rect.xMin -= value;
rect.xMax += value;
rect.yMin -= value;
rect.yMax += value;
return rect;
}

/// <summary>
/// Expands the Rect horizontally by a specified value.
/// </summary>
/// <param name="rect">The rect to update.</param>
/// <param name="value">The value to add.</param>
/// <returns>The updated Rect.</returns>
public static Rect ExpandX(this Rect rect, float value)
{
rect.xMin -= value;
rect.xMax += value;
return rect;
}

/// <summary>
/// Expands the Rect vertically by a specified value.
/// </summary>
/// <param name="rect">The rect to update.</param>
/// <param name="value">The value to add.</param>
/// <returns>The updated Rect.</returns>
public static Rect ExpandY(this Rect rect, float value)
{
rect.yMin -= value;
rect.yMax += value;
return rect;
}

/// <summary>
/// Adds a specified value to the X-coordinate of the Rect.
/// </summary>
/// <param name="rect">The rect to update.</param>
/// <param name="value">The value to add.</param>
/// <returns>The updated Rect.</returns>
public static Rect AddX(this Rect rect, float value)
{
rect.x += value;
return rect;
}

/// <summary>
/// Adds a specified value to the Y-coordinate of the Rect.
/// </summary>
/// <param name="rect">The rect to update.</param>
/// <param name="value">The value to add.</param>
/// <returns>The updated Rect.</returns>
public static Rect AddY(this Rect rect, float value)
{
rect.y += value;
return rect;
}

/// <summary>
/// Sets the width of the Rect to a specified value.
/// </summary>
/// <param name="rect">The rect to update.</param>
/// <param name="value">The value to set.</param>
/// <returns>The updated Rect.</returns>
public static Rect SetWidth(this Rect rect, float value)
{
rect.width = value;
return rect;
}

/// <summary>
/// Sets the height of the Rect to a specified value.
/// </summary>
/// <param name="rect">The rect to update.</param>
/// <param name="value">The value to set.</param>
/// <returns>The updated Rect.</returns>
public static Rect SetHeight(this Rect rect, float value)
{
rect.height = value;
return rect;
}
}
}
11 changes: 11 additions & 0 deletions src/NuGetForUnity/Editor/Ui/RectHelper.cs.meta

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

186 changes: 186 additions & 0 deletions src/NuGetForUnity/Editor/Ui/Styles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
using UnityEditor;
using UnityEngine;

namespace NugetForUnity.Ui
{
/// <summary>
/// Collection of GUIStyle.
/// </summary>
internal static class Styles
{
private static GUIStyle cachedSearchFieldStyle;

private static GUIStyle cachedHeaderStyle;

private static GUIStyle cachedBackgroundStyle;

private static GUIStyle cachedLinkLabelStyle;

/// <summary>
/// Gets the color used for lines used as seperators.
/// </summary>
public static Color LineColor
{
get
{
if (EditorGUIUtility.isProSkin)
{
return new Color(0.05f, 0.05f, 0.05f);
}

return new Color(0.6f, 0.6f, 0.6f);
}
}

/// <summary>
/// Gets the color used for package authors.
/// </summary>
public static Color AuthorsTextColor
{
get
{
if (EditorGUIUtility.isProSkin)
{
return new Color(0.55f, 0.55f, 0.55f);
}

return new Color(0.45f, 0.45f, 0.45f);
}
}

/// <summary>
/// Gets the color used for the foldout header.
/// </summary>
public static Color FoldoutHeaderColor
{
get
{
if (EditorGUIUtility.isProSkin)
{
return new Color(0.2f, 0.2f, 0.2f);
}

return new Color(0.85f, 0.85f, 0.85f);
}
}

/// <summary>
/// Gets a GUI style with a background color the same as the editor's current background color.
/// </summary>
public static GUIStyle BackgroundStyle
{
get
{
if (cachedBackgroundStyle != null)
{
return cachedBackgroundStyle;
}

cachedBackgroundStyle = new GUIStyle();
var backgroundColor = EditorGUIUtility.isProSkin ? new Color32(56, 56, 56, 255) : new Color32(194, 194, 194, 255);
cachedBackgroundStyle.normal.background = CreateSingleColorTexture(backgroundColor);

return cachedBackgroundStyle;
}
}

/// <summary>
/// Gets the GUI style used for the header of the NuGet window.
/// </summary>
public static GUIStyle HeaderStyle
{
get
{
if (cachedHeaderStyle != null)
{
return cachedHeaderStyle;
}

cachedHeaderStyle = new GUIStyle();
var backgroundColor = EditorGUIUtility.isProSkin ? new Color(0.1f, 0.1f, 0.1f) : new Color(0.4f, 0.4f, 0.4f);
cachedHeaderStyle.alignment = TextAnchor.MiddleLeft;
cachedHeaderStyle.normal.background = CreateSingleColorTexture(backgroundColor);
cachedHeaderStyle.normal.textColor = Color.white;

return cachedHeaderStyle;
}
}

/// <summary>
/// Gets the GUI style used for the package seach field.
/// </summary>
public static GUIStyle SearchFieldStyle
{
get
{
if (cachedSearchFieldStyle != null)
{
return cachedSearchFieldStyle;
}

var original = GetStyle("ToolbarSearchTextField");
cachedSearchFieldStyle = new GUIStyle(original) { fontSize = 12, fixedHeight = 20f };

return cachedSearchFieldStyle;
}
}

/// <summary>
/// Gets the GUI style used for labels representing a URL / clickable LINK.
/// </summary>
public static GUIStyle LinkLabelStyle
{
get
{
if (cachedLinkLabelStyle != null)
{
return cachedLinkLabelStyle;
}

cachedLinkLabelStyle = GetStyle("LinkLabel");
return cachedLinkLabelStyle;
}
}

/// <summary>
/// From here: http://forum.unity3d.com/threads/changing-the-background-color-for-beginhorizontal.66015/.
/// </summary>
/// <param name="color">The color to fill the texture with.</param>
/// <returns>The generated texture.</returns>
private static Texture2D CreateSingleColorTexture(Color color)
{
const int width = 16;
const int height = 16;
var pix = new Color32[width * height];
Color32 color32 = color;
for (var index = 0; index < pix.Length; index++)
{
pix[index] = color32;
}

var result = new Texture2D(width, height);
result.SetPixels32(pix);
result.Apply();

return result;
}

private static GUIStyle GetStyle(string styleName)
{
var style = GUI.skin.FindStyle(styleName);

if (style == null)
{
style = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle(styleName);
}

if (style == null)
{
Debug.LogError("Missing built-in guistyle " + styleName);
style = new GUIStyle();
}

return style;
}
}
}
11 changes: 11 additions & 0 deletions src/NuGetForUnity/Editor/Ui/Styles.cs.meta

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

Loading