From af340411703e4d7bbacadb94efcb04482aada229 Mon Sep 17 00:00:00 2001 From: Josh Smith Date: Thu, 24 Oct 2013 11:00:01 -0700 Subject: [PATCH 01/10] Update the README to include accurate information how to use cell_identifier in rmq.create --- README.md | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 2bdde36..258e4dd 100755 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ A fast, muggle, nonpolluting, jQuery-like library for [RubyMotion](http://rubymo ### Other wrapper libraries There are a lot of great wrappers out there such as Teacup and Sugarcube. I've used these and I enjoy them. However, many of the wrappers heavily pollute the standard classes, which is great if you like that sort of thing. RMQ is designed to have minimal pollution, to be very simple and high performance (it will be when it's done). RMQ shouldn't conflict with anything. -RMQ **doesn't require any** other wrapper or gem. +RMQ **doesn't require any** other wrapper or gem. > If you preferred jQuery over Prototype, you'll love RMQ. @@ -98,7 +98,7 @@ The example app works in any orientation, on both iPhone and iPad. Notice how th - an rmq instance is an array-like object containing UIViews - rmq() never returns nil. If nothing is selected, it's an empty [ ] array-like - object + object - an rmq object always (almost always) returns either itself or a new rmq object. This is how chaining works. You do not need to worry if an rmq is blank or not, everything always works without throwing a @@ -183,7 +183,7 @@ Here are the commands available to you: > rmq create shared some_class_used_app_wide > rmq create lib some_class_used_by_multiple_apps - > rmq create collection_view_controller foos + > rmq create collection_view_controller foos # To test the create command without actually creating any files, do: > rmq create view my_view dry_run @@ -242,7 +242,7 @@ all return another rmq instance, so you can chain. You can also do **rmq.length** and **rmq[0]** like an array -**.to_a** gives you an actual array, so will **.get** (this is preferred) +**.to_a** gives you an actual array, so will **.get** (this is preferred) ### Events and Gestures @@ -309,7 +309,7 @@ If you see Event, just remember that's either an event or gesture. I decided to :system :all -# Gestures +# Gestures :tap :pinch :rotate @@ -405,19 +405,19 @@ rmq.view_controller #### Create a view If you want to create a view but not add it to the subviews of any other view, you can -use #create. It's basically #append without the actual appending. +use #create. It's basically #append without the actual appending. This is very handy for stuff like table cells: ```ruby # In your controller that is a delegate for a UITableView def tableView(table_view, cellForRowAtIndexPath: index_path) - cell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin - rmq.create(StoreCell, :store_cell) + cell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin + rmq.create(StoreCell, :store_cell, cell_identifier: CELL_IDENTIFIER) end end # Your cell -class StoreCell < UITableViewCell +class StoreCell < UITableViewCell def rmq_did_create(self_in_rmq) self_in_rmq.append(UILabel, :title_label) # <- this works even though this object isn't in a controller end @@ -436,14 +436,14 @@ rmq(my_view).animate( ``` ```ruby -# As an example, this is the implementation of .animations.throb +# As an example, this is the implementation of .animations.throb rmq(selectors).animate( duration: 0.1, animations: -> (q) { q.style {|st| st.scale = 1.1} }, completion: -> (did_finish, q) { - q.animate( + q.animate( duration: 0.4, animations: -> (cq) { cq.style {|st| st.scale = 1.0} @@ -457,7 +457,7 @@ rmq(selectors).animate( ### Animations -#### Current animations included: +#### Current animations included: ```ruby rmq(my_view).animations.fade_in @@ -483,7 +483,7 @@ rmq.color.from_rgba(128, 128, 128, 0.5) # Add a new standard color rmq.color.add_named :pitch_black, '#000000' -# Or +# Or rmq.color.add_named :pitch_black, rmq.color.black # In a stylesheet you don't need the rmq @@ -503,7 +503,7 @@ rmq.font.for_family('Helvetica') # useful in console font_family = 'Helvetica Neue' font.add_named :large, font_family, 36 font.add_named :medium, font_family, 24 -font.add_named :small, font_family, 18 +font.add_named :small, font_family, 18 # then use them like so rmq.font.large @@ -576,7 +576,7 @@ rmq.device.iphone? rmq.device.four_inch? rmq.device.retina? -# return values are :unkown, :portrait, :portrait_upside_down, :landscape_Left, +# return values are :unkown, :portrait, :portrait_upside_down, :landscape_Left, # :landscape_right, :face_up, :face_down rmq.device.orientation rmq.device.landscape? @@ -605,7 +605,7 @@ RubyMotionQuery::RMQ.controller_for_view(view) RubyMotionQuery::RMQ.view_to_s(view) ``` -### Pollution +### Pollution The following are the only pollution in RMQ @@ -635,7 +635,7 @@ The following are the only pollution in RMQ - models - shared - stylers - - ui_view_styler.rb + - ui_view_styler.rb - ui_button_styler.rb - etc - stylesheets @@ -654,7 +654,7 @@ The following are the only pollution in RMQ - stylers - views -### Debugging +### Debugging Adding rmq_debug=true to rake turns on some debugging features that are too slow or verbose to include in a normal build. It's great for normal use in the simulator, but you'll want to leave it off if you're measuring performance. ``` @@ -750,10 +750,10 @@ class ApplicationStylesheet < RubyMotionQuery::Stylesheet font_family = 'Helvetica Neue' font.add_named :large, font_family, 36 font.add_named :medium, font_family, 24 - font.add_named :small, font_family, 18 + font.add_named :small, font_family, 18 - color.add_named :translucent_black, color.from_rgba(0, 0, 0, 0.4) - color.add_named :battleship_gray, '#7F7F7F' + color.add_named :translucent_black, color.from_rgba(0, 0, 0, 0.4) + color.add_named :battleship_gray, '#7F7F7F' end def label(st) @@ -905,7 +905,7 @@ class MainStylesheet < ApplicationStylesheet end def overlay(st) - st.frame = :full + st.frame = :full st.background_color = color.translucent_black st.hidden = true st.z_position = 99 @@ -1058,13 +1058,13 @@ end #### Add your own stylers -In the example app, look in **/app/stylers**, you can just copy that whole folder to start. Then add methods to the appropriate class. +In the example app, look in **/app/stylers**, you can just copy that whole folder to start. Then add methods to the appropriate class. Here is an example of adding a method to all stylers: ```ruby module RubyMotionQuery module Stylers - class UIViewStyler + class UIViewStyler def border_width=(value) @view.layer.borderWidth = value @@ -1072,7 +1072,7 @@ module RubyMotionQuery def border_width @view.layer.borderWidth end - + end end end @@ -1105,7 +1105,7 @@ class YourView < UIView end end end - + # In your controller rmq.append(YourView, :your_style) ``` @@ -1145,6 +1145,6 @@ RMQ is available under the MIT license. See the LICENSE file for more info. 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request +5. Create new Pull Request [1]: http://infinitered.com/rmq From ea36a0ccd9897c7e88fd192c018f71c7665de065 Mon Sep 17 00:00:00 2001 From: Eric <812048774@qq.com> Date: Thu, 14 Nov 2013 15:23:16 +0800 Subject: [PATCH 02/10] Fixed problems with README.md [tableView: cellForRowAtIndexPath] should return UITableViewCell instance --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 258e4dd..ac3cf09 100755 --- a/README.md +++ b/README.md @@ -411,8 +411,8 @@ This is very handy for stuff like table cells: ```ruby # In your controller that is a delegate for a UITableView def tableView(table_view, cellForRowAtIndexPath: index_path) - cell = tableView.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin - rmq.create(StoreCell, :store_cell, cell_identifier: CELL_IDENTIFIER) + cell = table_view.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin + rmq.create(StoreCell, :store_cell, cell_identifier: CELL_IDENTIFIER).get end end From e5d2f003154e56dea1b70e74030bd53d7e999c2a Mon Sep 17 00:00:00 2001 From: Todd Werth Date: Fri, 29 Nov 2013 12:03:56 -0800 Subject: [PATCH 03/10] Added ability to distribute views vertically and horizontally with a margin --- motion/ruby_motion_query/position.rb | 20 ++++++++++++++++++++ spec/position.rb | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/motion/ruby_motion_query/position.rb b/motion/ruby_motion_query/position.rb index baa474b..277909b 100644 --- a/motion/ruby_motion_query/position.rb +++ b/motion/ruby_motion_query/position.rb @@ -37,6 +37,26 @@ module RubyMotionQuery self end + def distribute(type = :vertical, params = {}) + return 0 if selected.length == 0 + + margin = params[:margin] || 0 + + current_end = 0 - margin + + selected.each do |view| + st = self.styler_for(view) + if type == :horizontal + st.left = current_end + margin + current_end = st.right + else + st.top = current_end + margin + current_end = st.bottom + end + + end + end + # @return [Array] or [CGSize] def location_in_root_view self.location_in(self.root_view) diff --git a/spec/position.rb b/spec/position.rb index 98cded8..8ac465d 100644 --- a/spec/position.rb +++ b/spec/position.rb @@ -39,7 +39,7 @@ describe 'position' do end end - it 'should align multiple views with each other' do + it 'should distribute multiple views with each other' do 1.should == 1 # TODO end From c643ba6b171430acd2745c87a4421b3a6e50dbbf Mon Sep 17 00:00:00 2001 From: Todd Werth Date: Fri, 29 Nov 2013 12:36:56 -0800 Subject: [PATCH 04/10] Added resize_to_fit_subviews to rmq object: rmq(you_view). resize_to_fit_subviews --- motion/ruby_motion_query/position.rb | 22 ++++++++++++++++++++++ spec/position.rb | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/motion/ruby_motion_query/position.rb b/motion/ruby_motion_query/position.rb index 277909b..9b28816 100644 --- a/motion/ruby_motion_query/position.rb +++ b/motion/ruby_motion_query/position.rb @@ -55,6 +55,28 @@ module RubyMotionQuery end end + + self + end + + def resize_to_fit_subviews + selected.each do |view| + st = self.styler_for(view) + + w = 0 + h = 0 + + view.subviews.each do |subview| + sub_st = self.styler_for(subview) + w = [sub_st.right, w].max + h = [sub_st.bottom, h].max + end + + st.width = w if st.width < w + st.height = h if st.height < h + end + + self end # @return [Array] or [CGSize] diff --git a/spec/position.rb b/spec/position.rb index 8ac465d..9b0a492 100644 --- a/spec/position.rb +++ b/spec/position.rb @@ -44,6 +44,11 @@ describe 'position' do # TODO end + it 'should resize to fit subviews' do + 1.should == 1 + # TODO + end + it 'should nudge a view in various directions' do view = @vc.rmq.append(UILabel).get view.origin.x.should == 0 From 334ae8b057f7b1a050ae3384b9c711e52fe33dd6 Mon Sep 17 00:00:00 2001 From: Ken Miller Date: Fri, 29 Nov 2013 12:38:12 -0800 Subject: [PATCH 05/10] making styler.frame= accept a CGRect --- .../stylers/ui_view_styler.rb | 12 +++++----- spec/stylers/_ui_view_styler.rb | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/motion/ruby_motion_query/stylers/ui_view_styler.rb b/motion/ruby_motion_query/stylers/ui_view_styler.rb index ad9005a..03c7abe 100644 --- a/motion/ruby_motion_query/stylers/ui_view_styler.rb +++ b/motion/ruby_motion_query/stylers/ui_view_styler.rb @@ -2,7 +2,7 @@ module RubyMotionQuery module Stylers # When you create a styler, always inherit UIViewStyler - class UIViewStyler + class UIViewStyler def initialize(view) @view = view end @@ -49,6 +49,8 @@ module RubyMotionQuery f.size.height =h[:h] || h[:height] || f.size.height @view.frame = f + else + @view.frame = value end end def frame @@ -68,7 +70,7 @@ module RubyMotionQuery value = [ [h[:l], h[:t]], [ - sbounds.size.width - h[:l] - h[:r], + sbounds.size.width - h[:l] - h[:r], sbounds.size.height - h[:t] - h[:b] ]] @@ -181,7 +183,7 @@ module RubyMotionQuery case option when :horizontal # Not using parent.center.x here for orientation - self.center_x = parent.bounds.size.width / 2 + self.center_x = parent.bounds.size.width / 2 when :vertical self.center_y = parent.bounds.size.height / 2 else @@ -196,7 +198,7 @@ module RubyMotionQuery def background_color @view.backgroundColor end - + def background_image=(value) @view.backgroundColor = UIColor.colorWithPatternImage(value) end @@ -246,7 +248,7 @@ module RubyMotionQuery end def rotation=(new_angle) - radians = new_angle * Math::PI / 180 + radians = new_angle * Math::PI / 180 @view.transform = CGAffineTransformMakeRotation(radians) end diff --git a/spec/stylers/_ui_view_styler.rb b/spec/stylers/_ui_view_styler.rb index 302a050..29a30e7 100644 --- a/spec/stylers/_ui_view_styler.rb +++ b/spec/stylers/_ui_view_styler.rb @@ -17,6 +17,10 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet st.frame = {left: 5, t: 10} end + def real_frame(st) + st.frame = CGRectMake(5, 10, 20, 30) + end + def ui_view_kitchen_sink(st) st.frame = {l: 1, t: 2, w: 3, h: 4} st.frame = {left: 1, top: 2, width: 3, height: 4} @@ -59,7 +63,7 @@ shared 'styler' do view.origin.x.should == 1 view.origin.y.should == 2 end - + it 'should return the view from the styler' do view = @vc.rmq.append(@view_klass, :my_style).get styler = @vc.rmq.styler_for(view) @@ -129,6 +133,14 @@ describe 'ui_view_styler' do view.frame.size.height.should == 30 end + it 'should set a real frame' do + view = @vc.rmq.append(@view_klass, :real_frame).get + view.frame.origin.x.should == 5 + view.frame.origin.y.should == 10 + view.frame.size.width.should == 20 + view.frame.size.height.should == 30 + end + it 'should keep existing frame values if not an entire frame is specified' do view = @vc.rmq.append(@view_klass).get view.frame = [[1,2],[3,4]] @@ -142,9 +154,9 @@ describe 'ui_view_styler' do view.frame = [[1,2],[3,4]] @vc.rmq(view).apply_style(:partial_frame_location) - view.frame.origin.x.should == 5 - view.frame.origin.y.should == 10 - view.frame.size.width.should == 3 - view.frame.size.height.should == 4 + view.frame.origin.x.should == 5 + view.frame.origin.y.should == 10 + view.frame.size.width.should == 3 + view.frame.size.height.should == 4 end end From 2e3c5fb0164d29b6cc9957e7e71cd6adb588b443 Mon Sep 17 00:00:00 2001 From: Todd Werth Date: Fri, 29 Nov 2013 12:44:16 -0800 Subject: [PATCH 06/10] Changed distribute to set the top to the top of the first view --- motion/ruby_motion_query/position.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/motion/ruby_motion_query/position.rb b/motion/ruby_motion_query/position.rb index 9b28816..2b5f4bb 100644 --- a/motion/ruby_motion_query/position.rb +++ b/motion/ruby_motion_query/position.rb @@ -41,11 +41,13 @@ module RubyMotionQuery return 0 if selected.length == 0 margin = params[:margin] || 0 - - current_end = 0 - margin + current_end = nil selected.each do |view| st = self.styler_for(view) + + current_end = (st.top - margin) unless current_end + if type == :horizontal st.left = current_end + margin current_end = st.right From c560fe68d21e49108b49db60b92a8fae6c475afe Mon Sep 17 00:00:00 2001 From: Ken Miller Date: Fri, 29 Nov 2013 12:51:12 -0800 Subject: [PATCH 07/10] additional test case --- spec/stylers/_ui_view_styler.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/stylers/_ui_view_styler.rb b/spec/stylers/_ui_view_styler.rb index 29a30e7..c2bbea0 100644 --- a/spec/stylers/_ui_view_styler.rb +++ b/spec/stylers/_ui_view_styler.rb @@ -21,6 +21,10 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet st.frame = CGRectMake(5, 10, 20, 30) end + def array_frame(st) + st.frame = [[5, 10], [20, 30]] + end + def ui_view_kitchen_sink(st) st.frame = {l: 1, t: 2, w: 3, h: 4} st.frame = {left: 1, top: 2, width: 3, height: 4} @@ -141,6 +145,14 @@ describe 'ui_view_styler' do view.frame.size.height.should == 30 end + it 'should set an array frame' do + view = @vc.rmq.append(@view_klass, :array_frame).get + view.frame.origin.x.should == 5 + view.frame.origin.y.should == 10 + view.frame.size.width.should == 20 + view.frame.size.height.should == 30 + end + it 'should keep existing frame values if not an entire frame is specified' do view = @vc.rmq.append(@view_klass).get view.frame = [[1,2],[3,4]] From 9257ad159508d7f5f32700c421f13f367b242be7 Mon Sep 17 00:00:00 2001 From: Todd Werth Date: Fri, 29 Nov 2013 16:24:42 -0800 Subject: [PATCH 08/10] Added array of margins for distribute, and ignoring views with 0 height --- motion/ruby_motion_query/position.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/motion/ruby_motion_query/position.rb b/motion/ruby_motion_query/position.rb index 2b5f4bb..bd6861f 100644 --- a/motion/ruby_motion_query/position.rb +++ b/motion/ruby_motion_query/position.rb @@ -40,19 +40,27 @@ module RubyMotionQuery def distribute(type = :vertical, params = {}) return 0 if selected.length == 0 + margins = params[:margins] margin = params[:margin] || 0 current_end = nil - selected.each do |view| + selected.each_with_index do |view, i| st = self.styler_for(view) + next if st.height == 0 - current_end = (st.top - margin) unless current_end + view_margin = if (margins && margins[i]) + margins[i] + else + margin + end + + current_end = (st.top - view_margin) unless current_end if type == :horizontal - st.left = current_end + margin + st.left = current_end + view_margin current_end = st.right else - st.top = current_end + margin + st.top = current_end + view_margin current_end = st.bottom end From 481904036068b8defbbdffc1e7bdffd0e17fc537 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 1 Dec 2013 21:20:46 -0500 Subject: [PATCH 09/10] argument name should be st following the rmq style changed argument name from `sv` to `st` --- motion/ruby_motion_query/stylesheet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motion/ruby_motion_query/stylesheet.rb b/motion/ruby_motion_query/stylesheet.rb index df5857b..607c522 100644 --- a/motion/ruby_motion_query/stylesheet.rb +++ b/motion/ruby_motion_query/stylesheet.rb @@ -92,7 +92,7 @@ module RubyMotionQuery view.rmq_data.style_name = style_name rescue NoMethodError => e if e.message =~ /.*#{style_name.to_s}.*/ - puts "\n[RMQ ERROR] style_name :#{style_name} doesn't exist for a #{view.class.name}. Add 'def #{style_name}(sv)' to #{stylesheet.class.name} class\n\n" + puts "\n[RMQ ERROR] style_name :#{style_name} doesn't exist for a #{view.class.name}. Add 'def #{style_name}(st)' to #{stylesheet.class.name} class\n\n" else raise e end From 2bd775616d61df1a510dbab013ad29035280ac72 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 1 Dec 2013 21:48:16 -0500 Subject: [PATCH 10/10] only invoke public methods __send__ also invokes private methods. In this case I think private method should not be invoked. --- motion/ruby_motion_query/stylesheet.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/motion/ruby_motion_query/stylesheet.rb b/motion/ruby_motion_query/stylesheet.rb index df5857b..9ae938d 100644 --- a/motion/ruby_motion_query/stylesheet.rb +++ b/motion/ruby_motion_query/stylesheet.rb @@ -88,7 +88,7 @@ module RubyMotionQuery def apply_style_to_view(view, style_name) begin - stylesheet.__send__(style_name, styler_for(view)) + stylesheet.public_send(style_name, styler_for(view)) view.rmq_data.style_name = style_name rescue NoMethodError => e if e.message =~ /.*#{style_name.to_s}.*/