Message Box - Adapting Font size to Text

KRAWALI's icon

Hey there,

I am displaying some text in an M4L device using a message box. However, when the text is too large, the text wraps into a second line and the size of the message box increases. Is there a way to essentially fix the message box size and instead have the font size of the text decrease to fit the longer text?

Or is there another object I should be using instead of message?

Thanks and Best,
Karan

double_UG's icon

there is live.comment, comment, textedit, (but there is no auto textsize) or you can calculate the text size

Max Patch
Copy patch and select New From Clipboard in Max.

11OLSEN's icon

I don't think you can measure text just by counting the characters unless you use a monospace font.
A better way is to use JSUI for example using the sketch text methods.

KRAWALI's icon

Thanks 11OLSEN, that is actually the problem I ran into using since I am using Futura and I couldn't really get a useful calculation that works for different texts. JSUI seems interesting but I think my programming knowledge is a little too basic to make this work on my own. Here is a quick description of what I would like to achieve:

I have this device that displays the selected scene, the previous and the two after it. At the moment my workaround is to just let the text "overflow" which works fine but I guess it would just be a bit nicer if the full text would be displayed. However, I would not like the text to be outside the gray panel, so I would like it to adapt (resize, wrap) to fit in it.

I am guessing there is no simpler way than JSUI to achieve this, right?

TFL's icon

I can't think of a simpler way either.
You can either work with Sketch as @11OLSEN proposed and use gettextinfo the size of the rendered text, or use MGraphics API with text_measure(text) to get the same result.
Then it's a matter of comparing the text's length to the available space on your device (for example by getting devicewidth), then if the text is too big, scale it using glscale (or scale for MGraphics).

11OLSEN's icon

Is it super important for you that the full text is visible? [textbutton] can auto truncate text. [message] will auto wrap but you would have to preserve space below the message box for the 2nd line.

Max Patch
Copy patch and select New From Clipboard in Max.

KRAWALI's icon

Thanks 11OLSEN, that is a good option to have, thanks! However I think am this point I'd rather just stick to the Scene names "overflowing" since I'd rather have the name cut off than losing space to the ".." - but thanks again for your help!