ruby_motion_query 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/LICENSE +21 -0
- data/README.md +964 -0
- data/lib/ruby_motion_query.rb +8 -0
- data/motion/ext.rb +34 -0
- data/motion/ruby_motion_query/actions.rb +44 -0
- data/motion/ruby_motion_query/animations.rb +125 -0
- data/motion/ruby_motion_query/app.rb +71 -0
- data/motion/ruby_motion_query/base.rb +161 -0
- data/motion/ruby_motion_query/color.rb +80 -0
- data/motion/ruby_motion_query/data.rb +32 -0
- data/motion/ruby_motion_query/device.rb +73 -0
- data/motion/ruby_motion_query/enumerablish.rb +74 -0
- data/motion/ruby_motion_query/event.rb +125 -0
- data/motion/ruby_motion_query/events.rb +65 -0
- data/motion/ruby_motion_query/factory.rb +32 -0
- data/motion/ruby_motion_query/font.rb +66 -0
- data/motion/ruby_motion_query/format.rb +54 -0
- data/motion/ruby_motion_query/image.rb +79 -0
- data/motion/ruby_motion_query/position.rb +45 -0
- data/motion/ruby_motion_query/selectors.rb +56 -0
- data/motion/ruby_motion_query/stylers/ui_button_styler.rb +32 -0
- data/motion/ruby_motion_query/stylers/ui_control_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_date_picker_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_image_view_styler.rb +14 -0
- data/motion/ruby_motion_query/stylers/ui_label_styler.rb +36 -0
- data/motion/ruby_motion_query/stylers/ui_navigation_bar_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_page_control_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_refresh_control_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_scroll_view_styler.rb +10 -0
- data/motion/ruby_motion_query/stylers/ui_segmented_control_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_slider_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_stepper_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_switch_styler.rb +10 -0
- data/motion/ruby_motion_query/stylers/ui_tab_bar_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_table_view_cell_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_table_view_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_text_field_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_text_view_styler.rb +8 -0
- data/motion/ruby_motion_query/stylers/ui_view_styler.rb +243 -0
- data/motion/ruby_motion_query/stylesheet.rb +185 -0
- data/motion/ruby_motion_query/subviews.rb +52 -0
- data/motion/ruby_motion_query/tags.rb +14 -0
- data/motion/ruby_motion_query/traverse.rb +183 -0
- data/motion/ruby_motion_query/utils.rb +53 -0
- metadata +89 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
class Event
|
3
|
+
attr_accessor :block, :recognizer, :event, :sdk_event_or_recognizer, :gesture, :sender
|
4
|
+
|
5
|
+
def initialize(sender, event, block)
|
6
|
+
if @sdk_event_or_recognizer = VIEW_GESTURES[event]
|
7
|
+
@gesture = true
|
8
|
+
elsif sender.is_a?(UIControl)
|
9
|
+
@gesture = false
|
10
|
+
@sdk_event_or_recognizer = CONTROL_EVENTS[event]
|
11
|
+
end
|
12
|
+
|
13
|
+
if @sdk_event_or_recognizer
|
14
|
+
@sender = sender
|
15
|
+
@event = event
|
16
|
+
@block = block
|
17
|
+
|
18
|
+
if @gesture
|
19
|
+
@recognizer = @sdk_event_or_recognizer.alloc.initWithTarget(self, action: :handle_gesture_or_event)
|
20
|
+
@sender.addGestureRecognizer(@recognizer)
|
21
|
+
else
|
22
|
+
@sender.addTarget(self, action: :handle_gesture_or_event, forControlEvents: @sdk_event_or_recognizer)
|
23
|
+
end
|
24
|
+
else
|
25
|
+
raise "[RMQ Error] Invalid event or gesture or invalid sender (#{event}). Example of use: button.on(:touch) { my_code }"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def handle_gesture_or_event
|
30
|
+
case @block.arity
|
31
|
+
when 2
|
32
|
+
@block.call(@sender, self)
|
33
|
+
when 1
|
34
|
+
@block.call(@sender)
|
35
|
+
else
|
36
|
+
@block.call
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_options(opts)
|
41
|
+
if gesture?
|
42
|
+
@recognizer.tap do |o|
|
43
|
+
o.cancelsTouchesInView = opts[:cancels_touches_in_view] if opts.include?(:cancels_touches_in_view)
|
44
|
+
o.delegate = opts[:delegate] if opts.include?(:delegate)
|
45
|
+
o.numberOfTapsRequired = opts[:taps_required] if opts.include?(:taps_required)
|
46
|
+
o.numberOfTouchesRequired = opts[:fingers_required] if opts.include?(:fingers_required)
|
47
|
+
# TODO, add the rest
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def gesture?
|
53
|
+
@gesture
|
54
|
+
end
|
55
|
+
|
56
|
+
def location
|
57
|
+
if gesture?
|
58
|
+
@recognizer.locationInView(@sender)
|
59
|
+
else
|
60
|
+
@sender.convertRect(@sender.bounds, toView: nil).origin
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def location_in(view)
|
65
|
+
if gesture?
|
66
|
+
@recognizer.locationInView(view)
|
67
|
+
else
|
68
|
+
@sender.convertRect(@sender.bounds, toView: view).origin
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def remove
|
73
|
+
if @sender
|
74
|
+
if self.gesture?
|
75
|
+
@sender.removeGestureRecognizer(@recognizer)
|
76
|
+
else
|
77
|
+
@sender.removeTarget(self, action: :handle_gesture_or_event, forControlEvents: @sdk_event_or_recognizer)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
CONTROL_EVENTS = {
|
83
|
+
touch: UIControlEventTouchUpInside,
|
84
|
+
touch_up: UIControlEventTouchUpInside,
|
85
|
+
touch_down: UIControlEventTouchDown,
|
86
|
+
touch_start: UIControlEventTouchDown | UIControlEventTouchDragEnter,
|
87
|
+
touch_stop: UIControlEventTouchUpInside | UIControlEventTouchCancel | UIControlEventTouchDragExit,
|
88
|
+
change: UIControlEventValueChanged | UIControlEventEditingChanged,
|
89
|
+
|
90
|
+
touch_down_repeat: UIControlEventTouchDownRepeat,
|
91
|
+
touch_drag_inside: UIControlEventTouchDragInside,
|
92
|
+
touch_drag_outside: UIControlEventTouchDragOutside,
|
93
|
+
touch_drag_enter: UIControlEventTouchDragEnter,
|
94
|
+
touch_drag_exit: UIControlEventTouchDragExit,
|
95
|
+
touch_up_inside: UIControlEventTouchUpInside,
|
96
|
+
touch_up_outside: UIControlEventTouchUpOutside,
|
97
|
+
touch_cancel: UIControlEventTouchCancel,
|
98
|
+
|
99
|
+
value_changed: UIControlEventValueChanged,
|
100
|
+
|
101
|
+
editing_did_begin: UIControlEventEditingDidBegin,
|
102
|
+
editing_changed: UIControlEventEditingChanged,
|
103
|
+
editing_did_change: UIControlEventEditingChanged,
|
104
|
+
editing_did_end: UIControlEventEditingDidEnd,
|
105
|
+
editing_did_endonexit: UIControlEventEditingDidEndOnExit,
|
106
|
+
|
107
|
+
all_touch: UIControlEventAllTouchEvents,
|
108
|
+
all_editing: UIControlEventAllEditingEvents,
|
109
|
+
|
110
|
+
application: UIControlEventApplicationReserved,
|
111
|
+
system: UIControlEventSystemReserved,
|
112
|
+
all: UIControlEventAllEvents
|
113
|
+
}
|
114
|
+
|
115
|
+
VIEW_GESTURES = {
|
116
|
+
tap: UITapGestureRecognizer,
|
117
|
+
pinch: UIPinchGestureRecognizer,
|
118
|
+
rotate: UIRotationGestureRecognizer,
|
119
|
+
swipe: UISwipeGestureRecognizer,
|
120
|
+
pan: UIPanGestureRecognizer,
|
121
|
+
long_press: UILongPressGestureRecognizer
|
122
|
+
}
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
class RMQ
|
3
|
+
def on(event, args = {}, &block)
|
4
|
+
selected.each do |view|
|
5
|
+
events(view).on(view, event, args, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
self
|
9
|
+
end
|
10
|
+
|
11
|
+
def off(*events)
|
12
|
+
selected.each do |view|
|
13
|
+
events(view).off(events)
|
14
|
+
end
|
15
|
+
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
def events(view)
|
22
|
+
view.rmq_data.events ||= Events.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Events
|
27
|
+
def initialize
|
28
|
+
@event_set = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_events?
|
32
|
+
!RMQ.is_blank?(@event_set)
|
33
|
+
end
|
34
|
+
|
35
|
+
def has_event?(event)
|
36
|
+
@event_set.include?(event)
|
37
|
+
end
|
38
|
+
|
39
|
+
def on(view, event, args = {}, &block)
|
40
|
+
raise "[RMQ Error] Event already exists on this object: #{event}. Remove first, using .off" if @event_set[event]
|
41
|
+
|
42
|
+
if rmqe = RubyMotionQuery::Event.new(view, event, block)
|
43
|
+
rmqe.set_options(args)
|
44
|
+
|
45
|
+
@event_set[event] = rmqe
|
46
|
+
end
|
47
|
+
|
48
|
+
view
|
49
|
+
end
|
50
|
+
|
51
|
+
def off(*events)
|
52
|
+
events.flatten!
|
53
|
+
events = @event_set.keys if events.length == 0
|
54
|
+
|
55
|
+
events.each do |event|
|
56
|
+
if rm_event = @event_set.delete(event)
|
57
|
+
rm_event.remove
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
self
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
class RMQ
|
3
|
+
# TODO question, should there be a rmq pool to reuse?
|
4
|
+
|
5
|
+
def create_blank_rmq
|
6
|
+
RMQ.create_with_array_and_selectors([], self.selectors, @context)
|
7
|
+
end
|
8
|
+
|
9
|
+
def create_rmq_in_context(*selectors)
|
10
|
+
RMQ.create_with_selectors(selectors, @context)
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def create_with_selectors(selectors, context)
|
16
|
+
RMQ.new.tap do |o|
|
17
|
+
o.context = context
|
18
|
+
o.selectors = selectors
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_with_array_and_selectors(array, selectors, context)
|
23
|
+
RMQ.new.tap do |o|
|
24
|
+
o.context = context
|
25
|
+
o.selectors = selectors
|
26
|
+
o.selected = array # Must be last
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Add custome app-wide fonts here
|
2
|
+
module RubyMotionQuery
|
3
|
+
class RMQ
|
4
|
+
def self.font
|
5
|
+
Font
|
6
|
+
end
|
7
|
+
|
8
|
+
def font
|
9
|
+
Font
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Font
|
14
|
+
class << self
|
15
|
+
# One way to add your own fonts it to open up the Font class and add your
|
16
|
+
# own message.
|
17
|
+
#
|
18
|
+
# STANDARD_FONT = 'Helvetica Neue'
|
19
|
+
# def standard_at_size(size);
|
20
|
+
# UIFont.fontWithName(STANDARD_NAME, size: size)
|
21
|
+
# end
|
22
|
+
# def standard_large ; @standard_large ||= standard_at_size(18) ; end
|
23
|
+
# def standard_medium ; @standard_medium ||= standard_at_size(12) ; end
|
24
|
+
|
25
|
+
|
26
|
+
# Another way is to add named fonts:
|
27
|
+
#
|
28
|
+
# Example
|
29
|
+
# RubyMotionQuery::Font.add_named_font :large, STANDARD_FONT, 44
|
30
|
+
#
|
31
|
+
# # The use like so in your stylesheet:
|
32
|
+
# font = font.large
|
33
|
+
def add_named(key, font_name_or_font, size = nil)
|
34
|
+
font = if font_name_or_font.is_a?(UIFont)
|
35
|
+
font_name_or_font
|
36
|
+
else
|
37
|
+
Font.font_with_name(font_name_or_font, size || 22)
|
38
|
+
end
|
39
|
+
|
40
|
+
Font.define_singleton_method(key) do
|
41
|
+
font
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def font_with_name(name, size)
|
46
|
+
UIFont.fontWithName(name, size: size)
|
47
|
+
end
|
48
|
+
alias :with_name :font_with_name
|
49
|
+
|
50
|
+
# Use this in the console to get a list of font families
|
51
|
+
def family_list
|
52
|
+
UIFont.familyNames.sort
|
53
|
+
end
|
54
|
+
|
55
|
+
def for_family(family)
|
56
|
+
UIFont.fontNamesForFamilyName(family)
|
57
|
+
end
|
58
|
+
|
59
|
+
def system(size = nil)
|
60
|
+
UIFont.systemFontOfSize(size)
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
class RMQ
|
3
|
+
def format
|
4
|
+
Format
|
5
|
+
end
|
6
|
+
def self.format
|
7
|
+
Format
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Format
|
12
|
+
class << self
|
13
|
+
|
14
|
+
# rmq.format.number(1232, '#,##0.##')
|
15
|
+
def numeric(number, format)
|
16
|
+
RubyMotionQuery::Format.numeric_formatter(format).stringFromNumber(number)
|
17
|
+
end
|
18
|
+
alias :number :numeric
|
19
|
+
|
20
|
+
# rmq.format.date(Time.now, 'EEE, MMM d, ''yy')
|
21
|
+
#
|
22
|
+
# See <http://www.unicode.org/reports/tr35/tr35-19.html#Date_Format_Patterns>
|
23
|
+
# for more information about date format strings.
|
24
|
+
def date(date, format)
|
25
|
+
RubyMotionQuery::Format.date_formatter(format).stringFromDate(date)
|
26
|
+
end
|
27
|
+
|
28
|
+
def numeric_formatter(format)
|
29
|
+
@_numeric_formatter ||= {}
|
30
|
+
|
31
|
+
# Caching here is very important for performance
|
32
|
+
@_numeric_formatter[format] ||= begin
|
33
|
+
number_formater = NSNumberFormatter.alloc.init
|
34
|
+
number_formater.setPositiveFormat(format)
|
35
|
+
number_formater
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def date_formatter(format)
|
40
|
+
@_date_formatters ||= {}
|
41
|
+
|
42
|
+
# Caching here is very important for performance
|
43
|
+
@_date_formatters[format] ||= begin
|
44
|
+
format_template = NSDateFormatter.dateFormatFromTemplate(format, options:0,
|
45
|
+
locale: NSLocale.currentLocale)
|
46
|
+
date_formatter = NSDateFormatter.alloc.init
|
47
|
+
date_formatter.setDateFormat(format_template)
|
48
|
+
date_formatter
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
class RMQ
|
3
|
+
def self.image
|
4
|
+
ImageUtils
|
5
|
+
end
|
6
|
+
|
7
|
+
def image
|
8
|
+
ImageUtils
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ImageUtils
|
13
|
+
class << self
|
14
|
+
DEFAULT_IMAGE_EXT = 'png'
|
15
|
+
def resource_for_device(file_base_name, opts = {})
|
16
|
+
resource( RMQ.device.four_inch? ? "#{file_base_name}-568h" : file_base_name, opts)
|
17
|
+
end
|
18
|
+
|
19
|
+
def resource(file_base_name, opts = {})
|
20
|
+
ext = opts[:ext] || DEFAULT_IMAGE_EXT
|
21
|
+
cached = opts[:cached]
|
22
|
+
cached = true if cached.nil?
|
23
|
+
|
24
|
+
if cached
|
25
|
+
UIImage.imageNamed("#{file_base_name}.#{ext}")
|
26
|
+
else
|
27
|
+
file_base_name << '@2x' if RMQ.device.retina?
|
28
|
+
file = NSBundle.mainBundle.pathForResource(file_base_name, ofType: ext)
|
29
|
+
UIImage.imageWithContentsOfFile(file)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def resource_resizable(file_base_name, opts)
|
34
|
+
# TODO, also alloow short syntax, t: instead of top: etc
|
35
|
+
ext = opts[:ext] || DEFAULT_IMAGE_EXT
|
36
|
+
image = resource(file_base_name, opts)
|
37
|
+
image.resizableImageWithCapInsets([opts[:top], opts[:left], opts[:bottom], opts[:right]], resizingMode: UIImageResizingModeStretch)
|
38
|
+
end
|
39
|
+
|
40
|
+
# [FROM Sugarcube, thanks Sugarcube]
|
41
|
+
#
|
42
|
+
# Easily take a snapshot of a `UIView`.
|
43
|
+
#
|
44
|
+
# Calling `from_view` with no arguments will return the image based on the
|
45
|
+
# `bounds` of the image. In the case of container views (notably
|
46
|
+
# `UIScrollView` and its children) this does not include the entire contents,
|
47
|
+
# which is something you probably want.
|
48
|
+
#
|
49
|
+
# If you pass a truthy value to this method, it will use the `contentSize` of
|
50
|
+
# the view instead of the `bounds`, and it will draw all the child views, not
|
51
|
+
# just those that are visible in the viewport.
|
52
|
+
#
|
53
|
+
# It is guaranteed that `true` and `:all` will always have this behavior. In
|
54
|
+
# the future, if this argument becomes something that accepts multiple values,
|
55
|
+
# those two are sacred.
|
56
|
+
def from_view(view, use_content_size = false)
|
57
|
+
scale = UIScreen.mainScreen.scale
|
58
|
+
if use_content_size
|
59
|
+
UIGraphicsBeginImageContextWithOptions(view.contentSize, false, scale)
|
60
|
+
context = UIGraphicsGetCurrentContext()
|
61
|
+
view.subviews.each do |subview|
|
62
|
+
CGContextSaveGState(context)
|
63
|
+
CGContextTranslateCTM(context, subview.frame.origin.x, subview.frame.origin.y)
|
64
|
+
subview.layer.renderInContext(context)
|
65
|
+
CGContextRestoreGState(context)
|
66
|
+
end
|
67
|
+
image = UIGraphicsGetImageFromCurrentImageContext()
|
68
|
+
UIGraphicsEndImageContext()
|
69
|
+
else
|
70
|
+
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, scale)
|
71
|
+
view.layer.renderInContext(UIGraphicsGetCurrentContext())
|
72
|
+
image = UIGraphicsGetImageFromCurrentImageContext()
|
73
|
+
UIGraphicsEndImageContext()
|
74
|
+
end
|
75
|
+
image
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
class RMQ
|
3
|
+
|
4
|
+
def move(opts)
|
5
|
+
# TODO, add centered and from_bottom and from_top, and bottom and top
|
6
|
+
# TODO, add animate option
|
7
|
+
left = opts[:left] || opts[:l] || opts[:x]
|
8
|
+
top = opts[:top] || opts[:t] || opts[:y]
|
9
|
+
width = opts[:width] || opts[:w]
|
10
|
+
height = opts[:height] || opts[:h]
|
11
|
+
|
12
|
+
selected.each do |view|
|
13
|
+
view.frame = [
|
14
|
+
[left || view.origin.x, top || view.origin.y],
|
15
|
+
[width || view.size.width, height || view.size.height]
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
self
|
20
|
+
end
|
21
|
+
alias :resize :move
|
22
|
+
|
23
|
+
def align(direction)
|
24
|
+
# TODO
|
25
|
+
# rmq(UILabel).align(:left)
|
26
|
+
# rmq(UILabel).align(:left, :top)
|
27
|
+
end
|
28
|
+
|
29
|
+
def nudge(opts)
|
30
|
+
left = opts[:left] || opts[:l] || 0
|
31
|
+
right = opts[:right] || opts[:r] || 0
|
32
|
+
up = opts[:up] || opts[:u] || 0
|
33
|
+
down = opts[:down] || opts[:d] || 0
|
34
|
+
|
35
|
+
selected.each do |view|
|
36
|
+
f = view.frame
|
37
|
+
f.origin = [view.origin.x - left + right, view.origin.y + down - up]
|
38
|
+
view.frame = f
|
39
|
+
end
|
40
|
+
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
class RMQ
|
3
|
+
|
4
|
+
def selectors=(value)
|
5
|
+
@selected_dirty = true
|
6
|
+
normalize_selectors(value)
|
7
|
+
@_selectors = value
|
8
|
+
end
|
9
|
+
def selectors
|
10
|
+
@_selectors
|
11
|
+
end
|
12
|
+
|
13
|
+
def match_context(new_selectors)
|
14
|
+
match(context_or_context_view, new_selectors)
|
15
|
+
end
|
16
|
+
|
17
|
+
def match(view, new_selectors)
|
18
|
+
new_selectors.each do |selector|
|
19
|
+
if selector == :tagged
|
20
|
+
return true unless view.rmq_data.has_tag?
|
21
|
+
elsif selector.is_a?(Hash)
|
22
|
+
return true if match_hash(view, selector)
|
23
|
+
elsif selector.is_a?(Symbol)
|
24
|
+
# TODO, make this faster
|
25
|
+
return true if (view.rmq_data.style_name == selector) || view.rmq_data.has_tag?(selector)
|
26
|
+
elsif selector.is_a?(Integer)
|
27
|
+
# TODO, make this hugely faster
|
28
|
+
return true if view.object_id == selector
|
29
|
+
elsif RMQ.is_class?(selector)
|
30
|
+
return true if view.is_a?(selector)
|
31
|
+
else
|
32
|
+
return true if view == selector
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
false
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def match_hash(view, hash)
|
43
|
+
# TODO, check speed, and do sub hashes for stuff like origin
|
44
|
+
# it's probably pretty slow
|
45
|
+
hash.each do |k,v|
|
46
|
+
return true if view.respond_to?(k) && (view.send(k) == v)
|
47
|
+
end
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
def normalize_selectors(a = self.selectors)
|
52
|
+
a.flatten! if a
|
53
|
+
a
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
module Stylers
|
3
|
+
class UIButtonStyler < UIControlStyler
|
4
|
+
|
5
|
+
def text=(value)
|
6
|
+
@view.setTitle(value, forState: UIControlStateNormal)
|
7
|
+
end
|
8
|
+
def text
|
9
|
+
@view.title
|
10
|
+
end
|
11
|
+
|
12
|
+
def font=(value) ; @view.titleLabel.font = value ; end
|
13
|
+
def font ; @view.titleLabel.font ; end
|
14
|
+
|
15
|
+
def color=(value)
|
16
|
+
@view.setTitleColor(value, forState: UIControlStateNormal)
|
17
|
+
end
|
18
|
+
def color
|
19
|
+
@view.titleColor
|
20
|
+
end
|
21
|
+
|
22
|
+
def image_normal=(value)
|
23
|
+
@view.setImage value, forState: UIControlStateNormal
|
24
|
+
end
|
25
|
+
|
26
|
+
def image_highlighted=(value)
|
27
|
+
@view.setImage value, forState: UIControlStateHighlighted
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RubyMotionQuery
|
2
|
+
module Stylers
|
3
|
+
|
4
|
+
class UILabelStyler < UIViewStyler
|
5
|
+
def text=(value) ; @view.text = value ; end
|
6
|
+
def text ; @view.text ; end
|
7
|
+
|
8
|
+
def font=(value) ; @view.font = value ; end
|
9
|
+
def font ; @view.font ; end
|
10
|
+
|
11
|
+
def color=(value) ; @view.textColor = value ; end
|
12
|
+
def color ; @view.textColor ; end
|
13
|
+
|
14
|
+
def text_alignment=(value)
|
15
|
+
@view.textAlignment = TEXT_ALIGNMENTS[value] || value
|
16
|
+
end
|
17
|
+
def text_alignment
|
18
|
+
@view.textAlignment
|
19
|
+
end
|
20
|
+
|
21
|
+
def resize_to_fit_text
|
22
|
+
@view.sizeToFit
|
23
|
+
end
|
24
|
+
alias :size_to_fit :resize_to_fit_text
|
25
|
+
|
26
|
+
TEXT_ALIGNMENTS = {
|
27
|
+
left: NSTextAlignmentLeft,
|
28
|
+
center: NSTextAlignmentCenter,
|
29
|
+
right: NSTextAlignmentRight,
|
30
|
+
justified: NSTextAlignmentJustified,
|
31
|
+
natural: NSTextAlignmentNatural
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|