LibUI 0.5.11용 Glimmer DSL - 기본 모양 드래그 앤 드롭

17149 단어 guidesktoprubylibui
Glimmer DSL for LibUI 0.5.11(Fukuoka Ruby 2022 Award Winning Ruby Desktop Development GUI 라이브러리)이 다음 변경 사항과 함께 출시되었습니다(Perfect Shape gem 제공).
  • perfect-shape 1.0.4(기하학적 알고리즘)로 업그레이드
  • 기본 끌어서 놓기가 지원되는 업데이트examples/shape_coloring.rb
  • 지원 #move_by(x_delta, y_delta) (별칭 translate ) 모든 모양 및 path (예: 끌어서 놓기에 유용)
  • 모든 도형에 대한 #move(x, y) 방법 및 x,y 좌표로 직접 이동하는 path 지원
  • 지원 #min_x 최소 x 좌표 모양/path (of-left corner)
  • 지원 #min_y 최소 y 좌표 모양/path (of-left corner)
  • 지지 #max_x 최대 x 좌표 of shape/path (of right-bottom corner)
  • 지원 #max_y 최대 y 좌표 of shape/path (of right-bottom corner)
  • 지지대 #center_point ( Array of x,y) 모양의 중심점/path
  • 지지대 #center_x 중심 x 모양의 좌표/path
  • 지지대 #center_y 도형의 중심 y 좌표/path

  • 이제 모양을 드래그 앤 드롭하여 Shape Coloring example에서 이동할 수 있습니다.





    # From: https://github.com/AndyObtiva/glimmer-dsl-libui#shape-coloring
    
    require 'glimmer-dsl-libui'
    
    class ShapeColoring
      include Glimmer::LibUI::Application
    
      COLOR_SELECTION = Glimmer::LibUI.interpret_color(:red)
    
      before_body {
        @shapes = []
      }
    
      body {
        window('Shape Coloring', 200, 220) {
          margined false
    
          grid {
            label("Drag & drop shapes to move or\nclick a shape to select and\nchange color via color button") {
              left 0
              top 0
              hexpand true
              halign :center
              vexpand false
            }
    
            color_button { |cb|
              left 0
              top 1
              hexpand true
              vexpand false
    
              on_changed do
                @selected_shape&.fill = cb.color
              end
            }
    
            area {
              left 0
              top 2
              hexpand true
              vexpand true
    
              rectangle(0, 0, 600, 400) { # background shape
                fill :white
              }
    
              @shapes << colorable(:rectangle, 20, 20, 40, 20) {
                fill :lime
              }
    
              @shapes << colorable(:square, 80, 20, 20) {
                fill :blue
              }
    
              @shapes << colorable(:circle, 75, 70, 20) {
                fill :green
              }
    
              @shapes << colorable(:arc, 120, 70, 40, 0, 145) {
                fill :orange
              }
    
              @shapes << colorable(:polygon, 120, 10, 120, 50, 150, 10, 150, 50) {
                fill :cyan
              }
    
              @shapes << colorable(:polybezier, 20, 40,
                         30, 100, 50, 80, 80, 110,
                         40, 120, 20, 120, 30, 91) {
                fill :pink
              }
    
              on_mouse_dragged do |area_mouse_event|
                mouse_dragged(area_mouse_event)
              end
    
              on_mouse_dropped do |area_mouse_event|
                mouse_dropped(area_mouse_event)
              end
            }
          }
        }
      }
    
      def colorable(shape_symbol, *args, &content)
        send(shape_symbol, *args) do |shape|
          on_mouse_up do |area_mouse_event|
            unless @dragged_shape
              old_stroke = Glimmer::LibUI.interpret_color(shape.stroke).slice(:r, :g, :b)
              @shapes.each {|sh| sh.stroke = nil}
              @selected_shape = nil
              unless old_stroke == COLOR_SELECTION
                shape.stroke = COLOR_SELECTION.merge(thickness: 2)
                @selected_shape = shape
              end
            end
          end
    
          on_mouse_drag_started do |area_mouse_event|
            mouse_drag_started(shape, area_mouse_event)
          end
    
          on_mouse_dragged do |area_mouse_event|
            mouse_dragged(area_mouse_event)
          end
    
          on_mouse_dropped do |area_mouse_event|
            mouse_dropped(area_mouse_event)
          end
    
          content.call(shape)
        end
      end
    
      def mouse_drag_started(dragged_shape, area_mouse_event)
        @dragged_shape = dragged_shape
        @dragged_shape_x = area_mouse_event[:x]
        @dragged_shape_y = area_mouse_event[:y]
      end
    
      def mouse_dragged(area_mouse_event)
        if @dragged_shape && @dragged_shape_x && @dragged_shape_y
          x_delta = area_mouse_event[:x] - @dragged_shape_x
          y_delta = area_mouse_event[:y] - @dragged_shape_y
          @dragged_shape.move_by(x_delta, y_delta)
          @dragged_shape_x = area_mouse_event[:x]
          @dragged_shape_y = area_mouse_event[:y]
        end
      end
    
      def mouse_dropped(area_mouse_event)
        @dragged_shape = nil
        @dragged_shape_x = nil
        @dragged_shape_y = nil
      end
    end
    
    ShapeColoring.launch
    


    해피Glimmering !

    좋은 웹페이지 즐겨찾기