Sha256: 2ff12cb9d7a222a9d4240f20c366aa87f200710be69e8346ec7609926efa60c9

Contents?: true

Size: 805 Bytes

Versions: 8

Compression:

Stored size: 805 Bytes

Contents

module Luck
class Label < Control
  attr_accessor :alignment, :text
  
  def initialize *args
    @alignment = :left
    @text = 'Label'
    super
  end
  
  def align direction
    @alignment = direction
  end
  
  def align_text text
    case @alignment
      when :center
        text.center width
      when :right
        text.rjust width
      else
        text.ljust width
    end
  end
  
  def redraw
    if text.empty?
      @display.place y1, x1, ' ' * width
      return
    end
    
    row = y1
    text.each_line do |line|
      line.chomp!
      length = line.size
      offset = 0
      while offset < width || offset == 0
        @display.place row, x1, align_text(line[offset, width])
        row += 1
        offset += width
        return if row >= y2
      end
    end
  end
end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
luck-0.1.6 lib/luck/label.rb
luck-0.1.5 lib/luck/label.rb
luck-0.1.4 lib/luck/label.rb
luck-0.1.3 lib/luck/label.rb
luck-0.1.2 lib/luck/label.rb
luck-0.1.1 lib/luck/label.rb
luck-0.1.0 lib/luck/label.rb
luck-0.0.0 lib/luck/label.rb