Class: RubyCurses::TableCellRenderer

Inherits:
Object
  • Object
show all
Includes:
ConfigSetup, Utils
Defined in:
lib/rbcurse/extras/widgets/table/tablecellrenderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(text = "", config = {}, &block) ⇒ TableCellRenderer

Returns a new instance of TableCellRenderer.



15
16
17
18
19
20
21
22
# File 'lib/rbcurse/extras/widgets/table/tablecellrenderer.rb', line 15

def initialize text="", config={}, &block
  @text = text
  @editable = false
  @focusable = false
  config_setup config # @config.each_pair { |k,v| variable_set(k,v) }
  instance_eval &block if block_given?
  init_vars
end

Instance Method Details

#init_varsObject



23
24
25
26
# File 'lib/rbcurse/extras/widgets/table/tablecellrenderer.rb', line 23

def init_vars
  @justify ||= :left
  @display_length ||= 10
end

#repaint(graphic, r = @row, c = @col, row_index = -1,, value = @text, focussed = false, selected = false) ⇒ Object

XXX need to move wrapping etc up and done once.



33
34
35
36
37
38
39
40
41
42
43
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rbcurse/extras/widgets/table/tablecellrenderer.rb', line 33

def repaint graphic, r=@row,c=@col, row_index=-1, value=@text, focussed=false, selected=false
    lablist = []
    #value=value.to_s # ??
    value=transform value
    if @height && @height > 1
      lablist = wrap_text(value, @display_length).split("\n")
    else
      # ensure we do not exceed
      if !@display_length.nil?
        if value.length > @display_length
          dlen = @display_length - 1
          dlen = 0 if dlen < 0
          value = value[0..dlen]
        end
      end
      lablist << value
    end
    len = @display_length || value.length
    #$log.debug "less ZERO #{@display_length} || #{value.length}, ri: #{row_index}" if len < 0
    acolor = get_color $datacolor
    #acolor =get_color $datacolor, @color || @parent.color, @bgcolor || @parent.bgcolor #unless @parent.nil?
    _attr = Ncurses::A_NORMAL
    if selected
      _attr = Ncurses::A_BOLD if selected
      acolor =get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor unless @parent.nil?
    end
    if focussed 
      _attr |= Ncurses::A_REVERSE
    end
    #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor= #{acolor} j:#{@justify} dlL: #{@display_length} "
    _height = @height || 1
    str = @justify.to_sym == :right ? "%*s" : "%-*s"  # added 2008-12-22 19:05 
    # loop added for labels that are wrapped.
    # TODO clear separately since value can change in status like labels
    0.upto(_height-1) { |i| 
      graphic.printstring r+i, c, " " * len , acolor,_attr
    }
    lablist.each_with_index do |_value, ix|
      break if ix >= _height
      if @justify.to_sym == :center
        padding = (@display_length - _value.length)/2
        padding = 0 if padding < 0
        _value = " "*padding + _value + " "*padding # so its cleared if we change it midway
      end
      # XXX  2009-10-05 23:01 since the len can vary when scrolling
      # right justification for numbers suffers.
      # perhaps one should use display_length and then truncate using len
      graphic.printstring r, c, str % [len, _value], acolor,_attr
      r += 1
    end
end

#transform(value) ⇒ Object



27
28
29
# File 'lib/rbcurse/extras/widgets/table/tablecellrenderer.rb', line 27

def transform value
  return value.to_s
end