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

2 Comments:

  • Did you think about using the .nib files that Interface Builder generates?

    I think they are xml, so yes they would require parsing, but if I had to choose an existing UI building tool to be compatible with, Interface Builder would win hands-down!

    By Anonymous Sam Deane, at 1:08 AM  

  • I just took a look at IB's .nib format. It creates 3 sub-files, classes.nib wich is some text format but not xml, info.nib which is xml but looks like info for IB itself, and keyedobjects.nib, which seems to contains object info, but is a binary file. I read that IB uses the Coder protocol to store the objects, and that would probably store data in binary. Unless there is a need to use IB to create UIs in Inertia, I'll stick with the current format. Plus, I hope to create an IB like tool in Inertia anyway. :)

    By Blogger Mike Austin, at 11:03 AM  

Post a Comment

<< Home