Sha256: ab5f17b94faf88462db0dbf2a1a4066f54a23ab935ede66608575e5229c3c066
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
motion_require "base" =begin { from: [0, 0], to: [10, 20] } { from: 100, to: 200, axis: :y } =end module Walt module Operation class MoveOperation < Base PROPERTIES = [:from, :to, :axis] attr_accessor *PROPERTIES attr_default :axis, :x def initialize(params = {}) super if axis = (params[:axis] || params["axis"]) self.axis = axis end params.each do |key, value| if PROPERTIES.include?(key.to_sym) self.send("#{key}=", value) end end end ["from", "to"].each do |point| define_method("#{point}=") do |new_point| _point = new_point case new_point when Numeric if self.axis.to_sym == :x _point = [new_point, nil] else _point = [nil, new_point] end when CGPoint _point = [new_point.x, new_point.y] when NSArray else raise "Invalid class for #{point}=: #{new_point.inspect}" end instance_variable_set("@#{point}", _point) end end def setup(view, animation) if self.from origin = view.frame.origin origin.x = (self.from[0] || origin.x) origin.y = (self.from[1] || origin.y) view.frame = [origin, view.frame.size] end end def finalize(view, animation) origin = view.frame.origin origin.x = (self.to[0] || origin.x) origin.y = (self.to[1] || origin.y) view.frame = [origin, view.frame.size] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
walt-0.1.2 | lib/walt/operation/move.rb |