Class: RubyCurses::TableCellRenderer
- Inherits:
-
Object
- Object
- RubyCurses::TableCellRenderer
- Includes:
- DSL, ConfigSetup, Utils
- Defined in:
- lib/rbcurse/table/tablecellrenderer.rb
Instance Method Summary collapse
- #init_vars ⇒ Object
-
#initialize(text = "", config = {}, &block) ⇒ TableCellRenderer
constructor
A new instance of TableCellRenderer.
-
#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.
- #transform(value) ⇒ Object
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Methods included from DSL
Constructor Details
#initialize(text = "", config = {}, &block) ⇒ TableCellRenderer
Returns a new instance of TableCellRenderer.
18 19 20 21 22 23 24 25 |
# File 'lib/rbcurse/table/tablecellrenderer.rb', line 18 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_vars ⇒ Object
26 27 28 29 |
# File 'lib/rbcurse/table/tablecellrenderer.rb', line 26 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.
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 84 85 86 |
# File 'lib/rbcurse/table/tablecellrenderer.rb', line 36 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
30 31 32 |
# File 'lib/rbcurse/table/tablecellrenderer.rb', line 30 def transform value return value.to_s end |