Class: SplitLayout

Inherits:
AbstractLayout show all
Defined in:
lib/canis/core/include/layouts/SplitLayout.rb

Instance Attribute Summary

Attributes inherited from AbstractLayout

#bottom_margin, #components, #form, #gap, #height, #height_pc, #ignore_list, #left_margin, #right_margin, #top_margin, #width, #width_pc

Instance Method Summary collapse

Methods inherited from AbstractLayout

#_init_layout, #add, #add_with_weight, #cget, #clear, #configure_item, #cset, #push, #remove

Constructor Details

#initialize(arg, config = {}, &block) ⇒ SplitLayout

Returns a new instance of SplitLayout.

Parameters:

  • optional (Form)

    give a form

  • optional (Hash)

    give settings/attributes which will be set into variables



94
95
96
97
# File 'lib/canis/core/include/layouts/SplitLayout.rb', line 94

def initialize arg, config={}, &block
  super
  @splits = nil
end

Instance Method Details

#_split(type, args, &block) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
# 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_layoutObject

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.



126
127
128
129
130
131
# 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) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# 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) ⇒ Object



111
112
113
114
# 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) ⇒ Object



115
116
117
118
119
# 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