Skip navigation.
 
mlRe: Why initialize the menubar without Interface Builder
FROM : Robert Nikander
DATE : Sun Nov 04 00:26:07 2007

On Nov 3, 2007, at 3:39 PM, Erik Buck wrote:

> There is a current discussion "Re: Initializing the menubar without 
> Interface Builder."  What I desperatly want to know is WHY ?



Do you mean that I need to explain why I "think different"? :)

Seriously, let me try to answer your question.  For me, I usually 
find it easier and more powerful to work with code-defined GUIs, but 
in order to do this I need two things that don't exist in all GUI 
libraries, and don't seem to exist by default with Cocoa.  I'll 
explain those two things below.  Let me just say, I do *not* want to 
define a GUI like this:

    button = new Button();
    button.X = 231;
    button.Y = 54;
    panel.add( button );
    ...

where I manually specify coordinates and dimensions.

The two things I need are:

1. "Layout managers", or whatever you want to call them.
2. A way to use declarative language.

If these things are not present, then building them can be more 
trouble than it's worth.  But in my case, I don't mind building them, 
and I am working on connecting Cocoa to another language (Scheme), 
which will give me #2.

For #1, when I say "layout managers" (a term from the Java GUI 
libraries), I mean that you can create GUI components that manage the 
geometry of their child components in high-level ways.  For example, 
HTML works like this -- you define a "table" or "div", and set styles 
like borders, but you don't worry about making a button wide enough 
to fit it's text, because that is handled automatically.  Code might 
look like:

    panel = new VerticalPanel();
    panel.borderWidth = 5;
    panel.add( new Button("OK") );
    panel.add( button2 );
    ...

Other layouts might include a horizontal panel, and grid/table.

For #2, I mean that you do not use "imperative" code to specify the 
exact order of building the GUI, like I did in the example above. 
Instead, the code looks more like HTML, where you simply declare the 
structure of the GUI.  You could use XML, but I prefer Lisp/Scheme, 
so it looks something like this:

    (vertical-panel
      (border 5)
      (button (text "OK") (on-click do-such-and-such))
      (button (image "/a/b/thing.png"))
      (drop-down-list
        (items "Apple" "Banana" "Orange")))

Now, if I decide that I want a fatter border, I find it just as easy 
to change the "5" to an "8" as it is to open IB and drag something 
around.

Going further, I can use variables in the definition of the GUI, and 
make things more abstract than is possible with IB.  For example, I 
could define a variable 'dialog-border-width' and use it in the 
definitions of all the dialogs.

(define dialog1
    (vertical-panel
      (border dialog-border-width)
      ...

Then I can change "dialog-border-width" in one place and change all 
the dialogs.

Rob

Related mailsAuthorDate
mlWhy initialize the menubar without Interface Builder Erik Buck Nov 3, 20:39
mlRe: Why initialize the menubar without Interface Builder Uli Kusterer Nov 3, 22:06
mlRe: Why initialize the menubar without Interface Builder Fritz Anderson Nov 3, 22:44
mlRe: Why initialize the menubar without Interface Builder Uli Kusterer Nov 4, 00:15
mlRe: Why initialize the menubar without Interface Builder Robert Nikander Nov 4, 00:26
mlRe: Why initialize the menubar without Interface Builder Sherm Pendley Nov 4, 00:49
mlRe: Why initialize the menubar without Interface Builder Erik Buck Nov 4, 01:55
mlRe: Why initialize the menubar without Interface Builder Erik Buck Nov 4, 02:10
mlRe: Why initialize the menubar without Interface Builder Jon Hess Nov 4, 02:18
mlRe: Why initialize the menubar without Interface Builder Chris Hanson Nov 4, 02:38
mlRe: Why initialize the menubar without Interface Builder Chris Hanson Nov 4, 02:45
mlRe: Why initialize the menubar without Interface Builder Robert Nikander Nov 4, 03:06
mlRe: Why initialize the menubar without Interface Builder Erik Buck Nov 4, 03:15
mlRe: Why initialize the menubar without Interface Builder Rob Keniger Nov 4, 04:29
mlRe: Why initialize the menubar without Interface Builder Uli Kusterer Nov 4, 12:33
mlRe: Why initialize the menubar without Interface Builder Uli Kusterer Nov 4, 13:06
mlRe: Why initialize the menubar without Interface Builder Jon Hess Nov 5, 19:55
mlRe: Why initialize the menubar without Interface Builder John Labovitz Nov 5, 20:11
mlRe: Why initialize the menubar without Interface Builder Jon Hess Nov 5, 20:15