DEV Community

Cover image for Glimmer DSL for SWT v4.24.1.0 Improved Hello, Canvas Path!
Andy Maleh
Andy Maleh

Posted on

Glimmer DSL for SWT v4.24.1.0 Improved Hello, Canvas Path!

Glimmer DSL for SWT v4.24.1.0 has been released with the following changes:

  • Upgrade to JRuby 9.3.6.0
  • Speed up app scaffolding by dropping packaging from the scaffolding steps as there is no point in packaging an unfinished product
  • Refactor/simplify Hello, Canvas Path!

Updated Hello, Canvas Path! Sample Screenshot

screenshot

Updated Hello, Canvas Path! Sample Code

# From: https://github.com/AndyObtiva/glimmer-dsl-swt/blob/development/docs/reference/GLIMMER_SAMPLES.md#hello-canvas-path

require 'glimmer-dsl-swt'

class HelloCanvasPath
  include Glimmer::UI::Application

  after_body do
    regenerate
  end

  body {
    shell {
      grid_layout {
        margin_width 0
        margin_height 0
        margin_top 5
      }

      text 'Hello, Canvas Path!'
      minimum_size 800, 700

      @button = button {
        layout_data :center, :center, true, false

        text 'Regenerate'
        enabled false

        on_widget_selected do
          regenerate
        end
      }

      canvas {
        layout_data :fill, :fill, true, true
        background :white

        text('line', 15, 200) {
          foreground :red
        }
        @path1 = path {
          antialias :on
          foreground :red
        }

        text('quad', 15, 300) {
          foreground :dark_green
        }
        @path2 = path {
          antialias :on
          foreground :dark_green
        }

        text('cubic', 15, 400) {
          foreground :blue
        }
        @path3 = path {
          antialias :on
          foreground :blue
        }
      }

      on_widget_disposed do
        # safe to kill thread as data is in memory only, so no risk of data loss
        @thread.kill
      end
    }
  }

  def regenerate
    @thread = Thread.new do
      @button.enabled = false
      @path1.clear
      @path2.clear
      @path3.clear
      y1 = y2 = y3 = 300
      700.times.each do |x|
        x += 55
        x1 = x - 2
        x2 = x - 1
        x3 = x
        y1 = y3
        y2 = y1
        y3 = [[y3 + (rand*24 - 12), 0].max, 700].min
        @path1.content {
          line(x1, y1 - 100)
        }
        if x % 2 == 0
          @path2.content {
            quad(x1, y1, x2, y2)
          }
        end
        if x % 3 == 0
          @path3.content {
            cubic(x1, y1 + 100, x2, y2 + 100, x3, y3 + 100)
          }
        end
        sleep(0.01)
      end
      @button.enabled = true
    end
  end
end

HelloCanvasPath.launch
Enter fullscreen mode Exit fullscreen mode

Updated Hello, Canvas Path! Sample Tutorial

Glimmer On!

Top comments (0)