class SugarCube::Repl
Public Class Methods
adjust(item=nil)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 10 def adjust(item=nil) return @adjust_item unless item if item.is_a? Fixnum @tree_items ||= build_default_tree item = @tree_items[item] end # a/adjust will return this object @adjust_item = item adjust_init(item) item end
adjust_init(item)
click to toggle source
# File lib/android/sugarcube-repl/repl.rb, line 8 def adjust_init(item) if item.is_a?(Android::View::View) @restore = {} end end
blink(color=nil)
click to toggle source
# File lib/ios/sugarcube-repl/repl.rb, line 61 def blink(color=nil) return unless check_sugarcube_view 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 @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 @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 UIView.animateWithDuration(duration, animations: ->{ blinking_view.alpha = 1 }, completion: ->(finished) do UIView.animateWithDuration(duration, animations: ->{ blinking_view.alpha = 0 }, completion: ->(finished) do blinking_view.removeFromSuperview end) end) end) end) end
build_default_tree()
click to toggle source
# File lib/android/sugarcube-repl/repl.rb, line 4 def build_default_tree build_tree(@default) end
build_tree(item)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 159 def build_tree(item) items = call_item_selector(item) ret = [item] return ret if @collapsed_items && @collapsed_items.include?(item) index = 0 items.each do |subitem| ret.concat build_tree(subitem) index += 1 end ret end
call_item_selector(item)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 173 def call_item_selector(item) selector = nil klass = item.class while klass && !selector selector = tree_selectors(klass) klass = klass.superclass end if !selector raise "Unable to determine a SugarCube::Repl::tree selector for #{item.class.to_s}" end if selector.is_a? Proc items = selector.call(item) else items = item.send(selector) end return items || [] end
center(*args)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 149 def center(*args) return unless check_sugarcube_view element = nil total = nil direction = 'h' args.each do |option| case option when String, Symbol # accept string or symbol direction = option.to_s when Numeric unless total total = option elsunless element element = option else raise "I don't know what to do with #{option.inspect}" end else raise "I don't know what to do with #{option.inspect}" end end element = 1 unless element total = 1 unless total view = @adjust_item left = view.origin.x top = view.origin.y if /h|x/.match(direction.downcase) swidth = view.frame.size.width pwidth = view.superview.frame.size.width / total left = (pwidth - swidth) / 2 + pwidth * (element - 1) end if /v|y/.match(direction.downcase) sheight = view.frame.size.height pheight = view.superview.frame.size.height / total top = (pheight - sheight) / 2 + pheight * (element - 1) end self.origin left, top end
Also aliased as: c
check_sugarcube_view()
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 212 def check_sugarcube_view raise 'no view has been assigned to SugarCube::Repl::adjust' unless @adjust_item true end
clear_default()
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 52 def clear_default @default = nil end
collapse(item)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 26 def collapse(item) if item.is_a? Fixnum @tree_items ||= build_default_tree item = @tree_items[item] end @collapsed_items ||= [] if @collapsed_items.include?(item) @collapsed_items.delete(item) else @collapsed_items << item end retval = tree if @collapsed_items @collapsed_items.keep_if { |v| @tree_items.include? v } end retval end
down(val=1)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 47 def down(val=1) return unless check_sugarcube_view f = @adjust_item.frame f.origin.y += val @adjust_item.frame = f puts format_frame(f) @adjust_item end
Also aliased as: d
draw_tree(item, tab=nil, is_last=true, items_index=0)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 102 def draw_tree(item, tab=nil, is_last=true, items_index=0) line = '' space = ' ' if items_index < 10 line << ' ' elsif items_index < 100 line << ' ' elsif items_index > 999 # good god, man! space = '' end line << items_index.to_s + ":" + space if tab line << tab if @collapsed_items && @collapsed_items.include?(item) line << '<<< ' else if is_last line << '`-- ' tab += ' ' else line << '+-- ' tab += '| ' end end else line << '. ' tab = '' end if self == item || @adjust_item == item line << "\033[1m" end line << draw_tree_item(item) if self == item || @adjust_item == item line << "\033[0m" end puts line items = call_item_selector(item) unless @collapsed_items && @collapsed_items.include?(item) index = 0 items.each do |subitem| items_index += 1 if self.respond_to? :draw_tree items_index = draw_tree(subitem, tab, index == items.length - 1, items_index) else items_index = draw_tree(subitem, tab, index == items.length - 1, items_index) end index += 1 end end return items_index end
draw_tree_item(item)
click to toggle source
# File lib/android/sugarcube-repl/repl.rb, line 25 def draw_tree_item(item) # item.to_s 'todo' end
format_frame(frame)
click to toggle source
# File lib/android/sugarcube-repl/repl.rb, line 38 def format_frame(frame) "[[#{frame.origin.x}, #{frame.origin.y}], [#{frame.size.width}, #{frame.size.height}]]" end
frame(f=nil)
click to toggle source
| FRAME
# File lib/cocoa/sugarcube-repl/repl.rb, line 9 def frame(f=nil) return unless check_sugarcube_view return @adjust_item.frame unless f if defined?(SugarCube::CoreGraphics) f = SugarCube::CoreGraphics::Rect(f) end @adjust_item.frame = f puts format_frame(f) @adjust_item end
Also aliased as: f
get_tree_item(item)
click to toggle source
# File lib/android/sugarcube-repl/repl.rb, line 30 def get_tree_item(item) if item.nil? @default else item end end
left(val=1)
click to toggle source
| ORIGIN
# File lib/cocoa/sugarcube-repl/repl.rb, line 25 def left(val=1) SugarCube::Repl::right -val end
Also aliased as: l
origin(x=nil, y=nil)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 59 def origin x=nil, y=nil return unless check_sugarcube_view f = @adjust_item.frame return f.origin unless x if y f.origin.x = x f.origin.y = y else if defined?(SugarCube::CoreGraphics) f.origin = SugarCube::CoreGraphics::Point(x) else f.origin = x end end @adjust_item.frame = f puts format_frame(f) @adjust_item end
Also aliased as: o
register_default_tree_selectors()
click to toggle source
# File lib/android/sugarcube-repl/repl.rb, line 14 def register_default_tree_selectors register_tree_selector(Android::ViewGroup) do |view| views = [] # item.getChildCount.times do |index| # views << item.getChildAt(index) # end views end register_tree_selector(Android::View::View) { |view| [view] } end
register_platform_tree_selectors()
click to toggle source
# File lib/ios/sugarcube-repl/repl.rb, line 87 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 ret end end
register_tree_selector(klass, selector=nil, &sel_blk)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 56 def register_tree_selector(klass, selector=nil, &sel_blk) if selector && sel_blk raise "You can't hand me a block AND a selector. I don't know what to do with both!" end tree_selectors[klass] = selector || sel_blk end
restore()
click to toggle source
| RESTORE
# File lib/cocoa/sugarcube-repl/repl.rb, line 141 def restore return unless check_sugarcube_view @restore.each do |msg, value| SugarCube::Repl.send(msg, value) end end
right(val=1)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 30 def right(val=1) return unless check_sugarcube_view f = @adjust_item.frame f.origin.x += val @adjust_item.frame = f puts format_frame(f) @adjust_item end
Also aliased as: r
root()
click to toggle source
# File lib/ios/sugarcube-repl/repl.rb, line 14 def root window.rootViewController end
set_default(item)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 48 def set_default(item) @default = item end
shadow(shadow=nil)
click to toggle source
| SHADOW
# File lib/ios/sugarcube-repl/repl.rb, line 28 def shadow(shadow=nil) return unless check_sugarcube_view if shadow { opacity: :'shadowOpacity=', radius: :'shadowRadius=', offset: :'shadowOffset=', color: :'shadowColor=', path: :'shadowPath=', }.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 @adjust_item.layer.send(msg, value) @adjust_item.layer.masksToBounds = false @adjust_item.layer.shouldRasterize = true end } @adjust_item else { 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
Also aliased as: h
shorter(val=1)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 100 def shorter(val=1) SugarCube::Repl::taller -val end
Also aliased as: s
size(w=nil, h=nil)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 117 def size(w=nil, h=nil) return unless check_sugarcube_view f = @adjust_item.frame return f.size unless w if h f.size.width = w f.size.height = h else if defined?(SugarCube::CoreGraphics) f.size = SugarCube::CoreGraphics::Size(w) else f.size = w end end @adjust_item.frame = f puts format_frame(f) @adjust_item end
Also aliased as: z
taller(val=1)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 105 def taller(val=1) return unless check_sugarcube_view f = @adjust_item.frame f.size.height += val @adjust_item.frame = f puts format_frame(f) @adjust_item end
Also aliased as: t
thinner(val=1)
click to toggle source
| SIZE
# File lib/cocoa/sugarcube-repl/repl.rb, line 83 def thinner(val=1) SugarCube::Repl::wider -val end
Also aliased as: n
tree(item=nil, selector=nil, &sel_blk)
click to toggle source
@param item this can be a tree-like item (View, ViewController, CALayer
,
Menu) or an integer, in which case it will select that window. Defalt is to display the keyWindow
@param selector If you pass an unsupported object to tree, you will need
to pass a selector as well - this method should return an array of items which are passed recursively to tree
@block sel_blk If a block is passed, it will be used to build the array of
items that are called recursively
# File lib/all/sugarcube-repl/repl.rb, line 85 def tree(item=nil, selector=nil, &sel_blk) item = get_tree_item(item) if selector || sel_blk register_tree_selector(item.class, selector, &sel_blk) end @tree_items = build_tree(item) if @collapsed_items @collapsed_items.keep_if { |v| @tree_items.include? v } end draw_tree(item) puts '' return item end
tree_selectors(klass=nil)
click to toggle source
# File lib/all/sugarcube-repl/repl.rb, line 63 def tree_selectors(klass=nil) if ! @tree_selectors @tree_selectors ||= {} @tree_selectors[nil.class] = -> (foo) { nil } register_default_tree_selectors end if klass @tree_selectors[klass] else @tree_selectors end end
up(val=1)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 42 def up(val=1) SugarCube::Repl::down -val end
Also aliased as: u
wider(val=1)
click to toggle source
# File lib/cocoa/sugarcube-repl/repl.rb, line 88 def wider(val=1) return unless check_sugarcube_view f = @adjust_item.frame f.size.width += val @adjust_item.frame = f puts format_frame(f) @adjust_item end
Also aliased as: w
window(index=nil)
click to toggle source
# File lib/ios/sugarcube-repl/repl.rb, line 4 def window(index=nil) if index UIApplication.sharedApplication.windows[index] elsif UIApplication.sharedApplication.keyWindow UIApplication.sharedApplication.keyWindow else UIApplication.sharedApplication.windows.select { |window| window.subviews.count > 0 }.first end end