Module: Teacup::StylesheetExtension
- Included in:
- Limelight, Stylesheet
- Defined in:
- lib/teacup-osx/style_extensions/autoresize.rb,
lib/teacup/stylesheet_extensions/transform.rb,
lib/teacup-ios/stylesheet_extensions/device.rb,
lib/teacup/stylesheet_extensions/constraints.rb,
lib/teacup-ios/stylesheet_extensions/autoresize.rb
Instance Method Summary collapse
-
#app_size ⇒ Object
returns the application frame, which takes the status bar into account.
- #autoresize(&block) ⇒ Object
- #constrain(target, attribute = nil) ⇒ Object
- #constrain_above(relative_to, margin = 0) ⇒ Object
-
#constrain_below(relative_to, margin = 0) ⇒ Object
|.
- #constrain_bottom(y) ⇒ Object
- #constrain_center_x(x = 0) ⇒ Object
- #constrain_center_y(y = 0) ⇒ Object
- #constrain_height(height) ⇒ Object
- #constrain_left(x) ⇒ Object
- #constrain_right(x) ⇒ Object
- #constrain_size(width, height) ⇒ Object
- #constrain_to_left(relative_to, margin = 0) ⇒ Object
- #constrain_to_right(relative_to, margin = 0) ⇒ Object
- #constrain_top(y) ⇒ Object
- #constrain_width(width) ⇒ Object
-
#constrain_xy(x, y) ⇒ Object
|.
-
#device ⇒ Object
returns a bit-wise OR of the device masks.
- #device_is?(this_device) ⇒ Boolean
- #flexible_bottom ⇒ Object
- #flexible_height ⇒ Object
-
#flexible_left ⇒ Object
| | DEPRECATED |.
- #flexible_right ⇒ Object
- #flexible_top ⇒ Object
- #flexible_width ⇒ Object
- #flip(matrix, angle) ⇒ Object
- #identity ⇒ Object
- #iPad ⇒ Object
- #iPadRetina ⇒ Object
- #iPhone ⇒ Object
- #iPhone35 ⇒ Object
- #iPhone4 ⇒ Object
- #iPhone5 ⇒ Object
- #iPhoneRetina ⇒ Object
- #pi ⇒ Object
- #rotate(matrix, angle, x, y, z) ⇒ Object
-
#screen_size ⇒ Object
returns the device size in points, regardless of status bar.
- #spin(matrix, angle) ⇒ Object
- #transform_layer ⇒ Object
- #transform_view ⇒ Object
- #twist(matrix, angle) ⇒ Object
Instance Method Details
#app_size ⇒ Object
returns the application frame, which takes the status bar into account
47 48 49 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 47 def app_size UIScreen.mainScreen.applicationFrame.size end |
#autoresize(&block) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/teacup-osx/style_extensions/autoresize.rb', line 12 def autoresize &block @@autoresize ||= Autoresize.new if block return @@autoresize.instance_exec &block else return @@autoresize end end |
#constrain(target, attribute = nil) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 4 def constrain(target, attribute=nil) if attribute.nil? attribute = target target = :self end Teacup::Constraint.new(target, attribute) end |
#constrain_above(relative_to, margin = 0) ⇒ Object
77 78 79 80 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 77 def constrain_above(relative_to, margin=0) margin = 8 if margin == :auto Teacup::Constraint.new(:self, :bottom).equals(relative_to, :top).minus(margin) end |
#constrain_below(relative_to, margin = 0) ⇒ Object
|
72 73 74 75 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 72 def constrain_below(relative_to, margin=0) margin = 8 if margin == :auto Teacup::Constraint.new(:self, :top).equals(relative_to, :bottom).plus(margin) end |
#constrain_bottom(y) ⇒ Object
36 37 38 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 36 def constrain_bottom(y) Teacup::Constraint.new(:self, :bottom).equals(:superview, :bottom).plus(y) end |
#constrain_center_x(x = 0) ⇒ Object
28 29 30 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 28 def constrain_center_x(x=0) Teacup::Constraint.new(:self, :center_x).equals(:superview, :center_x).plus(x) end |
#constrain_center_y(y = 0) ⇒ Object
40 41 42 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 40 def constrain_center_y(y=0) Teacup::Constraint.new(:self, :center_y).equals(:superview, :center_y).plus(y) end |
#constrain_height(height) ⇒ Object
48 49 50 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 48 def constrain_height(height) Teacup::Constraint.new(:self, :height).equals(height) end |
#constrain_left(x) ⇒ Object
20 21 22 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 20 def constrain_left(x) Teacup::Constraint.new(:self, :left).equals(:superview, :left).plus(x) end |
#constrain_right(x) ⇒ Object
24 25 26 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 24 def constrain_right(x) Teacup::Constraint.new(:self, :right).equals(:superview, :right).plus(x) end |
#constrain_size(width, height) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 52 def constrain_size(width, height) if width.is_a? Numeric width_attr = nil else width_attr = :width end if height.is_a? Numeric height_attr = nil else height_attr = :height end [ Teacup::Constraint.new(:self, :width).equals(width, width_attr), Teacup::Constraint.new(:self, :height).equals(height, height_attr), ] end |
#constrain_to_left(relative_to, margin = 0) ⇒ Object
87 88 89 90 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 87 def constrain_to_left(relative_to, margin=0) margin = 20 if margin == :auto Teacup::Constraint.new(:self, :right).equals(relative_to, :left).minus(margin) end |
#constrain_to_right(relative_to, margin = 0) ⇒ Object
82 83 84 85 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 82 def constrain_to_right(relative_to, margin=0) margin = 20 if margin == :auto Teacup::Constraint.new(:self, :left).equals(relative_to, :right).plus(margin) end |
#constrain_top(y) ⇒ Object
32 33 34 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 32 def constrain_top(y) Teacup::Constraint.new(:self, :top).equals(:superview, :top).plus(y) end |
#constrain_width(width) ⇒ Object
44 45 46 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 44 def constrain_width(width) Teacup::Constraint.new(:self, :width).equals(width) end |
#constrain_xy(x, y) ⇒ Object
|
13 14 15 16 17 18 |
# File 'lib/teacup/stylesheet_extensions/constraints.rb', line 13 def constrain_xy(x, y) [ Teacup::Constraint.new(:self, :left).equals(:superview, :left).plus(x), Teacup::Constraint.new(:self, :top).equals(:superview, :top).plus(y), ] end |
#device ⇒ Object
returns a bit-wise OR of the device masks
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 52 def device @@this_device ||= nil return @@this_device if @@this_device @@this_device = 0 if UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone @@this_device |= iPhone if UIScreen.mainScreen.respond_to?(:scale) && UIScreen.mainScreen.scale == 2 @@this_device |= iPhoneRetina end if UIScreen.mainScreen.bounds.size.height == 568 @@this_device |= iPhone4 else @@this_device |= iPhone35 end else @@this_device |= iPad if UIScreen.mainScreen.respond_to? :scale @@this_device |= iPadRetina end end return @@this_device end |
#device_is?(this_device) ⇒ Boolean
79 80 81 82 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 79 def device_is?(this_device) this_device = self.send(this_device) if this_device.is_a? Symbol return self.device & this_device > 0 end |
#flexible_bottom ⇒ Object
50 51 52 53 |
# File 'lib/teacup-osx/style_extensions/autoresize.rb', line 50 def flexible_bottom NSLog("The Stylesheet method `flexible_bottom` is deprecated, use `autoresize.flexible_bottom` instead") NSViewMinYMargin end |
#flexible_height ⇒ Object
45 46 47 48 |
# File 'lib/teacup-osx/style_extensions/autoresize.rb', line 45 def flexible_height NSLog("The Stylesheet method `flexible_height` is deprecated, use `autoresize.flexible_height` instead") NSViewHeightSizable end |
#flexible_left ⇒ Object
| | DEPRECATED |
25 26 27 28 |
# File 'lib/teacup-osx/style_extensions/autoresize.rb', line 25 def flexible_left NSLog("The Stylesheet method `flexible_left` is deprecated, use `autoresize.flexible_left` instead") NSViewMinXMargin end |
#flexible_right ⇒ Object
35 36 37 38 |
# File 'lib/teacup-osx/style_extensions/autoresize.rb', line 35 def flexible_right NSLog("The Stylesheet method `flexible_right` is deprecated, use `autoresize.flexible_right` instead") NSViewMaxXMargin end |
#flexible_top ⇒ Object
40 41 42 43 |
# File 'lib/teacup-osx/style_extensions/autoresize.rb', line 40 def flexible_top NSLog("The Stylesheet method `flexible_top` is deprecated, use `autoresize.flexible_top` instead") NSViewMaxYMargin end |
#flexible_width ⇒ Object
30 31 32 33 |
# File 'lib/teacup-osx/style_extensions/autoresize.rb', line 30 def flexible_width NSLog("The Stylesheet method `flexible_width` is deprecated, use `autoresize.flexible_width` instead") NSViewWidthSizable end |
#flip(matrix, angle) ⇒ Object
22 23 24 25 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 22 def flip(matrix, angle) NSLog("The Stylesheet method `flip` is deprecated, use `transform_layer.flip` instead") transform_layer.flip(angle) end |
#identity ⇒ Object
17 18 19 20 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 17 def identity NSLog("The Stylesheet method `identity` is deprecated, use `transform_layer.identity` instead") transform_layer.identity end |
#iPad ⇒ Object
33 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 33 def iPad ; 1 << 5 ; end |
#iPadRetina ⇒ Object
34 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 34 def iPadRetina ; 1 << 6 ; end |
#iPhone ⇒ Object
29 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 29 def iPhone ; 1 << 1 ; end |
#iPhone35 ⇒ Object
32 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 32 def iPhone35 ; 1 << 4 ; end |
#iPhone4 ⇒ Object
31 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 31 def iPhone4 ; 1 << 3 ; end |
#iPhone5 ⇒ Object
36 37 38 39 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 36 def iPhone5 NSLog('TEACUP WARNING: iPhone5 method is deprecated in lieu of size-based method names (iPhone4, iPhone35)') 1 << 3 end |
#iPhoneRetina ⇒ Object
30 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 30 def iPhoneRetina ; 1 << 2 ; end |
#pi ⇒ Object
5 6 7 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 5 def pi Math::PI end |
#rotate(matrix, angle, x, y, z) ⇒ Object
37 38 39 40 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 37 def rotate(matrix, angle, x, y, z) NSLog("The Stylesheet method `rotate` is deprecated, use `transform_layer.rotate` instead") transform_layer.rotate(angle, x, y, z) end |
#screen_size ⇒ Object
returns the device size in points, regardless of status bar
42 43 44 |
# File 'lib/teacup-ios/stylesheet_extensions/device.rb', line 42 def screen_size UIScreen.mainScreen.bounds.size end |
#spin(matrix, angle) ⇒ Object
32 33 34 35 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 32 def spin(matrix, angle) NSLog("The Stylesheet method `spin` is deprecated, use `transform_layer.spin` instead") transform_layer.spin(angle) end |
#transform_layer ⇒ Object
13 14 15 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 13 def transform_layer @@transform_layer ||= TransformLayer.new end |
#transform_view ⇒ Object
9 10 11 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 9 def transform_view @@transform_layer ||= TransformView.new end |
#twist(matrix, angle) ⇒ Object
27 28 29 30 |
# File 'lib/teacup/stylesheet_extensions/transform.rb', line 27 def twist(matrix, angle) NSLog("The Stylesheet method `twist` is deprecated, use `transform_layer.twist` instead") transform_layer.twist(angle) end |