require 'glimmer-dsl-swt'
class HelloComputed
class Contact
attr_accessor :first_name, :last_name, :year_of_birth
def initialize(attribute_map)
@first_name = attribute_map[:first_name]
@last_name = attribute_map[:last_name]
@year_of_birth = attribute_map[:year_of_birth]
end
def name
"#{last_name}, #{first_name}"
end
def age
Time.now.year - year_of_birth.to_i
rescue
0
end
end
include Glimmer::UI::CustomShell
before_body {
@contact = Contact.new(
first_name: 'Barry',
last_name: 'McKibbin',
year_of_birth: 1985
)
}
body {
shell {
text 'Hello, Computed!'
composite {
grid_layout {
num_columns 2
make_columns_equal_width true
horizontal_spacing 20
vertical_spacing 10
}
label {text 'First &Name: '}
text {
text <=> [@contact, :first_name]
layout_data {
horizontal_alignment :fill
grab_excess_horizontal_space true
}
}
label {text '&Last Name: '}
text {
text <=> [@contact, :last_name]
layout_data {
horizontal_alignment :fill
grab_excess_horizontal_space true
}
}
label {text '&Year of Birth: '}
text {
text <=> [@contact, :year_of_birth]
layout_data {
horizontal_alignment :fill
grab_excess_horizontal_space true
}
}
label {text 'Name: '}
label {
text <= [@contact, :name, computed_by: [:first_name, :last_name]]
layout_data {
horizontal_alignment :fill
grab_excess_horizontal_space true
}
}
label {text 'Age: '}
label {
text <= [@contact, :age, on_write: :to_i, computed_by: [:year_of_birth]]
layout_data {
horizontal_alignment :fill
grab_excess_horizontal_space true
}
}
}
}
}
end
HelloComputed.launch
No, you are not hallucinating!!! The uses of <=> and <= to denote bidirectional (two-way) and unidirectional (one-way) data-binding respectively are real code from the updated Hello, Computed! sample working in Glimmer DSL for SWT 4.20.0.0, thanks to the new Shine syntax for View/Model Attribute Mapping and Ruby's ultra-malleable DSL syntax support.
The Glimmer DSL for SWT 4.20.0.0 major release ships with a number of innovations such as:
- The new Shine data-binding syntax (early alpha feature)
- SWT 4.20
- Experimental support for AARCH64 CPU architectures courtesy of the new SWT 4.20
- JRuby default version of 9.2.19.0
- Tweaked samples to utilize the Shine syntax wherever possible
Happy Glimmering!
Top comments (0)