Local merge fix

This commit is contained in:
Todd Werth
2014-04-16 15:02:53 -07:00
parent 978f614f95
commit 4713717ab4
9 changed files with 444 additions and 52 deletions

View File

@@ -27,6 +27,13 @@ module RubyMotionQuery
# /usr/bin/malloc_history 47706 0x937e5c0 | grep "rb_scope__.+?__"
class Debug
class << self
def inspector
if rmq(InspectorView).length == 0
rmq.append(InspectorView).animations.land_and_sink_and_throb
end
end
# Warning, this is very slow
def log_detailed(label, params = {})
return unless RMQ.app.development? || RMQ.app.test?

View File

@@ -0,0 +1,27 @@
module RubyMotionQuery
class InspectorView < UIView
def rmq_build
rmq.style do |st|
st.hidden = true
st.frame = :full
st.background_color = rmq.color.clear
st.scale = 3.0
end
end
def drawRect(rect)
super
context = UIGraphicsGetCurrentContext()
CGContextSetStrokeColorWithColor(context, rmq.color.red.CGColor)
CGContextSetLineWidth(context, 4.0)
CGContextMoveToPoint(context, 0,0)
CGContextAddLineToPoint(context, 200, 300)
CGContextStrokePath(context);
end
end
end

View File

@@ -7,19 +7,9 @@ module RubyMotionQuery
# rmq(my_view).resize(h: 10, w: 100)
#
# @return [RMQ]
def layout(opts)
# TODO, add centered and from_bottom and from_top, and bottom and top
# TODO, add animate option
left = opts[:left] || opts[:l] || opts[:x]
top = opts[:top] || opts[:t] || opts[:y]
width = opts[:width] || opts[:w]
height = opts[:height] || opts[:h]
def layout(params)
selected.each do |view|
view.frame = [
[left || view.origin.x, top || view.origin.y],
[width || view.size.width, height || view.size.height]
]
RubyMotionQuery::Rect.update_view_frame(view, params)
end
self
@@ -28,11 +18,12 @@ module RubyMotionQuery
alias :resize :layout
# @return [RMQ]
def nudge(opts)
left = opts[:left] || opts[:l] || 0
right = opts[:right] || opts[:r] || 0
up = opts[:up] || opts[:u] || 0
down = opts[:down] || opts[:d] || 0
# TODO move nudge implementation into Rect
def nudge(params)
left = params[:left] || params[:l] || 0
right = params[:right] || params[:r] || 0
up = params[:up] || params[:u] || 0
down = params[:down] || params[:d] || 0
selected.each do |view|
f = view.frame

View File

