[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[rgui-dev] simple design issue: question at the end, "All or One?"
From: |
Tom Sawyer |
Subject: |
[rgui-dev] simple design issue: question at the end, "All or One?" |
Date: |
09 Aug 2002 13:10:48 -0600 |
i have a simple question in regards to api syntax when creating widgets:
the simplist syntax option that CAN be used is this:
awindow = GUtopIa::Window.new
awindow.caption = 'Fruit App'
awindow.width = 200
awindow.height = 300
awindow.layout = :grid
awindow.body = [ [ aradio ], [ abutton ] ]
now, i WANTED to do it this way but CANNOT:
awindow = GUtopIa::Window.new {
caption = 'Fruit App'
width = 200
height = 300
layout = :grid
body = [ [ aradio ], [ abutton ] ]
}
due to ambiguity between local variable assignment and wirtter methods
this will not work unless we dirty things up with "self." or similiar
means. even so i have left in the code to do an instance eval, so it CAN
be done this way:
awindow = GUtopIa::Window.new {
self.caption = 'Fruit App'
self.width = 200
self.height = 300
self.layout = :grid
self.body = [ [ aradio ], [ abutton ] ]
}
now, thus far i have also allowed for the optional argument assignment
taken from the orignal utopia api, so you CAN do something like this as
well:
awindow = GUtopIa::Window.new.caption('Fruit App').width(200)
awindow.height(300).layout(:grid).body([ [ aradio ], [ abutton ] ])
notice we sort of reset with the second line, resusing "awindow". we
could just keep going on the first line, but long code lines suck.
anyway, you may not know it but you CAN actually write the above like
this:
awindow = GUtopIa::Window.new.
caption('Fruit App').
width(200).
height(300).
layout(:grid).
body([ [ aradio ], [ abutton ] ])
notice the periods at the end of each line, that's the trick.
and since we have these argument based writer methods, and also the
instance eval from above, we CAN combine the two and get this:
awindow = GUtopIa::Window.new {
caption 'Fruit App'
width 200
height 300
layout :grid
body [ [ aradio ], [ abutton ] ]
}
and this is essentially the Tk-way. except the TK-way also offers the
hash syntax, which is really the only viable form that GUTopIa CANNOT do
(yet?):
awindow = GUtopIa::Window.new (
:caption => 'Fruit App',
:width => 200,
:height => 300,
:layout => :grid,
:body => [ [ aradio ], [ abutton ] ]
)
so now my QUESTION: should all these CAN's be supported? and perhaps
throw in the last hash syntax as well? just cover all the bases. OR
whould we instead only support the first simpliest method. i'm pretty
sure that if what i WANTED had worked i would have only gone that far,
but alas, a different determination must be made.
suggestions? alternate ideas?
~transami
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [rgui-dev] simple design issue: question at the end, "All or One?",
Tom Sawyer <=