PDA

View Full Version : Getting the size of a windowcontrol on initialize



phantomwhale
April 2nd, 2012, 10:46
Been bashing me head at an issue of getting the size of a control during it's onInit() method.

the getSize() method always returns 0,0 until after initialize, and there is no event for me to hook into like "once everything is initialized and has got it's size determined" ! (or is there ?)

One workaround has been to "cheat" and do the following :


local controlwidth, controlheight = getSize()
if controlwidth == 0 or controlheight == 0 and anchored and anchored[1] and anchored.size and anchored.size[1] then
controlwidth, controlheight = tonumber(anchored[1].size[1].width[1]), tonumber(anchored[1].size[1].height[1]);
end

But this obviously relies on the control having a size and height defined - which in my case it didn't (it uses a left and right anchor) but I can define one just for the purpose of getting the workaround working.

So is there any event or trick I can use to redraw a window control as soon as it's getSize() method is going to return non-zero numbers ?

Zeus
April 2nd, 2012, 12:02
Ahh this one caused me lot of pain too in the past. No real way of getting around it unless you approach it as per your workaround example above or rework your sheet to use a sub window so that you can hook into onSubwindowInstantiated() - which is called immediately after onInit ;)

You can then make a call to update the size of the control within onSubWindowInstantiated. As onSubWindowInstantiated is called immediately after onInit, getSize() will return the correct control dimensions.

phantomwhale
April 3rd, 2012, 02:18
Ha - I'm not going near subwindows if I can help it - they always come back to bite me !

Glad to hear I've at least got it as far as I can with the existing ruleset. Might move the "get window size" hack into a utility class, as I use it in a few places.

And then I can wait patiently for this little feature : https://fg2app.idea.informer.com/proj/?ia=46655
(feel free to vote if this would help you too !!!)