Monday, February 22, 2021

Glimmer DSL for SWT Hello, Tree! and Hello, Canvas! Drag'n'Move

Glimmer DSL for SWT just had a relatively major release in version with the following major changes (detailed in Change Log):

  • No more need for explicit use of `sync_exec` as required by SWT when updating GUI from threads other than the main thread. Glimmer now automates calling it for you by detecting if you are in a different thread from the GUI thread when you make a GUI widget call to SWT. This is a very big one for veteran SWT developers. Still, if there is ever a need to have it happen manually, you can switch this behavior off with the Glimmer::Config.auto_sync_exec option
  • The Canvas Shape DSL gets full data-binding, parameter mutation support, and alternative syntax (placing parameters as attributes within content block instead of inside parentheses). That means you could now adjust shape parameters like x & y coordinates after placing a shape on the canvas, and then move it.  In fact, the Hello, Canvas! sample has been enhanced to permit drag & move.
  • The Hello, Tree! sample has finally been added. It demonstrates tree data population and data-binding as well as a master/detail view upon selecting tree nodes.

Hello, Tree!

The tree code is only the following bit, which is declaring the bare minimum needed to describe a tree, its items (root item is ``, pull children with the `subordinates` method and pull text for each node with the `to_s` method) and selection data-binding (binding to selected_employee class-level property on the Employee class):

@tree = tree {
  items bind(Employee, :ceo), tree_properties(children: :subordinates, text: :to_s)
  selection bind(Employee, :selected_employee)

Below is the full code:

Hello, Canvas!

Hello, Canvas! with Shapes Moved via Drag'n'Drop

Happy Glimmering!

No comments: