mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
@@ -79,25 +79,24 @@ class MainController < UIViewController
|
||||
},
|
||||
completion: -> (did_finish, rmq) {
|
||||
rmq.animate( duration: 0.2, animations: -> (rmq) {
|
||||
rmq.style do |sv|
|
||||
sv.scale = 1.0
|
||||
sv.top = 230
|
||||
end
|
||||
})
|
||||
rmq.style do |sv|
|
||||
sv.scale = 1.0
|
||||
sv.top = 230
|
||||
end
|
||||
})
|
||||
})
|
||||
end
|
||||
|
||||
rmq.append(UIButton, :collection_button).on(:touch_up) do |sender|
|
||||
rmq.append(UIButton, :collection_button).on(:touch_up) do
|
||||
controller = CollectionController.new
|
||||
rmq.view_controller.navigationController.pushViewController(controller, animated: true)
|
||||
end
|
||||
|
||||
rmq.append(UIButton, :table_button).on(:touch_up) do |sender|
|
||||
controller = TableController.new
|
||||
rmq.append(UIButton, :table_button).on(:touch_up) do
|
||||
rmq.view_controller.navigationController.pushViewController(controller, animated: true)
|
||||
end
|
||||
|
||||
rmq.append(UIButton, :present_button).on(:touch_up) do |sender|
|
||||
rmq.append(UIButton, :present_button).on(:touch_up) do
|
||||
rmq.view_controller.presentModalViewController(PresentedController.new, animated:true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,14 +11,14 @@ class Section < UIView
|
||||
|
||||
q.append(UISwitch, :section_enabled).on(:change) do |sender|
|
||||
style = sender.isOn ? :section_button_enabled : :section_button_disabled
|
||||
buttons = rmq(sender).parent.find(UIButton).apply_style(style)
|
||||
rmq(sender).parent.find(UIButton).apply_style(style)
|
||||
end
|
||||
|
||||
q.append(UIButton, :start_spinner).on(:tap) do |sender|
|
||||
q.append(UIButton, :start_spinner).on(:tap) do # optional |sender, rmq_event| on events
|
||||
rmq.animations.start_spinner
|
||||
end
|
||||
|
||||
q.append(UIButton, :stop_spinner).on(:tap) do |sender|
|
||||
q.append(UIButton, :stop_spinner).on(:tap) do
|
||||
rmq.animations.stop_spinner
|
||||
end
|
||||
end
|
||||
|
||||
@@ -288,7 +288,7 @@ module RubyMotionQuery
|
||||
|
||||
out << " #{view.class.name[0..21]}"
|
||||
out << " ( #{view.rmq_data.style_name[0..23]} )" if view.rmq_data.style_name
|
||||
out << " #{view.object_id.to_s}"
|
||||
out << " #{view.object_id}"
|
||||
out << " [ #{view.rmq_data.tag_names.join(',')} ]" if view.rmq_data.tag_names.length > 0
|
||||
|
||||
if view.origin
|
||||
|
||||
@@ -53,11 +53,10 @@ module RubyMotionQuery
|
||||
#
|
||||
# @example
|
||||
# font = rmq.font.font_with_name('Helvetica Neue', 18)
|
||||
def font_with_name(name, size)
|
||||
# TODO, should rename this to just with_name, so it's rmq.font.with_name
|
||||
def with_name(name, size)
|
||||
UIFont.fontWithName(name, size: size)
|
||||
end
|
||||
alias :with_name :font_with_name
|
||||
alias :font_with_name :with_name #for backwards compatibility
|
||||
|
||||
# Use this in the console to get a list of font families
|
||||
# @return [Array]
|
||||
|
||||
@@ -317,7 +317,7 @@ module RubyMotionQuery
|
||||
out << left_m
|
||||
out << r.to_s.rjust(4)
|
||||
|
||||
0.upto(@num_columns - 1).each do |c|
|
||||
0.upto(@num_columns - 1).each do
|
||||
out << " ."
|
||||
end
|
||||
end
|
||||
@@ -417,8 +417,6 @@ module RubyMotionQuery
|
||||
return unless @grid
|
||||
|
||||
context = UIGraphicsGetCurrentContext()
|
||||
screen_height = RMQ.device.screen_height
|
||||
screen_width = RMQ.device.screen_width
|
||||
|
||||
CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
|
||||
CGContextSelectFont(context, 'Courier New', 7, KCGEncodingMacRoman)
|
||||
|
||||
@@ -5,7 +5,7 @@ module RubyMotionQuery
|
||||
if existing.length > 0
|
||||
existing.remove
|
||||
end
|
||||
|
||||
|
||||
puts 'The currently selected views will be assigned to $q'
|
||||
|
||||
rmq(window).append(InspectorView).get.update(selected)
|
||||
@@ -14,8 +14,8 @@ module RubyMotionQuery
|
||||
end
|
||||
|
||||
class InspectorView < UIView
|
||||
# A note about this code. InspectorView will be sitting in the Window, not
|
||||
# the current controller. So when you do this rmq(UIButton), that is on the
|
||||
# A note about this code. InspectorView will be sitting in the Window, not
|
||||
# the current controller. So when you do this rmq(UIButton), that is on the
|
||||
# current controller. rmq(self).find(UIButton) would be the buttons in the
|
||||
# inspector.
|
||||
|
||||
@@ -28,7 +28,7 @@ module RubyMotionQuery
|
||||
|
||||
rmq.stylesheet = InspectorStylesheet
|
||||
@self_rmq.apply_style(:inspector_view)
|
||||
|
||||
|
||||
@hud = @self_rmq.append(InspectorHud, :hud).on(:tap) do |sender, rmq_event|
|
||||
select_at rmq_event.location_in(sender)
|
||||
end.get
|
||||
@@ -37,7 +37,7 @@ module RubyMotionQuery
|
||||
|
||||
rmq(root_view).animate(
|
||||
animations: ->(q){ q.apply_style :root_view_scaled },
|
||||
after: ->(finished, q) do
|
||||
after: ->(finished, q) do
|
||||
@self_rmq.animations.fade_in
|
||||
dim_nav
|
||||
end
|
||||
@@ -45,12 +45,12 @@ module RubyMotionQuery
|
||||
|
||||
@stats = @self_rmq.append! UILabel, :stats
|
||||
|
||||
@self_rmq.append(UIButton, :close_button).on(:touch) do |sender|
|
||||
@self_rmq.append(UIButton, :close_button).on(:touch) do
|
||||
rmq(root_view).animate(
|
||||
animations: ->(q){ q.apply_style(:root_view) },
|
||||
after: ->(finished, inner_q){ rmq.stylesheet = @puppets_stylesheet })
|
||||
|
||||
@self_rmq.animations.drop_and_spin(after: ->(finished, inner_q) do
|
||||
@self_rmq.animations.drop_and_spin(after: ->(finished, inner_q) do
|
||||
inner_q.remove
|
||||
end)
|
||||
|
||||
@@ -59,35 +59,35 @@ module RubyMotionQuery
|
||||
show_nav_in_all_its_glory
|
||||
end
|
||||
|
||||
@self_rmq.append(UIButton, :grid_button).on(:touch) do |sender|
|
||||
@self_rmq.append(UIButton, :grid_button).on(:touch) do
|
||||
@hud.draw_grid = !@hud.draw_grid
|
||||
redisplay
|
||||
end
|
||||
|
||||
@self_rmq.append(UIButton, :grid_x_button).on(:touch) do |sender|
|
||||
@self_rmq.append(UIButton, :grid_x_button).on(:touch) do
|
||||
@hud.draw_grid_x = !@hud.draw_grid_x
|
||||
redisplay
|
||||
end
|
||||
|
||||
@self_rmq.append(UIButton, :grid_y_button).on(:touch) do |sender|
|
||||
@self_rmq.append(UIButton, :grid_y_button).on(:touch) do
|
||||
@hud.draw_grid_y = !@hud.draw_grid_y
|
||||
redisplay
|
||||
end
|
||||
|
||||
@self_rmq.append(UIButton, :dim_button).on(:touch) do |sender|
|
||||
@self_rmq.append(UIButton, :dim_button).on(:touch) do
|
||||
@hud.dimmed = !@hud.dimmed
|
||||
redisplay
|
||||
end
|
||||
|
||||
@self_rmq.append(UIButton, :outline_button).on(:touch) do |sender|
|
||||
@self_rmq.append(UIButton, :outline_button).on(:touch) do
|
||||
@hud.views_outlined = !@hud.views_outlined
|
||||
redisplay
|
||||
end
|
||||
|
||||
@self_rmq.find(UIButton).distribute :horizontal, margin: 5
|
||||
@self_rmq.find(UIButton).distribute :horizontal, margin: 5
|
||||
|
||||
@tree_zoomed = false
|
||||
@tree_q = @self_rmq.append(UIScrollView, :tree).on(:tap) do |sender|
|
||||
@tree_q = @self_rmq.append(UIScrollView, :tree).on(:tap) do
|
||||
zoom_tree
|
||||
end
|
||||
end
|
||||
@@ -111,7 +111,7 @@ module RubyMotionQuery
|
||||
end
|
||||
|
||||
def zoom_tree
|
||||
rmq.animate do |q|
|
||||
rmq.animate do
|
||||
if @tree_zoomed
|
||||
@tree_q.apply_style(:tree)
|
||||
else
|
||||
@@ -140,7 +140,7 @@ module RubyMotionQuery
|
||||
|
||||
@hud.selected_views = []
|
||||
root_view = rmq.root_view
|
||||
|
||||
|
||||
if tapped_at
|
||||
@hud.selected.each do |view|
|
||||
rect = view.convertRect(view.bounds, toView: root_view)
|
||||
@@ -209,7 +209,7 @@ module RubyMotionQuery
|
||||
st.frame = {l: left, w: w, h: h}
|
||||
|
||||
st.border_color = rmq.color.from_rgba(34,202,250,0.7).CGColor
|
||||
st.border_width = 0.5
|
||||
st.border_width = 0.5
|
||||
st.background_color = rmq.stylesheet.tree_node_background_color
|
||||
|
||||
end.enable_interaction.on(:tap) do |sender|
|
||||
@@ -225,14 +225,14 @@ module RubyMotionQuery
|
||||
out = %(
|
||||
style_name: :#{view.rmq_data.style_name || ''}
|
||||
#{rmq(view).frame.inspect}
|
||||
#{view.class.name} - object_id: #{view.object_id.to_s}
|
||||
#{view.class.name} - object_id: #{view.object_id}
|
||||
).strip
|
||||
rmq(@stats).show.get.text = out
|
||||
end
|
||||
end
|
||||
|
||||
class InspectorHud < UIView
|
||||
attr_accessor :selected, :selected_views, :dimmed, :views_outlined,
|
||||
attr_accessor :selected, :selected_views, :dimmed, :views_outlined,
|
||||
:draw_grid_x, :draw_grid, :draw_grid_y
|
||||
|
||||
def rmq_build
|
||||
@@ -273,7 +273,6 @@ module RubyMotionQuery
|
||||
# Fixes upside down issue
|
||||
CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0))
|
||||
|
||||
w = rmq.window
|
||||
grid = rmq.stylesheet.grid
|
||||
root_view = rmq.root_view
|
||||
|
||||
@@ -305,7 +304,7 @@ module RubyMotionQuery
|
||||
0.upto(grid.num_columns - 1) do |c|
|
||||
rec = grid[[c, r]]
|
||||
CGContextSetFillColorWithColor(context, @column_fill_color)
|
||||
CGContextFillRect(context, rec.to_cgrect)
|
||||
CGContextFillRect(context, rec.to_cgrect)
|
||||
text = "#{(c+97).chr}#{r}"
|
||||
CGContextSetFillColorWithColor(context, @light_text_color)
|
||||
CGContextShowTextAtPoint(context, rec.origin.x + 1, rec.origin.y + 5, text, text.length)
|
||||
@@ -319,7 +318,7 @@ module RubyMotionQuery
|
||||
rec = view.frame
|
||||
rec.origin = rmq(view).location_in(root_view)
|
||||
#rec.origin = view.origin
|
||||
|
||||
|
||||
if @selected_views.include?(view)
|
||||
CGContextSetFillColorWithColor(context, @view_selected_background_color.CGColor)
|
||||
CGContextSetStrokeColorWithColor(context, @selected_outline_color)
|
||||
@@ -327,7 +326,7 @@ module RubyMotionQuery
|
||||
CGContextSetFillColorWithColor(context, @view_background_color)
|
||||
CGContextSetStrokeColorWithColor(context, @outline_color)
|
||||
end
|
||||
|
||||
|
||||
if @dimmed
|
||||
CGContextFillRect(context, rec)
|
||||
end
|
||||
|
||||
@@ -60,7 +60,7 @@ module RubyMotionQuery
|
||||
selected.each do |view|
|
||||
view.rmq_data.validations.each do |validation|
|
||||
unless validation.valid_status
|
||||
default_error = "Validation Error - input requires valid #{validation.rule_name.to_s}."
|
||||
default_error = "Validation Error - input requires valid #{validation.rule_name}."
|
||||
rule_message = view.rmq_data.validation_errors[validation.rule_name] || default_error
|
||||
errors.push(rule_message)
|
||||
end
|
||||
|
||||
@@ -127,8 +127,8 @@ describe 'device' do
|
||||
@rmq.device.reset_fake_caches
|
||||
end
|
||||
|
||||
describe 'retina?' do
|
||||
#TODO finish
|
||||
it 'detects if the device is retina' do
|
||||
(@rmq.device.screen.scale == 2).should == @rmq.device.retina?
|
||||
end
|
||||
|
||||
it 'should report landscape? and portrait? correctly' do
|
||||
|
||||
@@ -4,24 +4,25 @@ describe 'transversing' do
|
||||
@root_view = @vc.view
|
||||
|
||||
@views_hash = {
|
||||
v_0: {
|
||||
v_0: {
|
||||
klass: UIView,
|
||||
subs: {
|
||||
v_0: {
|
||||
v_0: {
|
||||
klass: UIView,
|
||||
subs: {
|
||||
v_0: { klass: UIView, subs: { } },
|
||||
v_1: { klass: UIImageView, subs: { } },
|
||||
v_2: { klass: UIView, subs: { } }
|
||||
}
|
||||
v_2: { klass: UIView, subs: { } },
|
||||
v_3: { klass: UILabel, subs: { } }
|
||||
}
|
||||
},
|
||||
v_1: { klass: UILabel, subs: { } },
|
||||
v_2: { klass: UIView, subs: { } }
|
||||
v_2: { klass: UIView, subs: { } }
|
||||
}
|
||||
},
|
||||
v_1: { klass: UILabel, subs: { } },
|
||||
v_2: { klass: UILabel, subs: { } },
|
||||
v_3: {
|
||||
v_3: {
|
||||
klass: UIView,
|
||||
subs: {
|
||||
v_0: { klass: UIView, subs: { } },
|
||||
@@ -34,7 +35,7 @@ describe 'transversing' do
|
||||
v_0: { klass: UILabel, subs: { } },
|
||||
v_1: { klass: UIView, subs: { } },
|
||||
v_2: { klass: UIImageView, subs: { } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +47,7 @@ describe 'transversing' do
|
||||
@v0 = @views_hash[:v_0][:view]
|
||||
@v3_v2_v0 = @views_hash[:v_3][:subs][:v_2][:subs][:v_0][:view]
|
||||
@last_image = @views_hash[:v_3][:subs][:v_2][:subs][:v_0][:subs][:v_2][:view]
|
||||
@total_views = 17
|
||||
@total_views = 18
|
||||
end
|
||||
|
||||
it 'locate view given view' do
|
||||
@@ -95,7 +96,7 @@ describe 'transversing' do
|
||||
q = @vc.rmq(UIView).filter do |view|
|
||||
@vc.rmq(view).find.get
|
||||
end
|
||||
q.length.should == 23
|
||||
q.length.should == 25
|
||||
|
||||
q = @vc.rmq(UIView).filter(uniq: true) do |view|
|
||||
@vc.rmq(view).find.get
|
||||
@@ -115,7 +116,8 @@ describe 'transversing' do
|
||||
all[2].should == @views_hash[:v_0][:subs][:v_0][:subs][:v_0][:view]
|
||||
all[3].should == @views_hash[:v_0][:subs][:v_0][:subs][:v_1][:view]
|
||||
all[4].should == @views_hash[:v_0][:subs][:v_0][:subs][:v_2][:view]
|
||||
all[5].should == @views_hash[:v_0][:subs][:v_1][:view]
|
||||
all[5].should == @views_hash[:v_0][:subs][:v_0][:subs][:v_3][:view]
|
||||
all[6].should == @views_hash[:v_0][:subs][:v_1][:view]
|
||||
|
||||
all.last.should == @last_image
|
||||
@last_image.is_a?(UIImageView).should == true
|
||||
@@ -147,8 +149,14 @@ describe 'transversing' do
|
||||
q.length.should == 3
|
||||
q.and(UILabel).length.should == 1
|
||||
q.and(UILabel).get.is_a?(UILabel).should == true
|
||||
q.and(UIView).length.should == 3
|
||||
|
||||
# TODO, a few more scenarios here woudl be good
|
||||
s = @vc.rmq(@v0).children[0].children
|
||||
s.length.should == 4
|
||||
s.and(UILabel).length.should == 1
|
||||
s.and(UILabel).get.is_a?(UILabel).should == true
|
||||
s.and(UIImageView).length.should == 1
|
||||
s.and(UIImageView).get.is_a?(UIImageView).should == true
|
||||
end
|
||||
|
||||
it 'should add parent to selected when using .and_self' do
|
||||
@@ -183,7 +191,7 @@ describe 'transversing' do
|
||||
it 'should return parents / superviews' do
|
||||
@vc.rmq(@last_image).parents.length.should == 4
|
||||
|
||||
@vc.rmq.all.parents.length.should == 6 # All views that have subviews
|
||||
@vc.rmq.all.parents.length.should == 6 # All views that have subviews
|
||||
end
|
||||
|
||||
it 'should return children of a view' do
|
||||
@@ -191,7 +199,7 @@ describe 'transversing' do
|
||||
q.length.should == 3
|
||||
|
||||
q = @vc.rmq(@v0).find # children and sub children
|
||||
q.length.should == 6
|
||||
q.length.should == 7
|
||||
|
||||
q = @vc.rmq(@views_hash[:v_1][:view]).children
|
||||
q.length.should == 0
|
||||
@@ -209,18 +217,18 @@ describe 'transversing' do
|
||||
it 'should return children and sub-children of a view using .find' do
|
||||
@vc.rmq.find.length.should == @total_views
|
||||
@vc.rmq.all.find.length.should == @total_views - 4 # top views
|
||||
@vc.rmq(@v0).find.length.should == 6
|
||||
@vc.rmq(@v0).find(UILabel).length.should == 1
|
||||
@vc.rmq(@v0).find.length.should == 7
|
||||
@vc.rmq(@v0).find(UILabel).length.should == 2
|
||||
@vc.rmq(@v3_v2_v0).find(UIImageView).get.should == @last_image
|
||||
end
|
||||
|
||||
it 'should return children and sub-children of multiple views using .find' do
|
||||
@vc.rmq.all.length.should == @total_views
|
||||
@vc.rmq(UIView).length.should == @total_views
|
||||
@vc.rmq.find.length.should == @total_views
|
||||
@vc.rmq.find(UIView).length.should == @total_views
|
||||
@vc.rmq.all.length.should == @total_views
|
||||
@vc.rmq(UIView).length.should == @total_views
|
||||
@vc.rmq.find.length.should == @total_views
|
||||
@vc.rmq.find(UIView).length.should == @total_views
|
||||
|
||||
@vc.rmq.children(UIView).find(UILabel).length.should == 2
|
||||
@vc.rmq.children(UIView).find(UILabel).length.should == 3
|
||||
end
|
||||
|
||||
it 'should return the siblings of a view' do
|
||||
@@ -228,7 +236,7 @@ describe 'transversing' do
|
||||
q = @vc.rmq(test_view)
|
||||
q.get.should == test_view
|
||||
q = q.siblings
|
||||
q.length.should == (test_view.superview.subviews.length - 1)
|
||||
q.length.should == (test_view.superview.subviews.length - 1)
|
||||
q.get.should.not.include(test_view)
|
||||
end
|
||||
|
||||
@@ -236,7 +244,7 @@ describe 'transversing' do
|
||||
q = @vc.rmq(UIImageView)
|
||||
q.length.should == 2
|
||||
qsiblings = q.siblings
|
||||
qsiblings.length.should == 4
|
||||
qsiblings.length.should == 5
|
||||
qsiblings.get.should.not.include(q.get)
|
||||
|
||||
qsiblings.not(UILabel).length.should == 3
|
||||
@@ -338,7 +346,7 @@ describe 'transversing' do
|
||||
RubyMotionQuery::RMQ.new.wrap(view_1).view_controller.should == @vc
|
||||
view_1.rmq_data.view_controller.should == @vc
|
||||
view_1.rmq.view_controller.should == @vc
|
||||
|
||||
|
||||
view_2 = UIView.alloc.initWithFrame(CGRectZero)
|
||||
view_2.rmq_data.view_controller = @vc2
|
||||
RubyMotionQuery::RMQ.new.wrap(view_2).view_controller.should == @vc2
|
||||
|
||||
Reference in New Issue
Block a user