Chris Anderson discusses how to implement a custom layout engine and gives sample code in an article on gotnetdot.com.