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.



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

def initialize source=nil
  @source = source
end

Instance Attribute Details

#attrObject

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



1534
1535
1536
# File 'lib/canis/core/widgets/textpad.rb', line 1534

def attr
  @attr
end

#color_pairObject

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



1534
1535
1536
# File 'lib/canis/core/widgets/textpad.rb', line 1534

def color_pair
  @color_pair
end

#content_colsObject

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



1537
1538
1539
# File 'lib/canis/core/widgets/textpad.rb', line 1537

def content_cols
  @content_cols
end

#cpObject

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



1534
1535
1536
# File 'lib/canis/core/widgets/textpad.rb', line 1534

def cp
  @cp
end

#listObject

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



1537
1538
1539
# File 'lib/canis/core/widgets/textpad.rb', line 1537

def list
  @list
end

#sourceObject

the widget this is associated with.



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

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 ?



1547
1548
1549
1550
1551
1552
# File 'lib/canis/core/widgets/textpad.rb', line 1547

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.



1574
1575
1576
1577
# File 'lib/canis/core/widgets/textpad.rb', line 1574

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.



1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
# File 'lib/canis/core/widgets/textpad.rb', line 1558

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