class Canis::DefaultTreeRenderer
structures }}} renderer {{{
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
Constants
- PLUS_MINUS
- PLUS_PLUS
- PLUS_Q
Attributes
icon_can_collapse[RW]
icon_can_expand[RW]
icon_no_children[RW]
icon_not_visited[RW]
row_selected_attr[RW]
Public Class Methods
new(source)
click to toggle source
source is the textpad or extending widget needed so we can call show_colored_chunks if the user specifies column wise colors
# File lib/canis/core/widgets/tree.rb, line 60 def initialize source @source = source @color = :white @bgcolor = :black @color_pair = $datacolor @attrib = NORMAL @_check_coloring = nil @icon_can_collapse = PLUS_MINUS @icon_can_expand = PLUS_PLUS @icon_not_visited = PLUS_Q @icon_no_children = "+-" # how about '+|' # adding setting column_model auto on 2014-04-10 - 10:53 why wasn;t this here already #tree_model(source.tree_model) end
Public Instance Methods
content_attrib(att)
click to toggle source
# File lib/canis/core/widgets/tree.rb, line 82 def content_attrib att @attrib = att end
content_colors(fg, bg)
click to toggle source
set fg and bg color of content rows, default is $datacolor (white on black).
# File lib/canis/core/widgets/tree.rb, line 76 def content_colors fg, bg @color = fg @bgcolor = bg @color_pair = get_color($datacolor, fg, bg) end
render(pad, lineno, treearraynode)
click to toggle source
@param pad for calling print methods on @param lineno the line number on the pad to print on @param text data to print
# 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