textfield

danieleghisi's icon

Hallo,
I'm using a textfield for the first time.
I learnt from the examples how to get the text, set margins, set colors..., but I couldn't find a way to set the text font size from code.

Is there a command like
object_method(textfield, gensym("setfont"), &newfont);
or which is the way to do that?

BTW: is there a way to "lock" the text, and to have it editable only after keydown? I'd like to do exactly how it appens in [flonum] or [number], where the cursor on mouseover is the usual arrow cursor...

Thanks a lot!
Daniele

Timothy Place's icon

You might want to check out the functions in jpatcher_api.h, such as textfield_set_noactivate().

There is also some more example code @ http://github.com/jamoma/JamomaModular/blob/master/implementations/MaxMSP/jcom.textslider/jcom.textslider.cpp -- not sure if this will be relevant for you or not.

The font for a textfield comes from the textfield's owner's box. If you need more flexibility, you can use a jtextlayout object. Some example code using a jtextlayout can be found @ http://github.com/jamoma/JamomaModular/blob/master/implementations/MaxMSP/jcom.paramui/jcom.paramui.cpp -- the part specifying the font is down at line 398.

Cheers!

danieleghisi's icon

Thanks Timothy.

I've always used the jtextlayout objects, but this makes much more complicated to handle the "editing" of the text, doesn't it?

You say that the font for a textfield comes from the textfield's owner's box: I suppose that the textfield's owner is my UI object? Is there no way to change the size of the font of the textfield's owner?

Thanks again!
Daniele

Timothy Place's icon

Hi Daniele,

Yes, the textfield's owner is your UI object. To change the font, you then change the font of the UI object by e.g. using the inspector in Max. You can confirm this by testing the textslider example code of my previous post, which does indeed work this way.

HTH

danieleghisi's icon

Hi Timothy,
thanks again for your patience. I know ho to change the font of my UI object via the inspector, but I'd like to do that from the code (e.g. when the object is user-resized, the text size changes automatically).
In the textslider example, I can't see anything like that in the code (e.g. I can't see anything like that in the oksize method, which could be useful to resize the font with respect to the new object size...)

So maybe it is not possible to change the UI font size from the code?

Thanks again,
Daniele

Luigi Castelli's icon

Hi Daniele,

I would use jbox_set_fontsize() prototyped in jpatcher_api.h

Cheers.

- Luigi

danieleghisi's icon

Ach! Sure!
Thanks Luigi!
Daniele