Fixed panel auto sizing

It was incorrect before. Also now it doesn't create vector objects every
time it works it out.