User resize

danieleghisi's icon

Is there a way, in a UI, to catch the user resizing of an object? Is there a method which is called automatically when the user resizes the object in the patch? (without checking dimensions with a flag in the paint method?)

Thank,
Daniele

Emmanuel Jourdan's icon

You can define an oksize method for that, in your main()

class_addmethod(c, (method)yourobject_oksize, "oksize", A_CANT, 0);

It has the following signature:

long yourobject_oksize(t_yourobject *x, t_rect *newrect)

you can just mess with the newrect->width and newrect->height.

If 1 is returned, the object size will be checked afterward to make sure it fits the min/max again.

danieleghisi's icon

Thanks emmanuel.
Is it called only when the user is resizing it a screen? Cause I'm resizing the object too, sometimes, from the code: should I then put a flag to understand whether it's me or the user?

thanks again,
Daniele

Emmanuel Jourdan's icon

It's called whenever the object is resized. You probably want to store a flag in your object structure to avoid loops. It's also called when you create the object, and probably other situations.