Monday, November 19, 2007

Sneak Peak at Glimmer

Ruby has been popularized for developing web applications using Ruby on Rails, but it has not gathered the same momentum in building desktop applications. That can be changed by having a Ruby desktop development library that satisfies these goals/criteria:
  • Platform-independence
  • Native widget support
  • Industry-strength
  • Strong community support
  • Ease of use
Current available libraries for Ruby that accomplish some of the goals are:
  • TK
  • FXRuby
  • Shoes
  • GTK
  • wxWidgets

However, the library that seems to come closest to satisfying the goals listed above is the Eclipse SWT library, which is used as the foundation for building the Eclipse IDE UI. The only goal that it does not meet is "Ease of use" in Java.

Java's syntax can be cumbersome for representing UI, which is a part of the reason why people use GUI visual builders and XAML-like authoring languages (e.g. XSWT.) However, Ruby proved to simplify coding a lot by providing the ability to build textual DSLs that are tidy, concise, and have a great expressive power.

This is why I built Glimmer, a JRuby DSL that enables easy and efficient authoring of user-interfaces using Eclipse SWT. Glimmer currently supports painting widgets and adding listeners. Eventually, it will also come with built-in data-binding support to greatly facilitate synchronizing UI with domain models.

Here's an example written with SWT in Java:
Display display = Display.getDefault();
Shell shell = new Shell(display);
shell.setText("SWT");
shell.setLayout(new FillLayout());
Composite composite = new Composite(shell, SWT.NONE);
composite.setLayout(new GridLayout());
Label label = new Label(composite, SWT.NONE);
label.setText("Hello World!");
shell.pack();
shell.open();
while (!display.isDisposed()) {
  if (!display.readAndDispatch()) {
    display.sleep();
  }
}
display.dispose();
Here is the same example authored with the JRuby Glimmer DSL:
shell {
  text "JRuby on SWT"
  composite {
    label { 
      text "Hello World!" 
    }
  }
}
Need I say more about this? Stay tuned for more about Glimmer, delving deeper into the way it works and how to add event listeners to widgets. Initial version has been posted.

3 comments:

Victoria Wang said...

This sounds really cool, Andy! (I was hoping to attend Chirb last week to hear about this but was being crushed under school finals.) Looking forward to learning more.

Daniel Serodio said...

Is this fundamentally different from Groovy's GroovySWT, besides using Ruby instead of Groovy?

Andy Maleh said...

Fundamentally, I wouldn't say it is. However, Glimmer comes with built-in data-binding support and automatically supports custom widgets as long as they have a (parent, style) constructor.