Improve content item in tile view. Decrease margin between list view items.

This commit is contained in:
Chandler Cox
2023-09-01 14:28:26 -05:00
parent 36dca16991
commit 53861c4795
2 changed files with 66 additions and 20 deletions

View File

@@ -483,6 +483,30 @@ namespace FlaxEditor.Content
else
Render2D.FillRectangle(rectangle, Color.Black);
}
/// <summary>
/// Draws the item thumbnail.
/// </summary>
/// <param name="rectangle">The thumbnail rectangle.</param>
/// /// <param name="shadow">Whether or not to draw the shadow. Overrides DrawShadow.</param>
public void DrawThumbnail(ref Rectangle rectangle, bool shadow)
{
// Draw shadow
if (shadow)
{
const float thumbnailInShadowSize = 50.0f;
var shadowRect = rectangle.MakeExpanded((DefaultThumbnailSize - thumbnailInShadowSize) * rectangle.Width / DefaultThumbnailSize * 1.3f);
if (!_shadowIcon.IsValid)
_shadowIcon = Editor.Instance.Icons.AssetShadow128;
Render2D.DrawSprite(_shadowIcon, shadowRect);
}
// Draw thumbnail
if (_thumbnail.IsValid)
Render2D.DrawSprite(_thumbnail, rectangle);
else
Render2D.FillRectangle(rectangle, Color.Black);
}
/// <summary>
/// Gets the amount of references to that item.
@@ -655,9 +679,32 @@ namespace FlaxEditor.Content
{
case ContentViewType.Tiles:
{
var thumbnailSize = size.X - 2 * DefaultMarginSize;
thumbnailRect = new Rectangle(DefaultMarginSize, DefaultMarginSize, thumbnailSize, thumbnailSize);
var thumbnailSize = size.X;
thumbnailRect = new Rectangle(0, 0, thumbnailSize, thumbnailSize);
nameAlignment = TextAlignment.Center;
// Small shadow
var shadowRect = new Rectangle(2, 2, clientRect.Width + 1, clientRect.Height + 1);
var color = Color.Black.AlphaMultiplied(0.2f);
Render2D.FillRectangle(shadowRect, color);
Render2D.FillRectangle(clientRect, style.LightBackground);
Render2D.FillRectangle(TextRectangle, style.TextBoxBackground);
var accentHeight = 2 * view.ViewScale;
var barRect = new Rectangle(0, thumbnailRect.Height - accentHeight, clientRect.Width, accentHeight);
Render2D.FillRectangle(barRect, Color.DimGray);
DrawThumbnail(ref thumbnailRect, false);
if (isSelected)
{
Render2D.FillRectangle(textRect, Parent.ContainsFocus ? style.BackgroundSelected : style.LightBackground);
Render2D.DrawRectangle(clientRect, Parent.ContainsFocus ? style.BackgroundSelected : style.LightBackground);
}
else if (IsMouseOver)
{
Render2D.FillRectangle(textRect, style.BackgroundHighlighted);
Render2D.DrawRectangle(clientRect, style.BackgroundHighlighted);
}
break;
}
case ContentViewType.List:
@@ -665,23 +712,21 @@ namespace FlaxEditor.Content
var thumbnailSize = size.Y - 2 * DefaultMarginSize;
thumbnailRect = new Rectangle(DefaultMarginSize, DefaultMarginSize, thumbnailSize, thumbnailSize);
nameAlignment = TextAlignment.Near;
if (isSelected)
Render2D.FillRectangle(clientRect, Parent.ContainsFocus ? style.BackgroundSelected : style.LightBackground);
else if (IsMouseOver)
Render2D.FillRectangle(clientRect, style.BackgroundHighlighted);
DrawThumbnail(ref thumbnailRect);
break;
}
default: throw new ArgumentOutOfRangeException();
}
// Draw background
if (isSelected)
Render2D.FillRectangle(clientRect, Parent.ContainsFocus ? style.BackgroundSelected : style.LightBackground);
else if (IsMouseOver)
Render2D.FillRectangle(clientRect, style.BackgroundHighlighted);
// Draw preview
DrawThumbnail(ref thumbnailRect);
// Draw short name
Render2D.PushClip(ref textRect);
Render2D.DrawText(style.FontMedium, ShowFileExtension || view.ShowFileExtensions ? FileName : ShortName, textRect, style.Foreground, nameAlignment, TextAlignment.Center, TextWrapping.WrapWords, 0.75f, 0.95f);
Render2D.DrawText(style.FontMedium, ShowFileExtension || view.ShowFileExtensions ? FileName : ShortName, textRect, style.Foreground, nameAlignment, TextAlignment.Center, TextWrapping.WrapWords, 1f, 0.95f);
Render2D.PopClip();
}