On 6/12/13 8:14 PM, Scott Rossi wrote:
Has anyone created a routine that will truncate text in a field to given
pixel width, and append ellipses?

I found one that limits text based on character count, but I'm looking to
limit based on available space.

I did this ages ago, like back in MC. I used a real field, but now that I know better I'd use the templatefield instead. It's ugly, but since you can only measure text width from a field, you have to loop. The pseudocode is something like:

store the original text somewhere for reference later
put it into a field
repeat until the formattedwidth of the text is <= the column:
  delete last char of the field
  put "..." into last char of the field
end repeat

Even with a "real" field it was still pretty fast. Probably would be faster with the templatefield. The "..." isn't three periods, it needs to be the real elipsis character so that the "last" character includes all three visual dots.

--
Jacqueline Landman Gay         |     jac...@hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to