how to determine width of text?

Hi,

I know how to make text fit to the size of a button, but how do I make a button (or a text top) fit to the size of the text it contains, so the text size remains constant and the top size adapts to that?

tx
d

not sure if this helps but… i used this before, i forgot where. In the text:TOP, for Custom Res X use:

strlen(pars(“./text”))*par(“./fontsizex”)

multiply font size, and length of string and puts it as the total resolution. U should subtract out how many resolution u want deleted from there.

oh nm. doesn’t work. eheheh dani said it won’t and it doesn’t since letter widths are all different… i’ll go back to noob section, woot.

I’ll bring this to the forefront again…

I have a text TOP I want to size (within certain screen limitations) to encompass the length of some arbitrary text.

Anyway to get at that information to know what my x resolution would have to be given some text?

thanks,
dani

Hey Dani,

for that use the text(“string TOP”, string attribute) expression which returns width and height of the text based on the font settings of that text TOP.

cheers
markus

1 Like

For anyone stumbling across this from google, the textTop has a textWidth and textHeight member you can use.

For example, to set the width of something to the width of the text plus 20 pixels, you could use the following expression: op('./text1').textWidth + 20.

Related docs: textTOP Class - Derivative

4 Likes