mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Merge branch 'master' of github.com:infinitered/rmq
This commit is contained in:
54
README.md
54
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 = table_view.dequeueReusableCellWithIdentifier(CELL_IDENTIFIER) || begin
|
||||
rmq.create(StoreCell, :store_cell, cell_identifier: CELL_IDENTIFIER).get
|
||||
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)
|
||||
```
|
||||
@@ -1148,6 +1148,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
|
||||
|
||||
@@ -37,6 +37,58 @@ module RubyMotionQuery
|
||||
self
|
||||
end
|
||||
|
||||
def distribute(type = :vertical, params = {})
|
||||
return 0 if selected.length == 0
|
||||
|
||||
margins = params[:margins]
|
||||
margin = params[:margin] || 0
|
||||
current_end = nil
|
||||
|
||||
selected.each_with_index do |view, i|
|
||||
st = self.styler_for(view)
|
||||
next if st.height == 0
|
||||
|
||||
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 + view_margin
|
||||
current_end = st.right
|
||||
else
|
||||
st.top = current_end + view_margin
|
||||
current_end = st.bottom
|
||||
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]
|
||||
def location_in_root_view
|
||||
self.location_in(self.root_view)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -88,11 +88,11 @@ 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}.*/
|
||||
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
|
||||
|
||||
@@ -39,7 +39,12 @@ 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
|
||||
|
||||
it 'should resize to fit subviews' do
|
||||
1.should == 1
|
||||
# TODO
|
||||
end
|
||||
|
||||
@@ -17,6 +17,14 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet
|
||||
st.frame = {left: 5, t: 10}
|
||||
end
|
||||
|
||||
def real_frame(st)
|
||||
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}
|
||||
@@ -59,7 +67,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 +137,22 @@ 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 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]]
|
||||
@@ -142,9 +166,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
|
||||
|
||||
Reference in New Issue
Block a user