Author Topic: Assign fe.Text instance charsize property dynamically?  (Read 6662 times)

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Assign fe.Text instance charsize property dynamically?
« on: November 28, 2015, 07:41:07 AM »
Hi all,

Here's my (latest) question: if I have a text field that, at a given charsize, would get clipped, is there a flag or property that gets set somewhere that informs me of, say, the number of lines or soft carriage returns? That might not be the right way to phrase it, so here's what I want to happen:

If I have a string of text that wouldn't fit in a text instance (let's say I have a text field 1000 pixels wide; the text I want to assign to its msg property would take up 1200 pixels at a given charsize), is there any way to know, programmatically, when I'm out of bounds, visually? I want to recursively reduce the charsize until all the text fits within the available space, but I'd need to know when I'm back under the maximum width. In the way that fe.Text.width refers to the assigned width of the text instance, is there any internal value that lets me know what the actual width of the text is? Similar, I guess, to fe.Image.texture_width.

Clear as mud? Maybe pictures will help (they help me all the time!):

Uncorrected. This is what an overlong game title would look like:


Corrected. This is what I want to achieve programmatically:


Any thoughts? As always, thanks!

Edit: I just now noticed the scrollingtext module, and buried in there is code that would potentially work. Holy crap there's a lot of stuff under the hood there! :( Wow...
« Last Edit: November 28, 2015, 07:50:42 AM by Bgoulette »

liquid8d

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 442
    • View Profile
Re: Assign fe.Text instance charsize property dynamically?
« Reply #1 on: November 28, 2015, 11:14:11 AM »
Yes, unfortunately there is no way to do measureText - you can leave it to autoresize, but doesn't address the overflow which is why I did the scrolling text module.

There is a lot of stuff in there, I tried to allow for a lot of scenarios :) but basically it does kind of what we did with the other stuff - add a surface, add a text object to the surface then move the text object x/y values to scroll using onTick.

You could do a simple scrolling text, but it's still tricky since you don't know exactly how long the text will be.

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: Assign fe.Text instance charsize property dynamically?
« Reply #2 on: November 29, 2015, 05:12:58 PM »
I was afraid of that ;) Do you know if there's anyway to tell when AM wraps lines? If I could test for that, I could accomplish the same thing: just recursively reduce point size until no word wrap occurred...

raygun

  • Administrator
  • Sr. Member
  • *****
  • Posts: 393
    • View Profile
Re: Assign fe.Text instance charsize property dynamically?
« Reply #3 on: December 03, 2015, 11:32:45 PM »
I'm going to be adding a way to get the width of a text soon (I'm just testing now).  So in the next version there will be a way to do exactly what you are asking about here Bgoulette

Bgoulette

  • Sr. Member
  • ****
  • Posts: 116
  • I wrote a book.
    • View Profile
    • BlakeGoulette.com
Re: Assign fe.Text instance charsize property dynamically?
« Reply #4 on: December 04, 2015, 05:10:47 AM »
I'm going to be adding a way to get the width of a text soon (I'm just testing now).  So in the next version there will be a way to do exactly what you are asking about here Bgoulette

That's great to hear! As I've stated in some of my prior posts, I (used to!) know ActionScript pretty well, but not so much Squirrel, so I keep thinking in terms of what I could do with AS. Someday, I hope to wrap my head around Squirrel's intricacies more in-depth. I'm enjoying AM and I'd love to be able to contribute in some small way.