Method: AbstractLayout#do_layout
- Defined in:
- lib/canis/core/include/layouts/abstractlayout.rb
#do_layout ⇒ Object
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.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/canis/core/include/layouts/abstractlayout.rb', line 141 def do_layout $log.debug " inside do_layout" _init_layout raise "please implement this in your subclass " c = @left_margin # determine fixed widths and how much is left to share with others, # and how many variable width components there are. ht = 0 # accumulate fixed height fixed_ctr = 0 # how many items have a fixed wt var_ctr = 0 var_wt = 0.0 @components.each do |e| $log.debug " looping 1 #{e.name} " _tmpwt = @wts[e] || 0 # what of field and button placed side by side if e.is_a? Field or e.is_a? Button or e.is_a? Label @wts[e] ||= 1 ht += @wts[e] || 1 fixed_ctr += 1 elsif _tmpwt >= 1 ht += @wts[e] || 0 fixed_ctr += 1 elsif _tmpwt > 0 and _tmpwt <= 1 # FIXME how to specify 100 % ??? var_ctr += 1 var_wt += @wts[e] end end unaccounted = @components.count - (fixed_ctr + var_ctr) $log.debug " unacc #{unaccounted} , fixed #{fixed_ctr} , var : #{var_ctr} , ht #{ht} height #{@height} " balance_ht = @height - ht # use this for those who have specified a % balance_ht1 = balance_ht * (1 - var_wt ) average_ht = (balance_ht1 / unaccounted).floor # give this to those who have not specified ht average_ht = (balance_ht1 / unaccounted) # give this to those who have not specified ht $log.debug " #{balance_ht} , #{balance_ht1} , #{average_ht} " # not accounted for gap in heights rem = 0 # remainder to be carried over @components.each do |e| $log.debug " looping 2 #{e.name} #{e.class.to_s.downcase} " next if @ignore_list.include? e.class.to_s.downcase $log.debug " looping 3 #{e.name} " e.row = r e.col = c wt = @wts[e] if wt if wt.is_a? Fixnum e.height = wt elsif wt.is_a? Float e.height = (wt * balance_ht).floor end else # no wt specified, give average of balance wt e.height = average_ht hround = e.height.floor rem += e.height - hround e.height = hround # see comment in prev block regarding remaininder if rem >= 1 e.height += 1 rem = 0 end end $log.debug " layout #{e.name} , h: #{e.height} r: #{e.row} , c = #{e.col} " e.width = @width r += e.height.floor r += @gap end $log.debug " layout finished " end |