Sha256: 27c11d424002a0bcfe5384e9565008a8d5f9ff477dff819af992a4b92e94dba3
Contents?: true
Size: 1.4 KB
Versions: 1
Compression:
Stored size: 1.4 KB
Contents
module CyberarmEngine class MultiLineText attr_accessor :options, :x, :y, :width, :height def initialize(text, options={}) @texts = [] text.split("\n").each_with_index do |line, i| _options = options _options[:y]+=_options[:size] @texts << Text.new(line, _options) end @options = options @x = @texts.first ? @texts.first.x : 0 @y = @texts.first ? @texts.first.y : 0 @width = 0 @height = 0 calculate_boundry end def draw @texts.each(&:draw) end def text string = "" @texts.each {|t| string << t.text} return string end def text=(text) if text.lines.count < @texts.count range = ((@texts.count - @text.lines.count)-1)..@texts.count-1 p range @texts.slice!(range) end text.split("\n").each_with_index do |line, i| if @texts[i] @texts[i].text = line else @texts << Text.new(line, @options) end end self.y = @y calculate_boundry end def x=(int) @x = int @texts.each {|t| t.x = int} end def y=(int) @y = int @texts.each_with_index {|t, i| t.y=int+(i*t.size)} end def calculate_boundry @width = 0 @height= 0 @texts.each {|t| @width = t.width if t.width > @width} @texts.each {|t| @height+=t.height} end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cyberarm_engine-0.1.0 | lib/cyberarm_engine/objects/multi_line_text.rb |