Sha256: 136f350c19c0083f23616e7bc34b7d2b34905893ee51a4d229daab93780433a1

Contents?: true

Size: 944 Bytes

Versions: 12

Compression:

Stored size: 944 Bytes

Contents

module PurplishFrame
  module CanScaleWidthHeight
    def scale_to_fit(s)
      s = self.class.to_native_size(s)
      scaled = if s.width/s.height > width/height
                 [s.height/height * width, s.height]
               else
                 [s.width, s.width/width * height]
               end
      self.class.to_native_size(scaled)
    end

    def scale_to_fill(s)
      s = self.class.to_native_size(s)
      scaled = if s.width/s.height > width/height
                 [s.width, s.width/width * height]
               else
                 [s.height/height * width, s.height]
               end
      self.class.to_native_size(scaled)
    end

    def scale_to_fit!(s)
      size = scale_to_fit(s)
      self.width = size.width
      self.height = size.height
      self
    end

    def scale_to_fill!(s)
      size = scale_to_fill(s)
      self.width = size.width
      self.height = size.height
      self
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
purplish-frame-0.0.12 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.11 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.10 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.9 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.8 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.7 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.6 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.5 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.4 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.3 lib/purplish-frame/non-ui/can_scale_width_height.rb
purplish-frame-0.0.2 lib/purplish-frame/can_scale_width_height.rb
purplish-frame-0.0.1 lib/purplish-frame/can_scale_width_height.rb