Author Topic: Text spacing, y u no float?  (Read 7834 times)

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Text spacing, y u no float?
« on: October 09, 2014, 08:36:14 AM »
Hey!

So I want to animate the text spacing of a label, to make it fold out, like an accordion.
This works, but it moves in visible steps, because text spacing is not set as floats but ints.

I managed to get around this by changing UILabel, so it exposes text spacing as a float.
It does use float when setting the text spacing internally anyway.

However, I really don't like having to change the NGUI source code, since I'll have to do it for every update.
I realize that you can't just change the spacing to float in the next NGUI, since it won't use the old serialized spacing that was saved as an int. Right?

Is there by any chance, a way that NGUI could add this functionality, without breaking anything?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Text spacing, y u no float?
« Reply #1 on: October 10, 2014, 02:26:21 AM »
Problem with using a float is that it means the label won't be pixel-perfect anymore. Characters can't snap to pixels if you're not using whole integers.

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: Text spacing, y u no float?
« Reply #2 on: October 14, 2014, 03:05:40 AM »
Thanks for the reply, I can see your point.

Yet it seems to be jumping several pixels, even with a pixel perfect label.
I made a demonstration:
https://dl.dropboxusercontent.com/u/4375689/Web/LabelSpacing/LabelSpacing.html

I would like to propose a solution for this, that would allow me to animate it using a floating point values.
You could have an option on UILabel for overriding text spacing using a float.
And then add extra x and y properties as floats to the label, that will be used instead of the integer ones, if this option is selected.

I realize that I might be the only person in the world with this problem, so it might not be worth the trouble for you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Text spacing, y u no float?
« Reply #3 on: October 14, 2014, 02:25:04 PM »
They are jumping several pixels because you have many of them. "New Label" contains 9 characters, so the left-most letter is moved 9 pixels for every pixel adjustment.

I will have a look at what's involved in making it work with floats and see if I can add a way to do it without breaking backwards compatibility.

AGB

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 74
    • View Profile
    • Steam Defense
Re: Text spacing, y u no float?
« Reply #4 on: October 14, 2014, 04:49:27 PM »
Here is a youtube video with spacing X changed to float from int:
https://www.youtube.com/watch?v=zdVVs9rfDJ4&list=UULGT_riOOLDvcWRsBviCQAw
(at 0:20)

Actually it is only place, where i was using this spacing at all, so i dont mind, that it is always in float :)
I'm a busy man... I have places to go,monsters to kill...

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: Text spacing, y u no float?
« Reply #5 on: October 15, 2014, 07:52:33 AM »
@AGB Looks like you could really benefit from using float! :D

@ArenMook That actually makes perfect sense when I think about it. If you want, I can also look into it and have Nicki (moderator) send a pull request with my changes. We work at the same company.
« Last Edit: October 15, 2014, 07:58:08 AM by mathiassoeholm »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Text spacing, y u no float?
« Reply #6 on: October 16, 2014, 06:26:01 AM »
Sure, sounds good.

mathiassoeholm

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 4
  • Posts: 35
    • View Profile
Re: Text spacing, y u no float?
« Reply #7 on: October 17, 2014, 09:14:22 AM »
There should be a pull request now :-)