So I want to start with describing how my UI engine works. It's not finished, and this post is definitely not a 'here's how I solved this problem' thing. It's more of a 'struggles of a person, writing their first UI engine'. So here goes.
I come from the world of web programmin. So my view of how layout engine should work was influenced by css and html. The idea of specifying the UI with a set of rules, that are later resolved by an engine to draw the UI makes sense. It really is how I would describe an interface layout: