I'm not sure if there's a good generic way to solve this. But either way, the layout code will probably need further complications to support this smooth transitioning.