class RETerm::Components::RevealingLabel
Text that is revealed incrementally over time
Attributes
text[RW]
Public Class Methods
new(args={})
click to toggle source
Initialize the RevealingLabel
component
@param [Hash] args revealing label params @option args [String] :text text of the label
Calls superclass method
RETerm::Component::new
# File lib/reterm/components/revealing_label.rb, line 14 def initialize(args={}) activate_sync! super self.text = args[:text] || "" # time between characters being revealed @char_time = args[:char_time] || 0.01 # time wait after a line is displayed before starting new @line_wait = args[:line_wait] || 3 @draw_next = false @timestamp = nil end
Public Instance Methods
draw!()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 79 def draw! @current_line ||= 0 @current_index ||= 0 return unless @draw_next @draw_next = false current = ((lines.size > @current_line) && (lines[@current_line].size > @current_index)) ? lines[@current_line][@current_index] : "" dispatch :start_reveal if @current_line == 0 && @current_index == 0 @timestamp = DateTime.now window.mvaddstr(@current_line + 1, @current_index + 1, current) dispatch :revealed_char, current set_next end
empty?()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 37 def empty? @text.nil? || @text.length == 0 end
erase()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 119 def erase lines.each_with_index { |l, i| window.mvaddstr(i+1, 1, " " * l.size) } end
lines()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 41 def lines @lines ||= text.split("\n") end
requested_cols()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 49 def requested_cols empty? ? 1 : lines.max { |l1, l2| l1.size <=> l2.size }.size + 1 end
requested_rows()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 45 def requested_rows lines.size + 1 end
reset!()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 74 def reset! @current_line = 0 @current_index = 0 end
set_next()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 104 def set_next return if empty? @current_index += 1 if @current_index >= lines[@current_line].size @current_index = 0 @current_line += 1 end if @current_line >= lines.size @current_line = 0 dispatch :revealed end end
sync!()
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 54 def sync! if @timestamp.nil? @draw_next = true else if @current_index == 0 if (DateTime.now - @timestamp) * 24 * 60 * 60 > @line_wait @draw_next = true end else if (DateTime.now - @timestamp) * 24 * 60 * 60 > @char_time @draw_next = true end end end draw! end
text=(t)
click to toggle source
# File lib/reterm/components/revealing_label.rb, line 30 def text=(t) @text = t @lines = nil @current_line = nil @current_index = nil end