Glimmer는 최초의 공식 맞춤형 모양 보석을 얻습니다.

15148 단어 guigraphicsdesktopruby
Glimmer DSL for SWT , Top 8 Ruby Framework Projects on LibHunt for Feb 2021 , 최근 added support for Custom Shapes , 사용자 지정 위젯(재사용 가능한 위젯 구성)과 유사한 재사용 가능한 그래픽 구성입니다. Glimmer DSL for SWT 첫 번째 공식을 받았습니다 custom shape gems : glimmer-cp-bevel , bevel 제공 키워드 및 glimmer-cp-stickfigure , stick_figure 제공 키워드. 아래에서 다룹니다.

Bevel
이것은 다양한 색상과 크기를 가질 수 있는 베벨 사각형 사용자 정의 모양을 나타내며 나머지를 파악하기 위해 기본 색상만 설정하면 됩니다. API을 통해 사용자 정의할 수 있습니다. .



현재 에서 사용 중입니다.



Glimmer GUI DSL 코드 예제:

# From: https://github.com/AndyObtiva/glimmer-cp-bevel#example

require 'glimmer-cp-bevel'

include Glimmer

shell {
  text 'Glimmer Tetris Icon'
  label {
    text 'Check out the application icon!'
    font height: 20
  }
  icon_block_size = 64
  icon_bevel_size = icon_block_size.to_f / 25.to_f
  icon_bevel_pixel_size = 0.16*icon_block_size.to_f
  icon_size = 8
  icon_pixel_size = icon_block_size * icon_size
  image(icon_pixel_size, icon_pixel_size) {
    icon_size.times { |row|
      icon_size.times { |column|
        colored = row >= 1 && column.between?(1, 6)
        color = colored ? color(([:white] + [:cyan, :blue, :dark_yellow, :yellow, :green, :magenta, :red]).sample) : color(:white)
        x = column * icon_block_size
        y = row * icon_block_size
        bevel(x: x, y: y, base_color: color, size: icon_block_size)
      }
    }
  }
}.open


생성된 Tetris 아이콘 이미지:



Stick Figure
이것은 색상과 크기를 가질 수 있는 스틱 그림 사용자 정의 모양을 나타내며 스틱 그림 머리, 몸통, 팔 및 다리의 나머지 부분을 파악하기 위해 기본 크기만 설정하면 됩니다. API을 통해 사용자 정의할 수 있습니다. .



현재 사용 예정 DCR 프로젝트



Hello, Stick Figure! Sample에 대한 Glimmer GUI DSL 코드 :

# From: https://github.com/AndyObtiva/glimmer-cp-stickfigure/blob/master/samples/stick_figure/hello_stick_figure.rb

require_relative '../../lib/glimmer-cp-stickfigure' # Use `require 'glimmer-cp-stickfigure'` if gem is installed

class HelloStickFigure
  include Glimmer::UI::CustomShell

  WIDTH = 220
  HEIGHT = 235

  body {
    shell {
      text 'Hello, Stick Figure!'
      minimum_size WIDTH, HEIGHT

      @canvas = canvas {
        background :white

        15.times { |n|
          x_location = (rand*WIDTH/2).to_i%WIDTH + (rand*15).to_i
          y_location = (rand*HEIGHT/2).to_i%HEIGHT + (rand*15).to_i
          foreground_color = rgb(rand*255, rand*255, rand*255)

          stick_figure(location_x: x_location, location_y: y_location, size: 35+n*2) {
            foreground foreground_color
          }
        }

        on_mouse_down { |mouse_event|
          @drag_detected = false
          @canvas.cursor = :hand
          # select shape at location
          @selected_shape = @canvas.shape_at_location(mouse_event.x, mouse_event.y)
          # select shape parent if it is a nested shape like an arm or leg
          @selected_shape = @selected_shape.parent_shapes.last if @selected_shape.parent_shapes.any?
        }

        on_drag_detected { |drag_detect_event|
          @drag_detected = true
          @drag_current_x = drag_detect_event.x
          @drag_current_y = drag_detect_event.y
        }

        on_mouse_move { |mouse_event|
          if @drag_detected
            @selected_shape&.move_by(mouse_event.x - @drag_current_x, mouse_event.y - @drag_current_y)
            @drag_current_x = mouse_event.x
            @drag_current_y = mouse_event.y
          end
        }

        on_mouse_up { |mouse_event|
          @canvas.cursor = :arrow
          @drag_detected = false
          @selected_shape = nil
        }
      }
    }
  }
end

HelloStickFigure.launch


안녕하세요, 스틱피겨입니다!



행복한 Glimmering !

좋은 웹페이지 즐겨찾기