Author Topic: UITooltip and incorrect text size  (Read 1683 times)

Yukichu

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 8
  • Posts: 101
    • View Profile
UITooltip and incorrect text size
« on: July 14, 2014, 09:37:31 AM »
So I made a UITooltip and it works wonderfully other than it thinks the text is some weird size compared to what it actually is, causing the background box to be too slim and too tall.  After much brainpower spent, I also realized there were some other on-the-fly type options I wanted for the tooltip, so I ended up adding:

  1.     static public void ShowText(string tooltipText, NGUIText.Alignment align, UILabel.Overflow overflow, Vector4 offset, int width = 0)
  2.     {
  3.         if (mInstance != null)
  4.         {
  5.             mInstance.text.overflowMethod = overflow;
  6.             mInstance.text.alignment = align;
  7.             if (width != 0)
  8.                 mInstance.text.width = width;
  9.             mInstance.SetText(tooltipText, offset);
  10.         }
  11.     }

and I overloaded SetText with

  1.     protected virtual void SetText(string tooltipText)
  2.     {
  3.         SetText(tooltipText, Vector4.zero);
  4.     }
  5.  
  6.     protected virtual void SetText(string tooltipText, Vector4 offsetBorderSize)
  7.         {
  8. ...
  9.                         if (background != null)
  10.                         {
  11.                                 Vector4 border = background.border + offsetBorderSize;
  12.  
  13.  

Granted I'm no code genius, but it lets me set the tooltip's label overflow and alignment to be different as needed, the width of the tooltip when needed, and pad the sides of the background box as needed.

It works great.  I am sure the border thing isn't working 100% as desired, but it works so far.

So the question is, could this be added?  I tried extending the class, but using the static method and mInstance was giving me fits and rather than figure it out I just went with this approach.

Regardless of my lack of knowledge of how to do it properly, having a more customized version of setting the UITooltip text is helpful.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITooltip and incorrect text size
« Reply #1 on: July 15, 2014, 12:33:33 AM »
The tooltip script is just an example. I don't think I've ever once used it outside of NGUI's examples myself in any of my projects. I would always create a custom one instead because there is almost always more than just the single label that needs to be displayed. For example in Windward I display not only the item description text, but also the item's title (in another font), as well as the item's icon. I wrote a custom tooltip script to handle that.

Yukichu

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 8
  • Posts: 101
    • View Profile
Re: UITooltip and incorrect text size
« Reply #2 on: July 15, 2014, 08:45:02 AM »
Thanks, that explains it perfectly. 

I'll just write my own for the functionality I need.  Thanks!