class TextWidget

Public Class Methods

new(x, y, text) click to toggle source
# File lib/delve/widgets/text.rb, line 2
def initialize(x, y, text)
  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 text is nil' unless text

  @x = x
  @y = y
  @text = text
end

Public Instance Methods

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

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

Private Instance Methods

determine_x(display) click to toggle source
# File lib/delve/widgets/text.rb, line 24
def determine_x display
  if @x == :center
    return (display.width / 2.0).ceil - (@text.length / 2.0).floor
  end
  @x
end
determine_y(display) click to toggle source
# File lib/delve/widgets/text.rb, line 31
def determine_y display
  if @y == :center
    return ((display.height / 2.0).ceil)
  end
  @y
end