lib/ios/sugarcube-repl/repl.rb in sugarcube-2.12.3 vs lib/ios/sugarcube-repl/repl.rb in sugarcube-3.0.0
- old
+ new
@@ -1,24 +1,26 @@
module SugarCube
- module Repl
- module_function
+ class << Repl
def window(index=nil)
if index
UIApplication.sharedApplication.windows[index]
else
- UIApplication.sharedApplication.keyWindow
+ (
+ UIApplication.sharedApplication.keyWindow ||
+ UIApplication.sharedApplication.windows[0]
+ )
end
end
def root
window.rootViewController
end
def adjust_init(view)
if view.is_a?(UIView)
- @sugarcube_restore = {
+ @restore = {
frame: SugarCube::Repl.frame,
shadow: SugarCube::Repl.shadow,
}
end
end
@@ -37,40 +39,40 @@
}.each { |key, msg|
if value = shadow[key]
if key == :color and [Symbol, Fixnum, NSString, UIImage, UIColor].any?{|klass| value.is_a? klass}
value = value.uicolor.CGColor
end
- @sugarcube_view.layer.send(msg, value)
- @sugarcube_view.layer.masksToBounds = false
- @sugarcube_view.layer.shouldRasterize = true
+ @adjust_item.layer.send(msg, value)
+ @adjust_item.layer.masksToBounds = false
+ @adjust_item.layer.shouldRasterize = true
end
}
- @sugarcube_view
+ @adjust_item
else
{
- opacity: @sugarcube_view.layer.shadowOpacity,
- radius: @sugarcube_view.layer.shadowRadius,
- offset: @sugarcube_view.layer.shadowOffset,
- color: @sugarcube_view.layer.shadowColor,
- path: @sugarcube_view.layer.shadowPath,
+ opacity: @adjust_item.layer.shadowOpacity,
+ radius: @adjust_item.layer.shadowRadius,
+ offset: @adjust_item.layer.shadowOffset,
+ color: @adjust_item.layer.shadowColor,
+ path: @adjust_item.layer.shadowPath,
}
end
end
alias h shadow
def blink(color=nil)
return unless check_sugarcube_view
- blinking_view = UIView.alloc.initWithFrame([[0,0], @sugarcube_view.frame.size])
+ blinking_view = UIView.alloc.initWithFrame([[0,0], @adjust_item.frame.size])
color = color.uicolor if color.respond_to?(:uicolor)
blinking_view.backgroundColor = color
blinking_view.alpha = 0
- if @sugarcube_view.window
- blinking_view.frame = @sugarcube_view.convertRect([[0, 0], @sugarcube_view.frame.size], toView: @sugarcube_view.window)
- @sugarcube_view.window.addSubview(blinking_view)
+ if @adjust_item.window
+ blinking_view.frame = @adjust_item.convertRect([[0, 0], @adjust_item.frame.size], toView: @adjust_item.window)
+ @adjust_item.window.addSubview(blinking_view)
else
- @sugarcube_view.addSubview(blinking_view)
+ @adjust_item.addSubview(blinking_view)
end
duration = 0.2
UIView.animateWithDuration(duration * 2, animations: ->{ blinking_view.alpha = 1 }, completion: ->(finished) do
UIView.animateWithDuration(duration, animations: ->{ blinking_view.alpha = 0 }, completion: ->(finished) do
@@ -81,22 +83,17 @@
end)
end)
end)
end
- def get_tree_selector(item)
- if item.is_a? UIView
- return :subviews
- elsif item.is_a? UIViewController
- return -> (ctlr) do
- ret = Array.new ctlr.childViewControllers
- if ctlr.presentedViewController && ctlr.presentedViewController.presentingViewController == ctlr
- ret << ctlr.presentedViewController
- end
- ret
+ def register_platform_tree_selectors
+ register_tree_selector(UIView, :subviews)
+ register_tree_selector(UIViewController) do |ctlr|
+ ret = Array.new ctlr.childViewControllers
+ if ctlr.presentedViewController && ctlr.presentedViewController.presentingViewController == ctlr
+ ret << ctlr.presentedViewController
end
- else
- nil
+ ret
end
end
def draw_tree_item(item)
if item.is_a?(UIView)