module RubyCurses::ModStack
Public Instance Methods
each(&block)
click to toggle source
traverse the components and their children
# File lib/canis/core/util/basestack.rb, line 310 def each &block @components.each { |e| traverse e, &block } end
flow(config={})
click to toggle source
# File lib/canis/core/util/basestack.rb, line 349 def flow config={}, &block _stack :flow, config, &block end
item_for(widget)
click to toggle source
given an widget, return the item, so we can change weight or some other config
# File lib/canis/core/util/basestack.rb, line 393 def item_for widget each do |e| if e.is_a? Item if e.widget == widget return e end end end return nil end
parent_of(widget)
click to toggle source
module level returns the parent (flow or stack) for a given widget
allowing user to change configuration such as weight
# File lib/canis/core/util/basestack.rb, line 406 def parent_of widget f = item_for widget return f.config[:parent] if f return nil end
stack(config={})
click to toggle source
module level
# File lib/canis/core/util/basestack.rb, line 346 def stack config={}, &block _stack :stack, config, &block end
traverse(c) { |c| ... }
click to toggle source
——————— module level ——————————# General routin to traverse components and their components
# File lib/canis/core/util/basestack.rb, line 296 def traverse c, &block if c.is_a? BaseStack yield c c.components.each { |e| yield e } c.components.each { |e| traverse(e, &block) } @ctr -= 1 else end end
Private Instance Methods
_add(s)
click to toggle source
module level
# File lib/canis/core/util/basestack.rb, line 331 def _add s if @active.empty? $log.debug "XXX: ADDING TO components #{s} " unless s.is_a? BaseStack raise "No stack or flow to add to. Results may not be what you want" end @components << s else @active.last.components << s end __add s end
_stack(type, config={})
click to toggle source
module level
# File lib/canis/core/util/basestack.rb, line 315 def _stack type, config={}, &block case type when :stack s = Stack.new(config) when :flow s = Flow.new(config) end _add s @active << s yield_or_eval &block if block_given? @active.pop # if active is empty then this is where we could calculate # percentatges and do recalc, thus making it independent end
add(w, config={})
click to toggle source
module level
# File lib/canis/core/util/basestack.rb, line 354 def add w, config={} i = Item.new config, w _add i end
Also aliased as: add_widget
calc_weightages2(components, parent)
click to toggle source
module level
# File lib/canis/core/util/basestack.rb, line 361 def calc_weightages2 components, parent #puts " #{@ctr} --> #{c.type}, wt: #{c.config[:weight]} " @ctr += 1 wt = 0 cnt = 0 sz = components.count $log.debug "XXX: calc COMP COUNT #{sz} " # calculate how much weightage has been given by user # so we can allocate average to other components components.each { |e| if e.config[:weight] wt += e.config[:weight] cnt += 1 end $log.debug "XXX: INC setting parent #{parent} to #{e} " e.config[:parent] = parent e.config[:level] = @ctr } used = sz - cnt $log.debug "XXX: ADDING calc COMP COUNT #{sz} - #{cnt} " if used > 0 avg = (100-wt)/used # Allocate average to other components components.each { |e| e.config[:weight] = avg unless e.config[:weight] } end components.each { |e| calc_weightages2(e.components, e) if e.respond_to? :components } @ctr -= 1 end