Module: PurplishFrame::CanScaleWidthHeight

Included in:
CGSize, NSSize
Defined in:
lib/purplish-frame/non-ui/can_scale_width_height.rb

Instance Method Summary collapse

Instance Method Details

#scale_to_fill(s) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/purplish-frame/non-ui/can_scale_width_height.rb', line 13

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

#scale_to_fill!(s) ⇒ Object



30
31
32
33
34
35
# File 'lib/purplish-frame/non-ui/can_scale_width_height.rb', line 30

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

#scale_to_fit(s) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/purplish-frame/non-ui/can_scale_width_height.rb', line 3

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

#scale_to_fit!(s) ⇒ Object



23
24
25
26
27
28
# File 'lib/purplish-frame/non-ui/can_scale_width_height.rb', line 23

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