Skip to content

Add TextScale property to ToolTip #2702

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 21 additions & 5 deletions Assets/Scripts/Game/UserInterface/ToolTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,25 @@ public class ToolTip : BaseScreenComponent
string lastText = string.Empty;
bool previousSDFState;

float textScale = 1.0f; // scale text

#endregion

#region Properties

/// <summary>
/// Set text scale factor - 1.0f is default value, 0.5f is half sized text, 2.0f double sized text and so on
/// </summary>
public float TextScale
{
get { return textScale; }
set
{
textScale = Math.Max(0.1f, value);
// Draw();
}
}

/// <summary>
/// Gets or sets font used inside tooltip.
/// </summary>
Expand Down Expand Up @@ -141,8 +156,8 @@ public void Draw(string text)

// Set tooltip size
Size = new Vector2(
widestRow + LeftMargin + RightMargin,
font.GlyphHeight * textRows.Length + TopMargin + BottomMargin - 1);
(widestRow + LeftMargin + RightMargin) * textScale,
(font.GlyphHeight * textScale) * textRows.Length + TopMargin + BottomMargin - 1);

// Set tooltip position
Position = Parent.ScaledMousePosition + MouseOffset;
Expand Down Expand Up @@ -188,15 +203,16 @@ public override void Draw()
Rect rect = Rectangle;
Vector2 textPos = new Vector2(
rect.x + LeftMargin * LocalScale.x,
rect.y + TopMargin * LocalScale.y);
rect.y + TopMargin * LocalScale.y
);

//if (rect.xMax > Screen.width) textPos.x -= (rect.xMax - Screen.width);

// Draw tooltip text
for (int i = 0; i < textRows.Length; i++)
{
font.DrawText(textRows[i], textPos, LocalScale, textColor);
textPos.y += font.GlyphHeight * LocalScale.y;
font.DrawText(textRows[i], textPos, (LocalScale * textScale), textColor);
textPos.y += font.GlyphHeight * (LocalScale.y * textScale);
}

// Lower flag
Expand Down