Class: WindowTerminal::WrappedText

Inherits:
Text
  • Object
show all
Defined in:
lib/accu-window.rb

Overview

A subclass of Text which allows for wrapped text within a Window.

Direct Known Subclasses

ColoredWrappedText

Instance Attribute Summary

Attributes inherited from Text

#orientation, #text, #y

Instance Method Summary collapse

Methods inherited from Text

#get_length, #render_line, #set_text, #to_s

Constructor Details

#initialize(orientation, text, y, mode = :destroy) ⇒ WrappedText

Initializes a WrappedText object.



256
257
258
259
# File 'lib/accu-window.rb', line 256

def initialize(orientation,text,y,mode=:destroy)
	@mode = mode
	super(orientation,text,y)
end

Instance Method Details

#render(lines, cols, rows, padding = 2) ⇒ Object

Renders the WrappedText object based on passed lines and returns the modified lines.



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/accu-window.rb', line 264

def render(lines,cols,rows,padding=2)
	#--
	lines = lines.dup
	words = wrap(@text,rows-padding*2)
	if words.length > (cols - @y) then
		words.slice!((cols - @y + 1)..(words.length-1))
	end
	range = (@y - 1)..(cols-1)
	sum = 0
	ending = cols - padding - 1
	lines.each_index { |index|
		if (range === index and words[sum]) and index < ending then
			#puts "|" + words[sum] + "|"
			lines[index] = WindowTerminal::Text.new(orientation,words[sum],0).render_line(lines[index],rows,padding)
			sum += 1
		end
	}
	return lines
	#++
end