Class: Canis::AbstractTextPadRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/canis/core/widgets/textpad.rb

Overview

renderer {{{ Very basic renderer that only prints based on color pair of the textpad

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = nil) ⇒ AbstractTextPadRenderer

Returns a new instance of AbstractTextPadRenderer.



1546
1547
1548
# File 'lib/canis/core/widgets/textpad.rb', line 1546

def initialize source=nil
  @source = source
end

Instance Attribute Details

#attrObject

attribute for row, color_pair, and the Ncurses int for the colorpair



1539
1540
1541
# File 'lib/canis/core/widgets/textpad.rb', line 1539

def attr
  @attr
end

#color_pairObject

attribute for row, color_pair, and the Ncurses int for the colorpair



1539
1540
1541
# File 'lib/canis/core/widgets/textpad.rb', line 1539

def color_pair
  @color_pair
end

#content_colsObject

content cols is the width in columns of pad list is the data array



1542
1543
1544
# File 'lib/canis/core/widgets/textpad.rb', line 1542

def content_cols
  @content_cols
end

#cpObject

attribute for row, color_pair, and the Ncurses int for the colorpair



1539
1540
1541
# File 'lib/canis/core/widgets/textpad.rb', line 1539

def cp
  @cp
end

#listObject

content cols is the width in columns of pad list is the data array



1542
1543
1544
# File 'lib/canis/core/widgets/textpad.rb', line 1542

def list
  @list
end

#sourceObject

the widget this is associated with.



1544
1545
1546
# File 'lib/canis/core/widgets/textpad.rb', line 1544

def source
  @source
end

Instance Method Details

#pre_renderObject Also known as: update_colors

have the renderer get the latest colors from the widget. Override this if for some reason the renderer wishes to hardcode its own. But then the widgets colors would be changed ?



1552
1553
1554
1555
1556
1557
# File 'lib/canis/core/widgets/textpad.rb', line 1552

def pre_render
  @attr = @source.attr
  cp = get_color($datacolor, @source.color(), @source.bgcolor())
  @color_pair = @source.color_pair || cp
  @cp = FFI::NCurses.COLOR_PAIR(cp)
end

#render(pad, lineno, text) ⇒ Object

concrete / derived classes should override this for their specific uses. Called if only a row is changed.



1579
1580
1581
1582
# File 'lib/canis/core/widgets/textpad.rb', line 1579

def render pad, lineno, text
  FFI::NCurses.mvwaddstr(pad,lineno, 0, @clearstring) if @clearstring
  FFI::NCurses.mvwaddstr(pad,lineno, 0, text)
end

#render_all(pad, arr) ⇒ Object

derived classes may choose to override this. However, they should set size and color and attrib at the start since these can change after the object has been created depending on the application.



1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
# File 'lib/canis/core/widgets/textpad.rb', line 1563

def render_all pad, arr
  pre_render
  @content_cols = @source.pad_cols
  @clearstring = " " * @content_cols
  @list = arr

  att = @attr || NORMAL
  FFI::NCurses.wattron(pad, @cp | att)

  arr.each_with_index { |line, ix|
    render pad, ix, line
  }
  FFI::NCurses.wattroff(pad, @cp | att)
end