Skip to content

Commit

Permalink
Adjust wheel peek wrap based on aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
ZachHembree committed Mar 24, 2022
1 parent 4d2f464 commit 2ccc84c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ protected override void Layout()

summaryLabel.Size = new Vector2(maxPeekWrapWidth - wheelBodyPeekPadding);

// Dynamically reduce wrap with while peeking based on aspect ratio
if (MenuState == QuickActionMenuState.WheelPeek)
{
Vector2 lastTextSize = summaryLabel.TextBoard.TextSize;

// If the text is substantially wider than tall, reduce wrap width
if (lastTextSize.X > 1.2f * lastTextSize.Y)
summaryLabel.Width = Math.Max(.5f * (lastTextSize.X + lastTextSize.Y), minPeekWrapWidth);
}

// Dynamically resize background and label to accomodate text
Vector2 textSize = new Vector2(summaryLabel.TextBoard.TextSize.Length());
textSize.Y += notificationText.Height;
textSize = new Vector2(Math.Max(textSize.X, textSize.Y));
Expand All @@ -190,11 +201,11 @@ protected override void Layout()
if (MenuState == QuickActionMenuState.WheelPeek)
{
// Don't bother resizing for small changes
if (Math.Abs(textSize.X - lastWidth) < 10f)
if (Math.Abs(textSize.X - lastWidth) < 15f)
textSize = new Vector2(lastWidth);

Size = textSize + Padding;
summaryLabel.Height = textSize.Y - notificationText.Height;
summaryLabel.Size = new Vector2(textSize.X, textSize.Y - notificationText.Height);
}

if ((background.Size - Size).LengthSquared() > 4f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public static readonly GlyphFormat
private const int textTickDivider = 4;
private const int maxEntryCharCount = 33;
private const double floatPropLogThreshold = 1E6;
private const float maxPeekWrapWidth = 270f,
private const float maxPeekWrapWidth = 270f,
minPeekWrapWidth = 190f,
wheelBodyPeekPadding = 43f,
wheelBodyPadding = 90f;
}
Expand Down

0 comments on commit 2ccc84c

Please sign in to comment.