teacup 2.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +113 -45
- data/lib/teacup/version.rb +1 -1
- data/lib/teacup-osx/core_extensions/z_core_extensions.rb +131 -0
- data/lib/teacup-osx/style.rb +7 -28
- metadata +3 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Teacup
|
2
2
|
======
|
3
3
|
|
4
|
-
A community-driven DSL for creating user interfaces on iOS.
|
4
|
+
A community-driven DSL for creating user interfaces on iOS and OS X.
|
5
5
|
|
6
6
|
[![Build Status](https://travis-ci.org/rubymotion/teacup.png)](https://travis-ci.org/rubymotion/teacup)
|
7
7
|
|
@@ -11,13 +11,20 @@ interfaces programmatically.
|
|
11
11
|
|
12
12
|
**Check out some sample apps!**
|
13
13
|
|
14
|
-
*
|
15
|
-
* “[
|
16
|
-
* “[
|
14
|
+
* iOS
|
15
|
+
* “[Hai][Hai]”
|
16
|
+
* “[AutoLayout][AutoLayout]”
|
17
|
+
* “[OnePage][OnePage]”
|
18
|
+
* OS X
|
19
|
+
* “[Tweets][Tweets]” - ported from [RubyMotionSamples][]
|
20
|
+
* “[teacup-osx][teacup-osx]”
|
17
21
|
|
18
22
|
[Hai]: https://github.com/rubymotion/teacup/tree/master/samples/Hai
|
19
23
|
[AutoLayout]: https://github.com/rubymotion/teacup/tree/master/samples/AutoLayout
|
20
24
|
[OnePage]: https://github.com/rubymotion/teacup/tree/master/samples/OnePage
|
25
|
+
[Tweets]: https://github.com/rubymotion/teacup/tree/master/samples/Tweets
|
26
|
+
[teacup-osx]: https://github.com/rubymotion/teacup/tree/master/samples/teacup-osx
|
27
|
+
[RubyMotionSamples]: https://github.com/HipByte/RubyMotionSamples/tree/master/osx/Tweets
|
21
28
|
|
22
29
|
**Quick Install**
|
23
30
|
|
@@ -29,7 +36,7 @@ and in your Rakefile
|
|
29
36
|
require 'teacup'
|
30
37
|
```
|
31
38
|
|
32
|
-
#### 10 second primer
|
39
|
+
#### 10 second primer, iOS
|
33
40
|
|
34
41
|
1. Create a `UIViewController` subclass:
|
35
42
|
|
@@ -63,17 +70,54 @@ require 'teacup'
|
|
63
70
|
end
|
64
71
|
```
|
65
72
|
|
73
|
+
#### 10 second primer, OS X
|
74
|
+
|
75
|
+
Pretty much the same!
|
76
|
+
|
77
|
+
**You should use the `TeacupWindowController` parent class instead of `NSWindowController`**
|
78
|
+
|
79
|
+
1. Create a `TeacupWindowController` subclass.
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class MyController < TeacupWindowController
|
83
|
+
```
|
84
|
+
2. Assign a stylesheet name:
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
class MyController < TeacupWindowController
|
88
|
+
stylesheet :main_window
|
89
|
+
```
|
90
|
+
3. Create a layout:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
class MyController < TeacupWindowController
|
94
|
+
stylesheet :main_window
|
95
|
+
|
96
|
+
layout do
|
97
|
+
subview(NSButton, :hi_button)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
4. Create the stylesheet (in `app/styles/` or somewhere near the controller)
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
Teacup::Stylesheet.new :main_window do
|
105
|
+
style :hi_button,
|
106
|
+
origin: [10, 10],
|
107
|
+
title: 'Hi!'
|
108
|
+
end
|
109
|
+
```
|
66
110
|
|
67
111
|
Teacup
|
68
112
|
------
|
69
113
|
|
70
|
-
Teacup's goal is to facilitate the creation and styling of your
|
71
|
-
|
114
|
+
Teacup's goal is to facilitate the creation and styling of your view hierarchy.
|
115
|
+
Say "Goodbye!" to Xcode & XIB files!
|
72
116
|
|
73
117
|
Teacup is composed of two systems:
|
74
118
|
|
75
119
|
- Layouts
|
76
|
-
A DSL to create
|
120
|
+
A DSL to create Views and to organize them in a hierarchy. You assign the
|
77
121
|
style name and style classes from these methods.
|
78
122
|
|
79
123
|
- Stylesheets
|
@@ -94,19 +138,19 @@ constraints. Teacup can also integrate with the [motion-layout][] gem!
|
|
94
138
|
* [Extending Styles](#extending-styles)
|
95
139
|
* [Style via UIView Class](#style-via-uiview-class)
|
96
140
|
* [Importing stylesheets](#importing-stylesheets)
|
97
|
-
* [Style via UIAppearance](#style-via-uiappearance)
|
141
|
+
* [Style via UIAppearance](#style-via-uiappearance) (iOS only)
|
98
142
|
* [More Teacup features](#more-teacup-features)
|
99
143
|
* [Styling View Properties](#styling-view-properties)
|
100
|
-
* [Orientation Styles](#orientation-styles)
|
101
|
-
* [
|
144
|
+
* [Orientation Styles](#orientation-styles) (iOS only)
|
145
|
+
* [Animation additions](#animation-additions)
|
102
146
|
* [Style Handlers](#style-handlers)
|
103
147
|
* [Frame Calculations](#frame-calculations)
|
104
148
|
* [Auto-Layout](#auto-layout)
|
105
149
|
* [Motion-Layout](#motion-layout)
|
106
150
|
* [Stylesheet extensions](#stylesheet-extensions)
|
107
151
|
* [Autoresizing Masks](#autoresizing-masks)
|
108
|
-
* [Device detection](#device-detection)
|
109
|
-
* [Rotation helpers](#rotation-helpers)
|
152
|
+
* [Device detection](#device-detection) (iOS only)
|
153
|
+
* [Rotation helpers](#rotation-helpers) (iOS only)
|
110
154
|
* [Showdown](#showdown)
|
111
155
|
* [The Nitty Gritty](#the-nitty-gritty)
|
112
156
|
* [Advanced Teacup Tricks](#advanced-teacup-tricks)
|
@@ -118,12 +162,14 @@ constraints. Teacup can also integrate with the [motion-layout][] gem!
|
|
118
162
|
Layouts
|
119
163
|
-------
|
120
164
|
|
121
|
-
The `Teacup::Layout` module is mixed into `UIViewController` and `UIView`
|
122
|
-
|
165
|
+
The `Teacup::Layout` module is mixed into `UIViewController` and `UIView` on
|
166
|
+
iOS, and `NSWindowController`, `NSViewController`, and `NSView` on OS X. These
|
167
|
+
classes can take advantage of the view-hierarchy DSL.
|
123
168
|
|
124
|
-
You saw an example in the primer, using the
|
125
|
-
`layout`. This is a helper
|
126
|
-
example might look like
|
169
|
+
You saw an example in the primer, using the
|
170
|
+
`UIViewController`/`NSWindowController` class method `layout`. This is a helper
|
171
|
+
function that stores the layout code. A more direct example might look like
|
172
|
+
this:
|
127
173
|
|
128
174
|
```ruby
|
129
175
|
# controller example
|
@@ -141,12 +187,12 @@ class MyController < UIViewController
|
|
141
187
|
end
|
142
188
|
```
|
143
189
|
|
144
|
-
You can use very similar code in your
|
190
|
+
You can use very similar code in your view subclasses.
|
145
191
|
|
146
192
|
```ruby
|
147
193
|
# view example
|
148
194
|
#
|
149
|
-
# if you use
|
195
|
+
# if you use Teacup in all your projects, you can bundle your custom views with
|
150
196
|
# their own stylesheets
|
151
197
|
def MyView < UIView
|
152
198
|
|
@@ -162,10 +208,10 @@ end
|
|
162
208
|
|
163
209
|
The `layout` and `subview` methods are the work horses of the Teacup view DSL.
|
164
210
|
|
165
|
-
* `layout(
|
166
|
-
- `
|
167
|
-
|
168
|
-
|
211
|
+
* `layout(view|ViewClass, stylename, style_classes, additional_styles, &block)`
|
212
|
+
- `view|ViewClass` - You can layout an existing class or you can have Teacup
|
213
|
+
create it for you (it just calls `new` on the class, nothing special). This
|
214
|
+
argument is required.
|
169
215
|
- `stylename` (`Symbol`) - This is the name of a style in your stylesheet. It
|
170
216
|
is optional
|
171
217
|
- `style_classes` (`[Symbol,...]`) - Other stylenames, they have lower
|
@@ -174,10 +220,10 @@ The `layout` and `subview` methods are the work horses of the Teacup view DSL.
|
|
174
220
|
either to override or augment the settings from the `Stylesheet`. It is
|
175
221
|
common to use this feature to assign the `delegate` or `dataSource`.
|
176
222
|
- `&block` - See discussion below
|
177
|
-
- Returns the `
|
178
|
-
- only the `
|
223
|
+
- Returns the `view` that was created or passed to `layout`.
|
224
|
+
- only the `view` arg is required. You can pass any combination of
|
179
225
|
stylename, style_classes, and additional_styles (some, none, or all).
|
180
|
-
* `subview(
|
226
|
+
* `subview(view|UIViewClass, stylename, style_classes, additional_styles, &block)`
|
181
227
|
- Identical to `layout`, but adds the view to the current target
|
182
228
|
|
183
229
|
The reason it is so easy to define view hierarchies in Teacup is because the
|
@@ -198,8 +244,9 @@ to add your *own view helpers*! I refer to this as a "partials" system, but
|
|
198
244
|
really it's just Ruby code (and isn't that the best system?).
|
199
245
|
|
200
246
|
```ruby
|
201
|
-
# the methods you add here will be available in UIView,
|
202
|
-
# any of your own
|
247
|
+
# the methods you add here will be available in UIView/NSview,
|
248
|
+
# UIViewController/NSViewController/NSWindowController, and any of your own
|
249
|
+
# classes that `include Teacup::Layout`
|
203
250
|
module Teacup::Layout
|
204
251
|
|
205
252
|
# creates a button and assigns a default stylename
|
@@ -246,12 +293,15 @@ class MyController < UIViewController
|
|
246
293
|
end
|
247
294
|
```
|
248
295
|
|
249
|
-
The `
|
296
|
+
The `Controller##layout` method that has been used so far is going to be
|
250
297
|
the first or second thing you add to a controller when you are building an app
|
251
298
|
with Teacup. It's method signature is
|
252
299
|
|
253
300
|
```ruby
|
301
|
+
# defined in teacup/teacup_controller.rb as Teacup::Controller module
|
254
302
|
UIViewController.layout(stylename=nil, styles={}, &block)
|
303
|
+
NSViewController.layout(stylename=nil, styles={}, &block)
|
304
|
+
NSWindowController.layout(stylename=nil, styles={}, &block)
|
255
305
|
```
|
256
306
|
|
257
307
|
* `stylename` is the stylename you want applied to your controller's `self.view`
|
@@ -422,12 +472,12 @@ Teacup::Stylesheet.new :main do
|
|
422
472
|
end
|
423
473
|
```
|
424
474
|
|
425
|
-
### Style via
|
475
|
+
### Style via View Class
|
426
476
|
|
427
|
-
If you need to apply styles to *all* instances of a `UIView` subclass,
|
428
|
-
do so by applying styles to a class name instead of a symbol. This
|
429
|
-
handy at times when you might otherwise use `UIAppearance` (which
|
430
|
-
supports!).
|
477
|
+
If you need to apply styles to *all* instances of a `UIView`/`NSView` subclass,
|
478
|
+
you can do so by applying styles to a class name instead of a symbol. This
|
479
|
+
feature is handy at times when you might otherwise use `UIAppearance` (which
|
480
|
+
teacup also supports!).
|
431
481
|
|
432
482
|
```ruby
|
433
483
|
Teacup::Stylesheet.new :app do
|
@@ -477,6 +527,8 @@ end
|
|
477
527
|
|
478
528
|
### Style via UIAppearance
|
479
529
|
|
530
|
+
*iOS only*
|
531
|
+
|
480
532
|
And lastly, the `UIAppearance protocol` is supported by creating an instance of
|
481
533
|
`Teacup::Appearance`. There is debatable benefit to using [UIAppearance][],
|
482
534
|
because it will apply styles to views that are outside your control, like the
|
@@ -526,9 +578,9 @@ You can use all the methods above without having to rely on the entirety of
|
|
526
578
|
Teacup's layout and stylesheet systems. By that I mean *any* time you are
|
527
579
|
creating a view hierarchy don't be shy about using Teacup to do it.
|
528
580
|
|
529
|
-
`UIView`
|
530
|
-
customizations anywhere in your code. You don't *have* to pull out a
|
531
|
-
to do it.
|
581
|
+
`UIView` and `NSView` have the `style` method, which can be used to group a
|
582
|
+
bunch of customizations anywhere in your code. You don't *have* to pull out a
|
583
|
+
stylesheet to do it.
|
532
584
|
|
533
585
|
```ruby
|
534
586
|
# Custom Navigation Title created and styled by Teacup
|
@@ -566,7 +618,7 @@ discussion:
|
|
566
618
|
|
567
619
|
- Styling View Properties
|
568
620
|
- Orientation Styles
|
569
|
-
-
|
621
|
+
- View Class Additions
|
570
622
|
- Style Handlers
|
571
623
|
- Frame Calculations
|
572
624
|
- Auto-Layout & [Motion-Layout][motion-layout]
|
@@ -595,6 +647,8 @@ style :tablecell,
|
|
595
647
|
|
596
648
|
### Orientation Styles
|
597
649
|
|
650
|
+
*iOS only*
|
651
|
+
|
598
652
|
There's more to stylesheets than just translating `UIView` setters. Teacup can
|
599
653
|
also apply orientation-specific styles. These are applied when the view is
|
600
654
|
created (using the current device orientation) and when a rotation occurs.
|
@@ -617,7 +671,7 @@ end
|
|
617
671
|
Combine these styles with [Frame Calculations][calculations] to have you view
|
618
672
|
frame recalculated automatically.
|
619
673
|
|
620
|
-
###
|
674
|
+
### Animation additions
|
621
675
|
|
622
676
|
We've already seen the Teacup related properties:
|
623
677
|
|
@@ -632,6 +686,9 @@ animations.
|
|
632
686
|
- `animate_to_styles(style_classes)`
|
633
687
|
- `animate_to_style(properties)`
|
634
688
|
|
689
|
+
On OS X you have to use the `view.animator` property to perform animations.
|
690
|
+
This is supported, but it's kind of "hacky".
|
691
|
+
|
635
692
|
### Style Handlers
|
636
693
|
|
637
694
|
*This feature is used extensively by [sweettea][] to make a more intuitive
|
@@ -671,6 +728,8 @@ style :container,
|
|
671
728
|
frame: :full # => [[0, 0], superview.frame.size]
|
672
729
|
```
|
673
730
|
|
731
|
+
[other-handlers]: https://github.com/rubymotion/teacup/tree/master/lib/teacup/z_core_extensions/z_handlers.rb
|
732
|
+
|
674
733
|
### Frame Calculations
|
675
734
|
|
676
735
|
*These are super cool, just don't forget your autoresizingMasks*
|
@@ -811,11 +870,14 @@ in you chuckle with glee. In this example you could go completely with just
|
|
811
870
|
frame calculation formulas and springs and struts. Your frame code would still
|
812
871
|
be cluttered, just cluttered in a different way.
|
813
872
|
|
814
|
-
|
873
|
+
This works on OS X and iOS, and you don't have to go changing the idea of "top"
|
874
|
+
and "bottom" even though OS X uses reversed frames.
|
875
|
+
|
876
|
+
### Motion-Layout
|
815
877
|
|
816
|
-
If you are using [Nick Quaranto][qrush]'s [motion-layout][] gem, you can use it
|
817
|
-
any class that includes `Teacup::Layout`. Then benefit is that the
|
818
|
-
stylenames assigned to your views will be used in the dictionary that the
|
878
|
+
If you are using [Nick Quaranto][qrush]'s [motion-layout][] gem, you can use it
|
879
|
+
from within any class that includes `Teacup::Layout`. Then benefit is that the
|
880
|
+
Teacup stylenames assigned to your views will be used in the dictionary that the
|
819
881
|
ASCII-based system relies on.
|
820
882
|
|
821
883
|
```ruby
|
@@ -887,13 +949,18 @@ The `fixed` methods pin the view to one of nine locations:
|
|
887
949
|
------------+---------------+-------------
|
888
950
|
bottom_left | bottom_middle | bottom_right
|
889
951
|
|
952
|
+
e.g. fixed_top_left, fixed_middle, fixed_bottom_right
|
953
|
+
|
890
954
|
The `float` methods fill in the last gap, when you don't want your view pinned
|
891
955
|
to any corner, and you don't want it to change size.
|
892
956
|
|
957
|
+
# incidentally:
|
893
958
|
float_horizontal | float_vertical == fixed_middle
|
894
959
|
|
895
960
|
#### Device detection
|
896
961
|
|
962
|
+
*iOS only*
|
963
|
+
|
897
964
|
Because the stylesheets are defined in a block, you can perform tests for device
|
898
965
|
and screen size before setting styles. For instance, on an ipad you might want
|
899
966
|
to have a larger margin than on the iphone.
|
@@ -931,6 +998,8 @@ end
|
|
931
998
|
|
932
999
|
#### Rotation helpers
|
933
1000
|
|
1001
|
+
*iOS only*
|
1002
|
+
|
934
1003
|
Because you can animate changes to the stylename or style_classes, you can make
|
935
1004
|
it pretty easy to apply rotation effects to a `UIView` or `CALayer`. The
|
936
1005
|
`style_classes` property is especially useful for this purpose.
|
@@ -1370,7 +1439,6 @@ tool helps you build great apps!
|
|
1370
1439
|
[advanced]: https://github.com/rubymotion/teacup/#advanced-teacup-tricks
|
1371
1440
|
[calculations]: https://github.com/rubymotion/teacup/#frame-calculations
|
1372
1441
|
[dummy.rb]: https://github.com/rubymotion/teacup/tree/master/lib/dummy.rb
|
1373
|
-
[other-handlers]: https://github.com/rubymotion/teacup/tree/master/lib/teacup/z_core_extensions/z_handlers.rb
|
1374
1442
|
|
1375
1443
|
[Pixate]: http://www.pixate.com
|
1376
1444
|
[NUI]: https://github.com/tombenner/nui
|
data/lib/teacup/version.rb
CHANGED
@@ -0,0 +1,131 @@
|
|
1
|
+
##|
|
2
|
+
##| NSView.frame
|
3
|
+
##|
|
4
|
+
Teacup.handler NSView, :left, :x do |target, x|
|
5
|
+
f = target.frame
|
6
|
+
f.origin.x = Teacup::calculate(target, :width, x)
|
7
|
+
target.frame = f
|
8
|
+
end
|
9
|
+
|
10
|
+
Teacup.handler NSView, :right do |target, r|
|
11
|
+
f = target.frame
|
12
|
+
f.origin.x = Teacup::calculate(target, :width, r) - f.size.width
|
13
|
+
target.frame = f
|
14
|
+
end
|
15
|
+
|
16
|
+
Teacup.handler NSView, :center_x, :middle_x do |target, x|
|
17
|
+
c = target.center
|
18
|
+
c.x = Teacup::calculate(target, :width, x)
|
19
|
+
target.center = c
|
20
|
+
end
|
21
|
+
|
22
|
+
Teacup.handler NSView, :top, :y do |target, y|
|
23
|
+
f = target.frame
|
24
|
+
f.origin.y = Teacup::calculate(target, :height, y)
|
25
|
+
target.frame = f
|
26
|
+
end
|
27
|
+
|
28
|
+
Teacup.handler NSView, :bottom do |target, b|
|
29
|
+
f = target.frame
|
30
|
+
f.origin.y = Teacup::calculate(target, :height, b) - f.size.height
|
31
|
+
target.frame = f
|
32
|
+
end
|
33
|
+
|
34
|
+
Teacup.handler NSView, :center_y, :middle_y do |target, y|
|
35
|
+
c = target.center
|
36
|
+
c.y = Teacup::calculate(target, :height, y)
|
37
|
+
target.center = c
|
38
|
+
end
|
39
|
+
|
40
|
+
Teacup.handler NSView, :width do |target, w|
|
41
|
+
f = target.frame
|
42
|
+
f.size.width = Teacup::calculate(target, :width, w)
|
43
|
+
target.frame = f
|
44
|
+
end
|
45
|
+
|
46
|
+
Teacup.handler NSView, :height do |target, h|
|
47
|
+
f = target.frame
|
48
|
+
f.size.height = Teacup::calculate(target, :height, h)
|
49
|
+
target.frame = f
|
50
|
+
end
|
51
|
+
|
52
|
+
Teacup.handler NSView, :size do |target, size|
|
53
|
+
f = target.frame
|
54
|
+
size_x = Teacup::calculate(target, :width, size[0])
|
55
|
+
size_y = Teacup::calculate(target, :height, size[1])
|
56
|
+
f.size = [size_x, size_y]
|
57
|
+
target.frame = f
|
58
|
+
end
|
59
|
+
|
60
|
+
Teacup.handler NSView, :origin do |target, origin|
|
61
|
+
f = target.frame
|
62
|
+
origin_x = Teacup::calculate(target, :width, origin[0])
|
63
|
+
origin_y = Teacup::calculate(target, :height, origin[1])
|
64
|
+
f.origin = [origin_x, origin_y]
|
65
|
+
target.frame = f
|
66
|
+
end
|
67
|
+
|
68
|
+
Teacup.handler NSView, :center do |target, center|
|
69
|
+
center_x = Teacup::calculate(target, :width, center[0])
|
70
|
+
center_y = Teacup::calculate(target, :height, center[1])
|
71
|
+
target.center = [center_x, center_y]
|
72
|
+
end
|
73
|
+
|
74
|
+
Teacup.handler NSView, :size do |target, size|
|
75
|
+
# odd... if I changed these to .is_a?, weird errors happen. Use ===
|
76
|
+
if Symbol === size && size == :full
|
77
|
+
if target.superview
|
78
|
+
size = target.superview.bounds.size
|
79
|
+
else
|
80
|
+
size = target.frame.size
|
81
|
+
end
|
82
|
+
elsif Array === size
|
83
|
+
size = [Teacup::calculate(target, :width, size[0]), Teacup::calculate(target, :height, size[1])]
|
84
|
+
end
|
85
|
+
f = target.frame
|
86
|
+
f.size = size
|
87
|
+
target.frame = f
|
88
|
+
end
|
89
|
+
|
90
|
+
Teacup.handler NSView, :frame do |target, frame|
|
91
|
+
# odd... if I changed these to .is_a?, weird errors happen. Use ===
|
92
|
+
if Symbol === frame && frame == :full
|
93
|
+
if target.superview
|
94
|
+
frame = target.superview.bounds
|
95
|
+
else
|
96
|
+
frame = target.frame
|
97
|
+
end
|
98
|
+
elsif Array === frame && frame.length == 4
|
99
|
+
frame = [
|
100
|
+
[Teacup::calculate(target, :width, frame[0]), Teacup::calculate(target, :height, frame[1])],
|
101
|
+
[Teacup::calculate(target, :width, frame[2]), Teacup::calculate(target, :height, frame[3])]
|
102
|
+
]
|
103
|
+
elsif (Array === frame && frame.length == 2) || CGRect === frame
|
104
|
+
frame = [
|
105
|
+
[Teacup::calculate(target, :width, frame[0][0]), Teacup::calculate(target, :height, frame[0][1])],
|
106
|
+
[Teacup::calculate(target, :width, frame[1][0]), Teacup::calculate(target, :height, frame[1][1])]
|
107
|
+
]
|
108
|
+
end
|
109
|
+
target.frame = frame
|
110
|
+
end
|
111
|
+
|
112
|
+
Teacup.handler NSView, :gradient do |target, gradient|
|
113
|
+
gradient_layer = target.instance_variable_get(:@teacup_gradient_layer) || begin
|
114
|
+
gradient_layer = CAGradientLayer.layer
|
115
|
+
gradient_layer.frame = target.bounds
|
116
|
+
target.layer.insertSublayer(gradient_layer, atIndex:0)
|
117
|
+
gradient_layer
|
118
|
+
end
|
119
|
+
|
120
|
+
gradient.each do |key, value|
|
121
|
+
case key.to_s
|
122
|
+
when 'colors'
|
123
|
+
colors = [value].flatten.collect { |color| color.is_a?(UIColor) ? color.CGColor : color }
|
124
|
+
gradient_layer.colors = colors
|
125
|
+
else
|
126
|
+
gradient_layer.send("#{key}=", value)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
target.instance_variable_set(:@teacup_gradient_layer, gradient_layer)
|
131
|
+
end
|
data/lib/teacup-osx/style.rb
CHANGED
@@ -1,43 +1,22 @@
|
|
1
1
|
module Teacup
|
2
2
|
# The Style class is where the precedence rules are applied. A Style can
|
3
3
|
# query the Stylesheet that created it to look up other styles (for
|
4
|
-
# `extends:`) and to import other Stylesheets.
|
5
|
-
# a `UIView` instance) and orientation, it will merge those in appropriately
|
6
|
-
# as well.
|
4
|
+
# `extends:`) and to import other Stylesheets.
|
7
5
|
class Style < Hash
|
8
6
|
attr_accessor :stylename
|
9
7
|
attr_accessor :stylesheet
|
10
8
|
|
11
|
-
#
|
12
|
-
#
|
13
|
-
|
14
|
-
@supports ||= {}
|
15
|
-
end
|
16
|
-
|
17
|
-
# returns the value - `nil` has special meaning when querying :portrait or :upside_up
|
18
|
-
def supports? orientation_key
|
19
|
-
false
|
20
|
-
end
|
21
|
-
|
9
|
+
# orientation is completely ignored on OS X, but the Teacup code was written
|
10
|
+
# to support them, and it was easier to ignore the orientation system than
|
11
|
+
# refactor it out of the shared code base.
|
22
12
|
def build(target=nil, rotation_orientation=nil, seen={})
|
23
13
|
properties = Style.new
|
24
14
|
properties.stylename = self.stylename
|
25
15
|
properties.stylesheet = self.stylesheet
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# in order to preserve the "local-first" override, we need to *delete*
|
31
|
-
# the keys in imported_stylesheets and extended_properties that are
|
32
|
-
# present in this style - even though we don't ultimately *apply* the
|
33
|
-
# styles
|
34
|
-
delete_keys = self.keys
|
35
|
-
orientation = rotation_orientation
|
36
|
-
else
|
37
|
-
delete_keys = []
|
38
|
-
properties.update(self)
|
39
|
-
orientation = nil
|
40
|
-
end
|
17
|
+
delete_keys = []
|
18
|
+
properties.update(self)
|
19
|
+
orientation = nil
|
41
20
|
|
42
21
|
# now we can merge extends, and imported_stylesheets. before merging,
|
43
22
|
# these will go through the same process that we just finished on the
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teacup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Teacup is a community-driven DSL for making CSS-like styling, and
|
15
15
|
layouts for
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/teacup-osx/core_extensions/ns_window.rb
|
63
63
|
- lib/teacup-osx/core_extensions/ns_window_controller.rb
|
64
64
|
- lib/teacup-osx/core_extensions/teacup_handlers.rb
|
65
|
+
- lib/teacup-osx/core_extensions/z_core_extensions.rb
|
65
66
|
- lib/teacup-osx/dummy.rb
|
66
67
|
- lib/teacup-osx/handler.rb
|
67
68
|
- lib/teacup-osx/style.rb
|