class MultiLineWidget

Public Class Methods

new(x, y, lines) click to toggle source
# File lib/delve/widgets/multi_line.rb, line 2
def initialize(x, y, lines)
  raise 'Cannot initialize text widget when x is nil' unless x
  raise 'Cannot initialize text widget when y is nil' unless y
  raise 'Cannot initialize text widget when lines is nil' unless lines

  @x = x
  @y = y
  @lines = lines
end

Public Instance Methods

draw(display) click to toggle source
# File lib/delve/widgets/multi_line.rb, line 12
def draw(display)
  raise 'Cannot draw text when display is nil' unless display

  y = determine_y(display) 
  @lines.each do |line|
    x = determine_x(display)
    line.each_char do |c|
      display.draw x, y, c
      x += 1
    end
    y += 1
  end
end

Private Instance Methods

determine_x(display) click to toggle source
# File lib/delve/widgets/multi_line.rb, line 27
def determine_x display
  if @x == :center
    return (display.width / 2.0).ceil - (longest_line / 2.0).floor
  end 
  @x
end
determine_y(display) click to toggle source
# File lib/delve/widgets/multi_line.rb, line 34
def determine_y display
  if @y == :center
    return ((display.height / 2.0).ceil) - (@lines.length / 2.0).floor
  end
  @y
end
longest_line() click to toggle source
# File lib/delve/widgets/multi_line.rb, line 41
def longest_line
  value = -1
  @lines.each do |line|
    if value < line.length
      value = line.length
    end
  end
  return value
end