class Gtk2HTML::Layout
Attributes
to_a[R]
Public Class Methods
new(instructions, width: 320, height: 240)
click to toggle source
# File lib/gtk2html.rb, line 136 def initialize(instructions, width: 320, height: 240) pcoords = [0, 0, width, height] @pcoords = [0,0,0,0] a = lay_out(instructions, pcoords) @a = del_pcoords a end
Private Instance Methods
del_pcoords(a)
click to toggle source
# File lib/gtk2html.rb, line 159 def del_pcoords(a) if a.first.is_a? Array then a.map {|row| del_pcoords row if row} else a.pop a end end
lay_out(a, pcoords=[])
click to toggle source
# File lib/gtk2html.rb, line 169 def lay_out(a, pcoords=[]) if a.first.is_a? Symbol then @text_style = %i(font-size color).inject({})\ {|r,x| r.merge(x => a[4][x]) } set_row(a, pcoords) elsif a.first.is_a? String then [a.first, @pcoords.take(2), @text_style, pcoords] elsif a.first.is_a? Array if a.first.empty? then a.delete a.first lay_out a, pcoords else if a.first.first.is_a? Symbol then item, children = a r = lay_out(item, pcoords) pcoords = r[-1] if children.any? then r2 = lay_out(children, pcoords) r = [r,r2] else r end #r << pcoords else a.map do |row| row2 =lay_out(row, pcoords) pcoords[1] = row2[1][2] row2 end end end else a.map {|row| lay_out(row, pcoords) } end end
set_row(row, pcoords)
click to toggle source
# File lib/gtk2html.rb, line 224 def set_row(row, pcoords) name, margin, raw_coords, padding, style = row coords = raw_coords.map.with_index {|x,i| x ? x : pcoords[i]} width, height = style[:width], style[:height] x1 = coords[0] + margin[0] y1 = coords[1] + margin[1] if width then x2 = x1 + width.to_f x2 += margin[2] else x2 = coords[2] - margin[2] end if height then y2 = y1 + height.to_f y2 += margin[3] else y2 = coords[3] - margin[3] end new_coords = [x1, y1, x2, y2] @pcoords[0] = x1 + padding[0] @pcoords[1] = y1 + padding[1] @pcoords[2] = x2 - padding[2] @pcoords[3] = y2 - padding[3] pcoords = @pcoords.clone [name, margin, new_coords, padding, style, pcoords] end