Class: Canis::DefaultTreeRenderer

Inherits:
AbstractTextPadRenderer show all
Defined in:
lib/canis/core/widgets/tree.rb

Overview

TODO see how jtable does the renderers and columns stuff.

perhaps we can combine the two but have different methods or some flag that way oter methods can be shared

Constant Summary collapse

PLUS_PLUS =
"++"
PLUS_MINUS =
"+-"
PLUS_Q =
"+?"

Instance Attribute Summary collapse

Attributes inherited from AbstractTextPadRenderer

#attr, #color_pair, #content_cols, #cp, #list, #source

Instance Method Summary collapse

Methods inherited from AbstractTextPadRenderer

#pre_render, #render_all

Constructor Details

#initialize(source) ⇒ DefaultTreeRenderer

source is the textpad or extending widget needed so we can call show_colored_chunks if the user specifies column wise colors



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/canis/core/widgets/tree.rb', line 61

def initialize source
  @source = source
  @color = :white
  @bgcolor = :black
  @color_pair = $datacolor
  @attrib = NORMAL
  @_check_coloring = nil
  @icon_can_collapse = "+-"
  @icon_can_expand = "++"
  @icon_not_visited = "+?"
  @icon_no_children = "+-"

  # adding setting column_model auto on 2014-04-10 - 10:53 why wasn;t this here already
  #tree_model(source.tree_model)
end

Instance Attribute Details

#icon_can_collapseObject

Returns the value of attribute icon_can_collapse.



53
54
55
# File 'lib/canis/core/widgets/tree.rb', line 53

def icon_can_collapse
  @icon_can_collapse
end

#icon_can_expandObject

Returns the value of attribute icon_can_expand.



53
54
55
# File 'lib/canis/core/widgets/tree.rb', line 53

def icon_can_expand
  @icon_can_expand
end

#icon_no_childrenObject

Returns the value of attribute icon_no_children.



53
54
55
# File 'lib/canis/core/widgets/tree.rb', line 53

def icon_no_children
  @icon_no_children
end

#icon_not_visitedObject

Returns the value of attribute icon_not_visited.



53
54
55
# File 'lib/canis/core/widgets/tree.rb', line 53

def icon_not_visited
  @icon_not_visited
end

#row_selected_attrObject

Returns the value of attribute row_selected_attr.



54
55
56
# File 'lib/canis/core/widgets/tree.rb', line 54

def row_selected_attr
  @row_selected_attr
end

Instance Method Details

#content_attrib(att) ⇒ Object



82
83
84
# File 'lib/canis/core/widgets/tree.rb', line 82

def content_attrib att
  @attrib = att
end

#content_colors(fg, bg) ⇒ Object

set fg and bg color of content rows, default is $datacolor (white on black).



77
78
79
80
81
# File 'lib/canis/core/widgets/tree.rb', line 77

def content_colors fg, bg
  @color = fg
  @bgcolor = bg
  @color_pair = get_color($datacolor, fg, bg)
end

#render(pad, lineno, treearraynode) ⇒ Object

Parameters:

  • pad

    for calling print methods on

  • lineno

    the line number on the pad to print on

  • text

    data to print



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/canis/core/widgets/tree.rb', line 89

def render pad, lineno, treearraynode
  parent = @source
  level = treearraynode.level
  node = treearraynode
  if parent.node_expanded? node
    icon = @icon_can_collapse  # can collapse
  else
    icon = @icon_can_expand   # can expand
  end
  if node.children.size == 0
    icon = @icon_not_visited # either no children or not visited yet
    if parent.has_been_expanded node
      icon = @icon_no_children # definitely no children, we've visited
    end
  end
  # adding 2 to level, that's the size of icon
  # XXX FIXME if we put the icon here, then when we scroll right, the icon will show, it shoud not
  # FIXME we ignore truncation etc on previous level and take the object as is !!!
  _value =  "%*s %s" % [ level+2, icon,  node.user_object ]
  len =  _value.length
  #graphic.printstring r, c, "%-*s" % [len, _value], @color_pair,@attr
  cp = @color_pair
  att = @attrib
  raise "attrib is nil in tree render 104" unless att
  raise "color pair is nil in tree render 104" unless cp
  # added for selection, but will crash if selection is not extended !!! XXX
    if @source.is_row_selected? lineno
      att = @row_selected_attr || $row_selected_attr
      # FIXME currentl this overflows into next row
    end
  
  FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att)
  FFI::NCurses.mvwaddstr(pad, lineno, 0, _value)
  FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att)

end