class TheFox::TermKit::TextView

Basic Text View class. View sub-class.

Provides functionalities to draw text.

Public Class Methods

new(text = nil, name = nil) click to toggle source
Calls superclass method TheFox::TermKit::View.new
# File lib/termkit/view/view_text.rb, line 11
def initialize(text = nil, name = nil)
    name = "TextView_#{object_id}" if name.nil?
    super(name)
    
    #puts 'TextView->initialize'
    
    if !text.nil?
        draw_text(text)
    end
end

Public Instance Methods

draw_text(text) click to toggle source
# File lib/termkit/view/view_text.rb, line 30
def draw_text(text)
    changes = 0
    
    y_pos = 0
    text.split("\n").each do |line|
        x_pos = 0
        
        # puts "line '#{line}'"
        
        line.split('').each do |char|
            # puts "c '#{char}'"
            
            content = draw_point(Point.new(x_pos, y_pos), char)
            if !content.nil?
                changes += 1
            end
            
            # puts "    c '#{char}' #{changes}"
            
            x_pos += 1
        end
        
        # puts "line '#{line}', changes #{changes}"
        
        y_pos += 1
    end
    
    changes
end
text=(text) click to toggle source
# File lib/termkit/view/view_text.rb, line 22
def text=(text)
    if !text.is_a?(String)
        raise ArgumentError, "Argument is not a String -- #{text.class} given"
    end
    
    draw_text(text)
end