Set preferredMaxLayoutWidth based on an initial layout pass instead of hardcoding it

This method is somewhat less efficient as it requires a second layout
pass once the preferredMaxLayoutWidth is set on multi-line labels,
however it is much more flexible and generic and can scale to
arbitrarily complex layouts that would be very difficult to determine
the correct preferredMaxLayoutWidth value manually.

Also did some minor code cleanup here and there.