Module: Shoes::Basic

Defined in:
lib/shoes.rb

Instance Method Summary collapse

Instance Method Details

#tween(opts, &blk) ⇒ Object



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# File 'lib/shoes.rb', line 383

def tween(opts, &blk)
  opts = opts.dup

  if opts[:upward]
    opts[:top] = top - opts.delete(:upward)
  elsif opts[:downward]
    opts[:top] = top + opts.delete(:downward)
  end

  if opts[:sideways]
    opts[:left] = self.left + opts.delete(:sideways)
  end

  @TWEEN.remove if @TWEEN
  @TWEEN = parent.animate(opts[:speed] || 20) do
    # figure out a coordinate halfway between here and there
    cont = opts.select do |k, v|
      if self.respond_to? k
        n = v
        o = send(k)
        if n != o
          n = o + ((n - o) / 2)
          n = v if o == n
          send("#{k}=", n)
        end
        style[k] != v
      end
    end

    # if we're there, get rid of the animation
    if cont.empty?
      @TWEEN.remove
      @TWEEN = nil
      blk.call if blk
    end
  end
end