Re: Why initialize the menubar without Interface Builder
Re: Why initialize the menubar without Interface Builder
- Subject: Re: Why initialize the menubar without Interface Builder
- From: Robert Nikander <email@hidden>
- Date: Sat, 3 Nov 2007 19:26:07 -0400
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
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden