playMaker

Author Topic: Action for Auto-truncating NGUI Label Text?  (Read 8615 times)

memetic arts

  • Full Member
  • ***
  • Posts: 141
Action for Auto-truncating NGUI Label Text?
« on: April 27, 2013, 02:31:10 PM »
Hi folks -

Subject line says it all . . . any kind soul out there put this together already?  I can't say it's a "high" priority on my list, but definitely a nice-to-have. 

Basically needed for displaying track/album titles in the titlebar area . . . without truncation I'm forced to display a static string like "Albums" rather than dynamic display of the actual album itself.

If it hasn't been done, it might be my entre~ into the custom-action-creation world . . . just a little pressed for time

Thanks in advance . . .

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for Auto-truncating NGUI Label Text?
« Reply #1 on: April 29, 2013, 03:31:11 PM »
Hi,

 by "auto truncating", do you mean the "max width" setting available on UILabel? I am not sure I can find what you are looking for exatly, that kind of set up is likely done during editing time, using just ngui, not at runtime. I might miss something obvious, if you could point me to a sample, that wold help me. thanks.

bye,

 Jean

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: Action for Auto-truncating NGUI Label Text?
« Reply #2 on: April 30, 2013, 11:59:10 AM »
Hey Jean, thanks for the reply.

It's definitely a runtime thing, since I'm dealing with dynamically-generated labels, populated with pre-existing content that needs to be displayed in multiple Views (so in some cases it would be possible to fit the entire label, and in others not) . . . The function / action would basically, examine a string, and if the length exceeds N number of characters, remove all characters beyond the cutoff point and replace them with ellipses.  So if an entry says "New York City", and the cutoff is set at 7, the display would read "New Yor..."

So in pseudo-code, probably something like
Code: [Select]
function truncate(string, cutoff){
  newString = string.substr(0,cutoff-1) + "...";
  return newString;
}

// function call
truncate("New York City",7);

For practical reference, look at what iOS does in the screenTitle area with song titles when you move from the track listing to a specific track.  Also see Windows Explorer, as you make columns narrower, text gets truncated.  In this case, if you mouseover the text, you also get a tooltip displaying the complete string.  I don't really need that (though would be a nice feature).

Make sense?

Thanks again!

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: Action for Auto-truncating NGUI Label Text?
« Reply #3 on: April 30, 2013, 12:17:42 PM »
Ha, and you know what?  I just went back and re-read the spec on max width, and I see what you are saying now . . . so yes, I guess it is in fact covered there, but sans ellipses, which IMHO, from a UX standpoint, are a necessary indicator.  So it's almost right, but not quite. . . so maybe this is more in need of just a quick little script to append the ellipses rather than a full blown action . . .

Thanks for pointing out the max width property, I'd completely missed that!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for Auto-truncating NGUI Label Text?
« Reply #4 on: May 01, 2013, 06:24:07 AM »
Hi,

 Have you contacted Tasharen, I would think that if you request this to be implemented within ngui, this makes more sense, as it's obviously something that should be handled at that level. the problem with counting chars is that if chars are of different lengths it will never look right...

WWWWWWWWWW
1111111111

 both 10 chars different visual lengths. you can't compute ellipse this way, and computing real pixel lengths is a beast to tackle...

bye,

 Jean

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: Action for Auto-truncating NGUI Label Text?
« Reply #5 on: May 01, 2013, 09:47:26 AM »
Hi -

Yes, was realizing as I wrote the last post that I should probably reach out to them, tho I'm sure Aren has bigger fish to fry . . . still might be worth a shot, might be considered "low hanging fruit", as it were . . .

Good point about char counting, you're absolutely right . . . that's why we like Verdana.   ;)

Thx again,

==rr

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Action for Auto-truncating NGUI Label Text?
« Reply #6 on: May 02, 2013, 01:34:59 PM »
Hi,

 Make sure you make a post on the ngui forum, someone has probably a mods or something, and every author I am sure really count on user feedback, so never fear requesting things, and for sure your request is indeed important.

bye,

 Jean

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: Action for Auto-truncating NGUI Label Text?
« Reply #7 on: May 03, 2013, 03:48:39 PM »
point taken, will do!!

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: Action for Auto-truncating NGUI Label Text?
« Reply #8 on: May 14, 2013, 03:19:42 PM »
So I posted the request over in the NGUI forum.

Response from ArenMook was thus:

"I advise using the "shrink to fit" option instead."

Of course there are a number of reasons why this is not a good idea, but I understand, the guy's got his priorities . . . and I can probably find a way to handle this via script anyway . . .
« Last Edit: May 14, 2013, 03:21:47 PM by memetic arts »

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Action for Auto-truncating NGUI Label Text?
« Reply #9 on: May 14, 2013, 03:39:43 PM »
Plenty of use for truncating text, seems odd they would not be interested in at least entertaining the idea of adding it. The shrink thing literally squishes it, right?

Hypothetically it could be 20 characters, like "Melbourne, Australia" or something even longer where stretching is not feasible in small areas unless you want it to look like llllllllllll. There are tons of applications for that kind of functionality, maintaining aspect ratio is very important for text.

I'm not sure how the integration into NGUI works but I seem to remember glancing over some string actions that you could use to replace it dynamically on the fields you know can't be very long... I don't really like the idea of doing it that way. I'll look into it later and see if it's actually like I think it is.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

memetic arts

  • Full Member
  • ***
  • Posts: 141
Re: Action for Auto-truncating NGUI Label Text?
« Reply #10 on: May 14, 2013, 09:49:20 PM »
@Lane - To be clear (and fair!), NGUI does support truncation.  Admittedly, in my original post, I didn't realize this until Jean Fabre pointed it out. 

My issue, however, is that it just does that -- truncates the text -- whereas best practice in UX/Usability warrants the inclusion of ellipses to indicate that the text has, in fact, been truncated.

And yeah, the shrink-to-fit feature does just that -- reduces the font size so that the entire string is displayed within the allotted area, which to me seems entirely useless in mobile phone contexts.

But no biggie . . . as I said, I think I can work it out with a script, and maybe, if I'm feeling brave, a Custom Action.  Haven't tried creating one of those yet, might be time to try . . .

Cheers,

==rr