Clarify slider hover feedback
This commit is contained in:
parent
13540b972b
commit
830ab037d9
2 changed files with 107 additions and 11 deletions
|
|
@ -24,7 +24,11 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
private readonly ID2D1SolidColorBrush activeRowBrush;
|
||||
private readonly ID2D1SolidColorBrush outlineBrush;
|
||||
private readonly ID2D1SolidColorBrush accentBrush;
|
||||
private readonly ID2D1SolidColorBrush accentHoverBrush;
|
||||
private readonly ID2D1SolidColorBrush accentActiveBrush;
|
||||
private readonly ID2D1SolidColorBrush dimAccentBrush;
|
||||
private readonly ID2D1SolidColorBrush trackHoverBrush;
|
||||
private readonly ID2D1SolidColorBrush trackActiveBrush;
|
||||
private readonly IDWriteTextFormat titleFormat;
|
||||
private readonly IDWriteTextFormat smallFormat;
|
||||
private readonly int width;
|
||||
|
|
@ -69,7 +73,11 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
activeRowBrush = renderTarget.CreateSolidColorBrush(new Color4(0.19f, 0.18f, 0.24f, 0.99f));
|
||||
outlineBrush = renderTarget.CreateSolidColorBrush(new Color4(0.28f, 0.34f, 0.36f, 0.72f));
|
||||
accentBrush = renderTarget.CreateSolidColorBrush(new Color4(1.0f, 0.38f, 0.055f, 0.96f));
|
||||
accentHoverBrush = renderTarget.CreateSolidColorBrush(new Color4(1.0f, 0.58f, 0.30f, 0.98f));
|
||||
accentActiveBrush = renderTarget.CreateSolidColorBrush(new Color4(1.0f, 0.78f, 0.58f, 1.0f));
|
||||
dimAccentBrush = renderTarget.CreateSolidColorBrush(new Color4(0.20f, 0.20f, 0.22f, 0.95f));
|
||||
trackHoverBrush = renderTarget.CreateSolidColorBrush(new Color4(0.32f, 0.29f, 0.29f, 0.98f));
|
||||
trackActiveBrush = renderTarget.CreateSolidColorBrush(new Color4(0.45f, 0.38f, 0.34f, 1.0f));
|
||||
titleFormat = CreateTextFormat("Montserrat", 18.0f, FontWeight.Thin);
|
||||
smallFormat = CreateTextFormat("Ubuntu Sans", 11.0f, FontWeight.Regular);
|
||||
}
|
||||
|
|
@ -115,7 +123,11 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
primaryTextBrush,
|
||||
quietTextBrush,
|
||||
accentBrush,
|
||||
accentHoverBrush,
|
||||
accentActiveBrush,
|
||||
dimAccentBrush,
|
||||
trackHoverBrush,
|
||||
trackActiveBrush,
|
||||
width,
|
||||
height);
|
||||
renderTarget.EndDraw();
|
||||
|
|
@ -128,6 +140,10 @@ internal sealed class DirectWriteOverlay : IDisposable
|
|||
smallCapsTypography.Dispose();
|
||||
fontCollection.Dispose();
|
||||
dimAccentBrush.Dispose();
|
||||
trackActiveBrush.Dispose();
|
||||
trackHoverBrush.Dispose();
|
||||
accentActiveBrush.Dispose();
|
||||
accentHoverBrush.Dispose();
|
||||
accentBrush.Dispose();
|
||||
outlineBrush.Dispose();
|
||||
activeRowBrush.Dispose();
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ internal sealed class DebugUi
|
|||
closeButtonActive = closeButtonHovered && input.LeftMouseDown;
|
||||
foreach (var control in controls)
|
||||
{
|
||||
control.IsHovered = control.IsInteractive && control.HitTest(mousePosition);
|
||||
control.UpdateHover(mousePosition);
|
||||
control.IsActive = control.Id == activeControlId && input.LeftMouseDown;
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +113,7 @@ internal sealed class DebugUi
|
|||
|
||||
control.Click(mousePosition);
|
||||
activeControlId = control.Id;
|
||||
control.IsActive = true;
|
||||
if (control is SliderControl slider)
|
||||
{
|
||||
activeSliderId = slider.Id;
|
||||
|
|
@ -135,7 +136,11 @@ internal sealed class DebugUi
|
|||
ID2D1SolidColorBrush primaryBrush,
|
||||
ID2D1SolidColorBrush quietBrush,
|
||||
ID2D1SolidColorBrush accentBrush,
|
||||
ID2D1SolidColorBrush accentHoverBrush,
|
||||
ID2D1SolidColorBrush accentActiveBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush,
|
||||
ID2D1SolidColorBrush trackHoverBrush,
|
||||
ID2D1SolidColorBrush trackActiveBrush,
|
||||
int viewportWidth,
|
||||
int viewportHeight)
|
||||
{
|
||||
|
|
@ -181,7 +186,21 @@ internal sealed class DebugUi
|
|||
|
||||
foreach (var control in controls)
|
||||
{
|
||||
control.Draw(target, smallFormat, rowBrush, hoverRowBrush, activeRowBrush, outlineBrush, primaryBrush, quietBrush, accentBrush, dimAccentBrush);
|
||||
control.Draw(
|
||||
target,
|
||||
smallFormat,
|
||||
rowBrush,
|
||||
hoverRowBrush,
|
||||
activeRowBrush,
|
||||
outlineBrush,
|
||||
primaryBrush,
|
||||
quietBrush,
|
||||
accentBrush,
|
||||
accentHoverBrush,
|
||||
accentActiveBrush,
|
||||
dimAccentBrush,
|
||||
trackHoverBrush,
|
||||
trackActiveBrush);
|
||||
}
|
||||
|
||||
DrawTooltip(target, smallFormat, panelBrush, outlineBrush, primaryBrush, accentBrush, viewportWidth, viewportHeight);
|
||||
|
|
@ -327,6 +346,11 @@ internal sealed class DebugUi
|
|||
|
||||
public virtual bool HitTest(Vector2 mouse) => Contains(Bounds, mouse);
|
||||
|
||||
public virtual void UpdateHover(Vector2 mouse)
|
||||
{
|
||||
IsHovered = IsInteractive && HitTest(mouse);
|
||||
}
|
||||
|
||||
public virtual void Click(Vector2 mouse)
|
||||
{
|
||||
}
|
||||
|
|
@ -341,7 +365,11 @@ internal sealed class DebugUi
|
|||
ID2D1SolidColorBrush primaryBrush,
|
||||
ID2D1SolidColorBrush quietBrush,
|
||||
ID2D1SolidColorBrush accentBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush);
|
||||
ID2D1SolidColorBrush accentHoverBrush,
|
||||
ID2D1SolidColorBrush accentActiveBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush,
|
||||
ID2D1SolidColorBrush trackHoverBrush,
|
||||
ID2D1SolidColorBrush trackActiveBrush);
|
||||
|
||||
protected void DrawRow(
|
||||
ID2D1RenderTarget target,
|
||||
|
|
@ -385,7 +413,11 @@ internal sealed class DebugUi
|
|||
ID2D1SolidColorBrush primaryBrush,
|
||||
ID2D1SolidColorBrush quietBrush,
|
||||
ID2D1SolidColorBrush accentBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush)
|
||||
ID2D1SolidColorBrush accentHoverBrush,
|
||||
ID2D1SolidColorBrush accentActiveBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush,
|
||||
ID2D1SolidColorBrush trackHoverBrush,
|
||||
ID2D1SolidColorBrush trackActiveBrush)
|
||||
{
|
||||
target.DrawText(Label.ToUpperInvariant(), format, Bounds, accentBrush, DrawTextOptions.Clip);
|
||||
target.DrawLine(
|
||||
|
|
@ -410,7 +442,11 @@ internal sealed class DebugUi
|
|||
ID2D1SolidColorBrush primaryBrush,
|
||||
ID2D1SolidColorBrush quietBrush,
|
||||
ID2D1SolidColorBrush accentBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush)
|
||||
ID2D1SolidColorBrush accentHoverBrush,
|
||||
ID2D1SolidColorBrush accentActiveBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush,
|
||||
ID2D1SolidColorBrush trackHoverBrush,
|
||||
ID2D1SolidColorBrush trackActiveBrush)
|
||||
{
|
||||
DrawRow(target, rowBrush, hoverRowBrush, activeRowBrush, outlineBrush);
|
||||
target.DrawText(Label, format, LabelBounds(), accentBrush, DrawTextOptions.Clip);
|
||||
|
|
@ -432,7 +468,11 @@ internal sealed class DebugUi
|
|||
ID2D1SolidColorBrush primaryBrush,
|
||||
ID2D1SolidColorBrush quietBrush,
|
||||
ID2D1SolidColorBrush accentBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush)
|
||||
ID2D1SolidColorBrush accentHoverBrush,
|
||||
ID2D1SolidColorBrush accentActiveBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush,
|
||||
ID2D1SolidColorBrush trackHoverBrush,
|
||||
ID2D1SolidColorBrush trackActiveBrush)
|
||||
{
|
||||
DrawRow(target, rowBrush, hoverRowBrush, activeRowBrush, outlineBrush);
|
||||
target.DrawText(Label.ToUpperInvariant(), format, LabelBounds(), accentBrush, DrawTextOptions.Clip);
|
||||
|
|
@ -449,11 +489,26 @@ internal sealed class DebugUi
|
|||
|
||||
private abstract class SliderControl(string label, string? tooltip) : DebugUiControl(label, tooltip)
|
||||
{
|
||||
private const float ThumbRadius = 4.0f;
|
||||
private const float ThumbHitRadius = 8.0f;
|
||||
|
||||
private bool trackHovered;
|
||||
private bool thumbHovered;
|
||||
private bool trackActive;
|
||||
private bool thumbActive;
|
||||
|
||||
public override bool HitTest(Vector2 mouse)
|
||||
{
|
||||
return Contains(SliderInteractionBounds(), mouse);
|
||||
}
|
||||
|
||||
public override void UpdateHover(Vector2 mouse)
|
||||
{
|
||||
thumbHovered = Contains(ThumbInteractionBounds(), mouse);
|
||||
trackHovered = !thumbHovered && Contains(TrackInteractionBounds(), mouse);
|
||||
IsHovered = trackHovered || thumbHovered;
|
||||
}
|
||||
|
||||
public void Drag(Vector2 mouse)
|
||||
{
|
||||
var track = TrackBounds();
|
||||
|
|
@ -463,6 +518,8 @@ internal sealed class DebugUi
|
|||
|
||||
public override void Click(Vector2 mouse)
|
||||
{
|
||||
thumbActive = Contains(ThumbInteractionBounds(), mouse);
|
||||
trackActive = !thumbActive && Contains(TrackInteractionBounds(), mouse);
|
||||
Drag(mouse);
|
||||
}
|
||||
|
||||
|
|
@ -482,7 +539,11 @@ internal sealed class DebugUi
|
|||
ID2D1SolidColorBrush primaryBrush,
|
||||
ID2D1SolidColorBrush quietBrush,
|
||||
ID2D1SolidColorBrush accentBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush)
|
||||
ID2D1SolidColorBrush accentHoverBrush,
|
||||
ID2D1SolidColorBrush accentActiveBrush,
|
||||
ID2D1SolidColorBrush dimAccentBrush,
|
||||
ID2D1SolidColorBrush trackHoverBrush,
|
||||
ID2D1SolidColorBrush trackActiveBrush)
|
||||
{
|
||||
DrawRow(target, rowBrush, rowBrush, rowBrush, outlineBrush);
|
||||
target.DrawText(Label.ToUpperInvariant(), format, LabelBounds(), accentBrush, DrawTextOptions.Clip);
|
||||
|
|
@ -491,11 +552,16 @@ internal sealed class DebugUi
|
|||
var track = TrackBounds();
|
||||
var t = ReadNormalized();
|
||||
var fill = RectFromEdges(track.Left, track.Top, track.Left + (track.Right - track.Left) * t, track.Bottom);
|
||||
target.FillRectangle(track, IsActive ? activeRowBrush : IsHovered ? hoverRowBrush : dimAccentBrush);
|
||||
target.FillRectangle(fill, accentBrush);
|
||||
var isTrackActive = IsActive && trackActive;
|
||||
var isThumbActive = IsActive && thumbActive;
|
||||
var isTrackLit = trackHovered || isTrackActive;
|
||||
var trackBrush = isTrackActive ? trackActiveBrush : isTrackLit ? trackHoverBrush : dimAccentBrush;
|
||||
var fillBrush = isTrackActive ? accentActiveBrush : isTrackLit ? accentHoverBrush : accentBrush;
|
||||
target.FillRectangle(track, trackBrush);
|
||||
target.FillRectangle(fill, fillBrush);
|
||||
var thumbX = fill.Right;
|
||||
var thumbRadius = IsActive ? 5.5f : IsHovered ? 5.0f : 4.0f;
|
||||
target.FillRectangle(RectFromEdges(thumbX - thumbRadius, track.Top - thumbRadius, thumbX + thumbRadius, track.Bottom + thumbRadius), accentBrush);
|
||||
var thumbBrush = isThumbActive ? accentActiveBrush : thumbHovered ? accentHoverBrush : accentBrush;
|
||||
target.FillRectangle(RectFromEdges(thumbX - ThumbRadius, track.Top - ThumbRadius, thumbX + ThumbRadius, track.Bottom + ThumbRadius), thumbBrush);
|
||||
}
|
||||
|
||||
private Rect TrackBounds()
|
||||
|
|
@ -511,6 +577,20 @@ internal sealed class DebugUi
|
|||
var track = TrackBounds();
|
||||
return RectFromEdges(track.Left - 8.0f, Bounds.Top, track.Right + 8.0f, Bounds.Bottom);
|
||||
}
|
||||
|
||||
private Rect TrackInteractionBounds()
|
||||
{
|
||||
var track = TrackBounds();
|
||||
return RectFromEdges(track.Left - 4.0f, Bounds.Top, track.Right + 4.0f, Bounds.Bottom);
|
||||
}
|
||||
|
||||
private Rect ThumbInteractionBounds()
|
||||
{
|
||||
var track = TrackBounds();
|
||||
var thumbX = track.Left + (track.Right - track.Left) * ReadNormalized();
|
||||
var centerY = (track.Top + track.Bottom) * 0.5f;
|
||||
return RectFromEdges(thumbX - ThumbHitRadius, centerY - ThumbHitRadius, thumbX + ThumbHitRadius, centerY + ThumbHitRadius);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FloatSliderControl(
|
||||
|
|
|
|||
Loading…
Reference in a new issue