Jump to content

Limiting text width and height


themoonrat
 Share

Recommended Posts

With the Text class, you can choose to turn on and off word wrapping after a certain length, but what I require is to be able to limit the width and/or height of text. If I have a button of a certain size, I want the text 'Bob' to fit in it's natural size, and the text 'BobBobBobBobBobBob' to scale down to fit within this button.

Scenario 1: Limiting width. This is actually quite easy, with word wrapping off, because after drawing the text, if the canvas width exceeds how wide I want it to be, I can just scale it down.

Scenario 2: Limiting height. Now, in this scenario, word wrapping is on, so it's already wrapping at the appropriate width. However, I can't use the above method to scale the resulting canvas, because then the width would also be reduced, and I don't want that. 

I do have a very hack solution to these scenarios. Hack on scenario 1 requires checking in renderWebGL if I've scaled down due to limiting width, and if so record some variables so that if I scaled it up and down via .scale things still work. Hack on scenario 2 involves recursively calling updateText with smaller text sizes until it fits within the correct height! Ouch

Wondered if anyone had thought about this before and come across any better solutions?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...