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

WIP fix: make hue non nullable #2346

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion sources/core/Stride.Core/DisplayAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public DisplayAttribute(string name = null, string category = null)
/// Gets the hue of a color that is used in the UI.
/// </summary>
/// <remarks>If not null, this value must be in the range [0, 360].</remarks>
public float? CustomHue { get; set; }
public float CustomHue { get; set; } = -1f;

/// <summary>
/// Gets or sets whether to expand the control representing the associated object in the UI.
Expand Down
7 changes: 6 additions & 1 deletion sources/presentation/Stride.Core.Presentation/Core/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public static Color4 GetUniqueColor(this Type type)
var displayAttribute = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute<DisplayAttribute>(type);
var hash = displayAttribute?.Name.GetHashCode() ?? type.Name.GetHashCode();
hash = hash >> 16 ^ hash;
var hue = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute<DisplayAttribute>(type)?.CustomHue ?? hash % 360;

var hue = TypeDescriptorFactory.Default.AttributeRegistry.GetAttribute<DisplayAttribute>(type)?.CustomHue ?? -1;
if(hue is < 0 or > 360)
{
hue = hash % 360;
}
return new ColorHSV(hue, 0.75f + (hash % 101) / 400f, 0.5f + (hash % 151) / 300f, 1).ToColor();
}
}