When I do GUIs, I have a way of doing them, but people keep telling me it's cryptic. Yet I think it's easier, since it makes the left-hand side of the code look like a 'tree' of containers.
It works with most languages/toolkits. I've tried it with may. Since this is a Ubuntu forum, I decided to show it in GTK
I do my GUI code like this. I haven't tested this, as I haven't got a Ruby interpreter atm. This can be made a lot shorter using Ruby's functional features, but the point of this more expanded one is that it shows a 'tree' of containers.
Code:
require 'gtk2'
class GtkGui
include gtk
def initialize
@window = Window.new().add(
VBox.new(false, 0).pack_start(
HBox.new(false, 0).pack_start(
Button.new('One')).pack_start(
Button.new('Two'))).pack_start(
HBox.new(false, 0).pack_start(
Button.new('Three')).pack_start(
Button.new('Four'))))
end
def launch
@window.show_all
main
end
end
GtkGui.new.launch
See what I mean? I can clearly tell by looking at the side of the code what's inside what. So why do so many use the one-after-another style?