Class: RubyCurses::TreeCellRenderer
- Includes:
- ConfigSetup, Utils
- Defined in:
- lib/rbcurse/core/widgets/tree/treecellrenderer.rb
Overview
This is a basic list cell renderer that will render the to_s value of anything.
TODO upgrade as per new listcellrenderer
Constant Summary collapse
- PLUS_PLUS =
"++"
- PLUS_MINUS =
"+-"
- PLUS_Q =
"+?"
Instance Attribute Summary collapse
-
#actual_length ⇒ Object
readonly
Returns the value of attribute actual_length.
-
#pcol ⇒ Object
Returns the value of attribute pcol.
Instance Method Summary collapse
- #getvalue ⇒ Object
- #init_vars ⇒ Object
-
#initialize(text = "", config = {}, &block) ⇒ TreeCellRenderer
constructor
A new instance of TreeCellRenderer.
-
#prepare_default_colors(focussed, selected) ⇒ Object
sets @color_pair and @attr.
-
#repaint(graphic, r = @row, c = @col, row_index = -1,, treearraynode = nil, value = @text, leaf = nil, focussed = false, selected = false, expanded = false) ⇒ Object
paint a list box cell 2010-09-02 15:38 changed focussed to take true, false and :SOFT_FOCUS SOFT_FOCUS means the form focus is no longer on this field, but this row was focussed when use was last on this field.
Methods included from Utils
#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Constructor Details
#initialize(text = "", config = {}, &block) ⇒ TreeCellRenderer
Returns a new instance of TreeCellRenderer.
26 27 28 29 30 31 32 33 34 |
# File 'lib/rbcurse/core/widgets/tree/treecellrenderer.rb', line 26 def initialize text="", config={}, &block @text = text @editable = false @focusable = false @actual_length = 0 config_setup config # @config.each_pair { |k,v| variable_set(k,v) } instance_eval &block if block_given? init_vars end |
Instance Attribute Details
#actual_length ⇒ Object (readonly)
Returns the value of attribute actual_length.
23 24 25 |
# File 'lib/rbcurse/core/widgets/tree/treecellrenderer.rb', line 23 def actual_length @actual_length end |
#pcol ⇒ Object
Returns the value of attribute pcol.
24 25 26 |
# File 'lib/rbcurse/core/widgets/tree/treecellrenderer.rb', line 24 def pcol @pcol end |
Instance Method Details
#getvalue ⇒ Object
39 40 41 |
# File 'lib/rbcurse/core/widgets/tree/treecellrenderer.rb', line 39 def getvalue @text end |
#init_vars ⇒ Object
35 36 37 38 |
# File 'lib/rbcurse/core/widgets/tree/treecellrenderer.rb', line 35 def init_vars @justify ||= :left @display_length ||= 10 end |
#prepare_default_colors(focussed, selected) ⇒ Object
sets @color_pair and @attr
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rbcurse/core/widgets/tree/treecellrenderer.rb', line 44 def prepare_default_colors focussed, selected @color_pair = get_color $datacolor @attr = @row_attr || Ncurses::A_NORMAL ## determine bg and fg and attr if selected #@attr = Ncurses::A_BOLD if selected ## 2010-09-18 18:32 making selected row reverse @attr |= Ncurses::A_REVERSE # 2010-09-18 18:33 maybe not required, just confuses the whole thing and uglifies it #@color_pair =get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor unless @parent.nil? end case focussed when :SOFT_FOCUS @attr |= Ncurses::A_BOLD when true # earlier focussed row showed up in reverse, which was confusing since it looked selected # now focussed row has cursor on side, and can be bold. that's enough. @attr |= Ncurses::A_BOLD #@attr |= Ncurses::A_REVERSE when false end end |
#repaint(graphic, r = @row, c = @col, row_index = -1,, treearraynode = nil, value = @text, leaf = nil, focussed = false, selected = false, expanded = false) ⇒ Object
paint a list box cell
2010-09-02 15:38 changed focussed to take true, false and :SOFT_FOCUS
SOFT_FOCUS means the form focus is no longer on this field, but this row
was focussed when use was last on this field. This row will take focus
when field is focussed again
@param [Buffer] window or buffer object used for printing
@param [Fixnum] row
@param [Fixnum] column
@param [Fixnum] actual index into data, some lists may have actual data elsewhere and
display data separate. e.g. rfe_renderer (directory listing)
@param [String] text to print in cell
@param [Boolean, :SOFT_FOCUS] cell focussed, not focussed, cell focussed but field is not focussed
@param [Boolean] cell selected or not
renderer.repaint @graphic, r+hh, c+@left_margin, crow, object, content, focus_type, selected, expanded, leaf
86 87 88 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/rbcurse/core/widgets/tree/treecellrenderer.rb', line 86 def repaint graphic, r=@row,c=@col, row_index=-1, treearraynode=nil, value=@text, leaf=nil, focussed=false, selected=false, =false #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor= #{acolor} j:#{@justify} dlL: #{@display_length} " prepare_default_colors focussed, selected value=value.to_s # ?? #icon = object.is_leaf? ? "-" : "+" #icon = leaf ? "-" : "+" #level = treearraynode.level #node = treearraynode.node level = treearraynode.level node = treearraynode if parent. node icon = PLUS_MINUS # can collapse else icon = PLUS_PLUS # can expand end if node.children.size == 0 icon = PLUS_Q # either no children or not visited yet if parent. node icon = PLUS_MINUS # 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 ] @actual_length = _value.length pcol = @pcol if pcol > 0 _len = @display_length || @parent.width-2 _value = _value[@pcol..@pcol+_len-1] end _value ||= "" if @height && @height > 1 else # ensure we do not exceed if !@display_length.nil? if _value.length > @display_length @actual_length = _value.length _value = _value[0..@display_length-1] end end #lablist << value end len = @display_length || _value.length graphic.printstring r, c, "%-*s" % [len, _value], @color_pair,@attr #_height = @height || 1 #0.upto(_height-1) { |i| #graphic.printstring r+i, c, ( " " * len) , @color_pair,@attr #} #lablist.each_with_index do |_value, ix| #break if ix >= _height #if @justify.to_sym == :center #padding = (@display_length - _value.length)/2 #_value = " "*padding + _value + " "*padding # so its cleared if we change it midway #end #graphic.printstring r, c, str % [len, _value], @color_pair,@attr #r += 1 #end end |