Following http://limpet.net/mbrubeck/2014/08/08/toy-layout-engine-1.html in Scala