@@ -0,0 +1,254 @@
module RubyMotionQuery
class RMQ
def frame
if selected.length == 1
Rect.frame_for_view(selected.first)
else
selected.map{|s| Rect.frame_for_view(s)}
end
end
def bounds
if selected.length == 1
Rect.bounds_for_view(selected.first)
else
selected.map{|s| Rect.bounds_for_view(s)}
end
end
end
# RMQ Rect
#
# *******************---*******---*************************** value options
# * | | * -------------
# * | | * integer
# * | | * signed integer
# * top | * float
# * | | * :prev
# * | | *
# * --- | * additional size options
# * ***************|***** --- * -----------------------
# * * view | * | * :full
# * * | * | * :half
# * * bottom * | * :quarter
# * * | * | *
# *|--- left ---|* | * | * centered options
# * * | * height * ---------
# * * | * | * :horizontal
# * * | * | * :vertical
# *|-------------------- right -+---|* | * :both
# * * | * | *
# * * | * |--+--from_right----|*
# * * --- * | *
# * ***************---*** --- *
# * | *
# * |------ width - + -| *
# * | *
# * | *
# * from_bottom *
# * | *
# * | *
# * --- *
# ***********************************************************
#
class Rect < CGRect
class << self
def update_view_frame(view, params)
view.frame = view_rect_updated(view, view.frame, params)
end
def update_view_bounds(view, params)
view.bounds = view_rect_updated(view, view.bounds, params)
end
def view_rect_updated(view, rect, params)
if params == :full # Thanks teacup for the name
view.superview.bounds
elsif params.is_a?(Hash)
l = params[:l] || params[:left] || params[:x] || rect.origin.x
t = params[:t] || params[:top] || params[:y] || rect.origin.y
params_w = params[:w] || params[:width]
w = params_w || rect.size.width
params_h = params[:h] || params[:height]
h = params_h || rect.size.height
r = params[:r] || params[:right]
b = params[:b] || params[:bottom]
if sv = view.superview
fr = params[:from_right] || params[:fr]
fb = params[:from_bottom] || params[:fb]
if fr
if params_w
l = sv.bounds.size.width - w - fr
else
w = sv.bounds.size.width - l - fr
end
end
if fb
if params_h
t = sv.bounds.size.height - h - fb
else
h = sv.bounds.size.height - t - fb
end
end
end
rect.origin.x = l
rect.origin.y = t
rect.size.width = w
rect.size.height = h
rect
else
rect
end
end
def frame_for_view(view)
Rect.new(view.frame, view)
end
def bounds_for_view(view)
Rect.new(view.bounds, view)
end
end # << self
def initialize(rect, view = nil)
@view = view
self.origin = rect.origin
self.size = rect.size
end
def left
origin.x
end
alias :l :left
alias :x :left
def right
left + width
end
alias :r :right
def from_right
if @view && (sv = @view.superview)
sv.size.width - right
end
end
def top
origin.y
end
alias :t :top
alias :y :top
def bottom
top + height
end
alias :b :bottom
def from_bottom
if @view && (sv = @view.superview)
sv.size.height - bottom
end
end
def width
size.width
end
alias :w :width
def height
size.height
end
alias :h :height
def z_order
if @view
@view.superview.subviews.to_a.index(@view) # is there a better way??
end
end
def z_position
if @view
@view.layer.zPosition
end
end
def log
def i_f_to_s(int_or_float)
if int_or_float % 1 == 0
int_or_float.to_i.to_s
else
int_or_float.to_s
end
end
l = i_f_to_s(left).ljust(5)
t = i_f_to_s(top).rjust(5)
w = i_f_to_s(width).ljust(5)
h = i_f_to_s(height).ljust(5)
b = i_f_to_s(bottom).rjust(5)
r = i_f_to_s(right).ljust(5)
fr = i_f_to_s(from_right).ljust(5)
fb = i_f_to_s(from_bottom).rjust(5)
ww = i_f_to_s(rmq.app.window.size.width)
wh = i_f_to_s(rmq.app.window.size.height)
if @view && (sv = @view.superview)
sw = i_f_to_s(sv.size.width)
sh = i_f_to_s(sv.size.height)
end
out = %(
*****************---*******---**************************
* | | * window
* #{ t} top | * {w: #{ww}, h: #{wh}}
* | | *
* --- | * superview
* ***************|***** --- * {w: #{sw}, h: #{sh}}
* * | * | *
* * | * | *
* * #{ b} bottom * | * view
* #{ l} * | * | * {l: #{l.strip}, t: #{t.strip},
*|-- left --|* | * | * w: #{w.strip}, h: #{h.strip}}
* * | * height #{ h} *
* * | * | * z_order: #{z_order}
* * #{ r} | * | * z_position: #{z_position}
*|------------------ right -+---|* | *
* * | * | #{fr} *
* * | * |--+--from_right---|*
* * --- * | *
* ***************---*** --- *
* | *
* |------ width - + --| *
* #{ w} | *
* | *
* | *
* #{fb} from_bottom *
* | *
* --- *
********************************************************
)
NSLog out
end
def inspect
format = '#0.#'
s = "Rect {l: #{RMQ.format.numeric(left, format)}"
s << ", t: #{RMQ.format.numeric(top, format)}"
s << ", w: #{RMQ.format.numeric(width, format)}"
s << ", h: #{RMQ.format.numeric(height, format)}}"
s
end
end
end

View File

@@ -27,6 +27,20 @@ module RubyMotionQuery
!@view.rmq_data.style_name.nil?
end
def frame=(value)
RubyMotionQuery::Rect.update_view_frame(view, value)
end
def frame
RubyMotionQuery::Rect.frame_for_view(@view)
end
def bounds=(value)
RubyMotionQuery::Rect.update_view_bounds(view, value)
end
def bounds
RubyMotionQuery::Rect.bounds_for_view(@view)
end
def superview
@view.superview || rmq(@view).root_view || rmq.window
end
@@ -41,40 +55,10 @@ module RubyMotionQuery
end
def tag(tags)
rmq(@view).tag(tags)
end
def frame=(value)
if value == :full # Thanks teacup for the name
@view.frame = self.superview.bounds
elsif value.is_a?(Hash)
f = @view.frame
h = value
f.origin.x = h[:l] || h[:left] || f.origin.x
f.origin.y = h[:t] || h[:top] || f.origin.y
f.size.width = h[:w] || h[:width] || f.size.width
f.size.height = h[:h] || h[:height] || f.size.height
if sv = @view.superview
if fr = (h[:from_right] || h[:fr])
f.origin.x = sv.bounds.size.width - f.size.width - fr
end
if fb = (h[:from_bottom] || h[:fb])
f.origin.y = sv.bounds.size.height - f.size.height - fb
end
end
@view.frame = f
else
@view.frame = value
end
end
def frame
@view.frame
rmq.wrap(@view).tag(tags)
end
# @deprecated - use frame or bounds
def padded=(value)
if value.is_a?(Hash)
h = value
@@ -96,74 +80,102 @@ module RubyMotionQuery
end
end
# @deprecated - use frame or bounds
def left=(value)
f = @view.frame
f.origin.x = value
@view.frame = f
end
# @deprecated - use frame or bounds
def left
@view.origin.x
end
# @deprecated - use frame or bounds
alias :x :left
# @deprecated - use frame or bounds
def top=(value)
f = @view.frame
f.origin.y = value
@view.frame = f
end
# @deprecated - use frame or bounds
def top
@view.origin.y
end
# @deprecated - use frame or bounds
alias :y :top
# @deprecated - use frame or bounds
def width=(value)
f = @view.frame
f.size.width = value
@view.frame = f
end
# @deprecated - use frame or bounds
def width
@view.size.width
end
# @deprecated - use frame or bounds
def height=(value)
f = @view.frame
f.size.height = value
@view.frame = f
end
# @deprecated - use frame or bounds
def height
@view.size.height
end
# @deprecated - use frame or bounds
def bottom=(value)
self.top = value - self.height
end
# @deprecated - use frame or bounds
def bottom
self.top + self.height
end
# @deprecated - use frame or bounds
def from_bottom=(value)
if sv = @view.superview
self.top = sv.bounds.size.height - self.height - value
end
end
# @deprecated - use frame or bounds
def from_bottom
if sv = @view.superview
sv.bounds.size.height - self.top
end
end
# @deprecated - use frame or bounds
def right=(value)
self.left = value - self.width
end
# @deprecated - use frame or bounds
def right
self.left + self.width
end
# @deprecated - use frame or bounds
def from_right=(value)
if superview = @view.superview
self.left = superview.bounds.size.width - self.width - value
end
end
# @deprecated - use frame or bounds
def from_right
if superview = @view.superview
superview.bounds.size.width - self.left

View File

@@ -23,7 +23,6 @@ describe 'position' do
end
it 'should move and resize multiple views' do
view = @vc.rmq.append(UIView).get
view2 = @vc.rmq.append(UIView).get
view3 = @vc.rmq.append(UIView).get
@@ -91,5 +90,4 @@ describe 'position' do
@vc.rmq(view, view_2).location_in_root_view.should == [CGPoint.new(10, 20),CGPoint.new(20, 40)]
end
end

102
spec/rect.rb Normal file
View File

@@ -0,0 +1,102 @@
describe 'rect' do
describe 'view_rect_updated' do
def apply_frame(new_frame)
RubyMotionQuery::Rect.update_view_frame(@view, new_frame)
end
before do
@vc = UIViewController.alloc.init
@view = @vc.rmq.append(UIView).get
end
it 'should apply left or l or x' do
apply_frame l: 1
@view.frame.origin.x.should == 1
apply_frame left: 2
@view.frame.origin.x.should == 2
apply_frame x: 3
@view.frame.origin.x.should == 3
end
it 'should apply top or t or y' do
apply_frame t: 1
@view.frame.origin.y.should == 1
apply_frame top: 2
@view.frame.origin.y.should == 2
apply_frame y: 3
@view.frame.origin.y.should == 3
end
it 'should apply width or w' do
apply_frame w: 3
@view.frame.size.width.should == 3
apply_frame width: 4
@view.frame.size.width.should == 4
end
it 'should apply height or h' do
apply_frame h: 3
@view.frame.size.height.should == 3
apply_frame height: 4
@view.frame.size.height.should == 4
end
it 'should apply with only size' do
apply_frame w: 5, h: 6
@view.frame.size.width.should == 5
@view.frame.size.height.should == 6
end
it 'should apply with only origin' do
apply_frame l: 7, t: 8
@view.frame.origin.x.should == 7
@view.frame.origin.y.should == 8
end
it 'should apply in any order, size and origin' do
apply_frame l: 1, t: 2, w: 3, h: 4
@view.frame.origin.x.should == 1
@view.frame.origin.y.should == 2
@view.frame.size.width.should == 3
@view.frame.size.height.should == 4
apply_frame w: 1, l: 2, h: 3, t: 4
@view.frame.origin.x.should == 2
@view.frame.origin.y.should == 4
@view.frame.size.width.should == 1
@view.frame.size.height.should == 3
apply_frame h: 1, w: 2, t: 3, l: 4
@view.frame.origin.x.should == 4
@view.frame.origin.y.should == 3
@view.frame.size.width.should == 2
@view.frame.size.height.should == 1
end
it 'should apply from_right and fr' do
apply_frame width: 10, from_right: 10
@view.frame.origin.x.should == rmq.device.width - 20
apply_frame w: 20, from_right: 20
@view.frame.origin.x.should == rmq.device.width - 40
end
#it 'should apply from_bottom and fb' do
#end
#it 'should change w when fr and l are set' do
#end
#it 'should change h when fb and t are set' do
#end
#it 'should change l when fr and w are set' do
#end
#it 'should change t when fb and w are set' do
#end
end
end

View File

@@ -31,6 +31,7 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet
st.frame = {left: 1, top: 2, width: 3, height: 4}
st.frame = {from_right: 1, from_bottom: 2, width: 3, height: 4}
st.frame = {fr: 1, fb: 2, w: 3, h: 4}
st.frame = {l: 1, t: 2, fr: 3, fb: 4}
st.left = 20
st.top = 30
st.width = 40

View File

@@ -117,7 +117,7 @@ describe 'subviews' do
@vc.view.subviews.first.should == view
end
it 'should insert view to the beginning of a view\'s subviews' do
it 'should insert view to the beginning of a views subviews' do
1.should == 1
#TODO
end