class SplitLayout

Public Class Methods

new(arg, config={}) click to toggle source

@param [Form] optional give a form

@param [Hash] optional give settings/attributes which will be set into variables

Calls superclass method AbstractLayout::new
# File lib/canis/core/include/layouts/SplitLayout.rb, line 94
def initialize arg, config={}, &block
  super
  @splits = nil
end

Public Instance Methods

_split(type, args) { |flatten| ... } click to toggle source
# File lib/canis/core/include/layouts/SplitLayout.rb, line 98
def _split type, args, &block
  @splits = []
  @split_wts = args
  args.each do |e|
    @splits << Split.new(type, e, self)
  end
  if block_given?
    yield @splits.flatten
  else
    return @splits.flatten
  end
end
do_layout() click to toggle source

This program lays out the widgets deciding their row and columm and height and weight. This program is called once at start of application, and again whenever a RESIZE event happens.

# File lib/canis/core/include/layouts/SplitLayout.rb, line 126
def do_layout
  _init_layout
  recalc @splits, @top_margin, @left_margin if @splits
  #
  $log.debug "  layout finished "
end
recalc(splits, r, c) click to toggle source
# File lib/canis/core/include/layouts/SplitLayout.rb, line 132
def recalc splits, r, c
  splits.each_with_index do |s,i|
    $log.debug "  recalc #{i}, #{s} "
    p = s.parent
    s.top = r
    s.left = c
    case s.type
    when :v
      s.width = (s.weight * p.width ).floor
      s.height = p.height
      c += s.width
    when :h
      s.height = (s.weight * p.height ).floor
      s.width = p.width
      r += s.height
    end
    if s.component
      s.component.height = s.height
      s.component.row = s.top
      s.component.col = s.left
      s.component.width = s.width
    elsif s.splits
      recalc s.splits, s.top, s.left if s.splits
    else
      raise "Neither splits nor a component placed in #{s} #{s.type}, #{s.weight} #{s.name}"
    end
  end

end
split(*args, &block) click to toggle source
# File lib/canis/core/include/layouts/SplitLayout.rb, line 111
def split *args, &block
  raise "already split " if @splits
  _split :h, args, &block
end
vsplit(*args, &block) click to toggle source
# File lib/canis/core/include/layouts/SplitLayout.rb, line 115
def vsplit *args, &block
  raise "already split " if @splits
  $log.debug "  SPLIT GOT #{args} "
  _split :v, args, &block
end