The newly released Glimmer DSL for SWT v4.18.4.10 adds a progress bar to the Mandelbrot Fractal sample (blogged about over here) as well as a Cores Menu that enables switching the number of used CPU cores to allow for more responsiveness.
Otherwise, a new Hello sample was added too: Hello, Progress Bar!
Glimmer GUI DSL Code for Hello, Progress Bar! is below:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # From: https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_SAMPLES.md#hello-progress-bar | |
| class HelloProgressBar | |
| include Glimmer::UI::CustomWindow | |
| class ProgressModel | |
| attr_accessor :minimum, :maximum, :selection, :delay | |
| end | |
| before_body { | |
| @progress_model = ProgressModel.new | |
| @progress_model.minimum = 0 | |
| @progress_model.maximum = 100 | |
| @progress_model.selection = 0 | |
| @progress_model.delay = 0.01 | |
| } | |
| body { | |
| shell { | |
| grid_layout(4, true) | |
| text 'Hello, Progress Bar!' | |
| progress_bar(:indeterminate) { | |
| layout_data(:fill, :center, true, false) { | |
| horizontal_span 4 | |
| } | |
| } | |
| label { | |
| text 'Minimum' | |
| } | |
| label { | |
| text 'Maximum' | |
| } | |
| label { | |
| text 'Selection' | |
| } | |
| label { | |
| text 'Delay in Seconds' | |
| } | |
| spinner { | |
| selection bind(@progress_model, :minimum) | |
| } | |
| spinner { | |
| selection bind(@progress_model, :maximum) | |
| } | |
| spinner { | |
| selection bind(@progress_model, :selection) | |
| } | |
| spinner { | |
| digits 2 | |
| minimum 1 | |
| maximum 200 | |
| selection bind(@progress_model, :delay, on_read: ->(v) {v.to_f*100.0}, on_write: ->(v) {v.to_f/100.0}) | |
| } | |
| progress_bar { | |
| layout_data(:fill, :center, true, false) { | |
| horizontal_span 4 | |
| } | |
| minimum bind(@progress_model, :minimum) | |
| maximum bind(@progress_model, :maximum) | |
| selection bind(@progress_model, :selection) | |
| } | |
| progress_bar(:vertical) { | |
| layout_data(:fill, :center, true, false) { | |
| horizontal_span 4 | |
| } | |
| minimum bind(@progress_model, :minimum) | |
| maximum bind(@progress_model, :maximum) | |
| selection bind(@progress_model, :selection) | |
| } | |
| button { | |
| layout_data(:fill, :center, true, false) { | |
| horizontal_span 4 | |
| } | |
| text "Start" | |
| on_widget_selected { | |
| # if a previous thread is running, then kill first | |
| # (killing is not dangerous since it is only a thread about updating progress) | |
| @current_thread&.kill | |
| @current_thread = Thread.new { | |
| sync_exec { @progress_model.selection = @progress_model.minimum } | |
| (@progress_model.minimum..@progress_model.maximum).to_a.each do |n| | |
| sync_exec { | |
| @progress_model.selection = n | |
| } | |
| sleep(@progress_model.delay) | |
| end | |
| } | |
| } | |
| } | |
| } | |
| } | |
| end | |
| HelloProgressBar.launch |
Happy Glimmering!





No comments:
Post a Comment