Mike Austin's Blog

Sunday, November 06, 2005

Building ui hierarchies from a file

I looked at XML, YAML and a bunch of others [XML Alternatives] to do simple object persistence. But in the end, I'd have to create a binding (for Dylan) and learn the api, or use XML, so I borrowed the format for Borland's C++ Builder and tweaked it a bit. It only takes around 50 lines of code to read in and create the ui hierarchy.
let window = make (<window>, caption: "Window 1",
width: 600.0, height: 400.0);
build-hierarchy (window, "test.ui");

test.ui
-------
shape-left: 10
shape-top: 10
object button: <push-button>
caption: "It's Alive!"
shape-left: 10
shape-top: 10
end