Class: RubyCurses::ListCellRenderer
- Inherits:
-
Object
- Object
- RubyCurses::ListCellRenderer
- Includes:
- ConfigSetup, Utils
- Defined in:
- lib/rbcurse/listcellrenderer.rb
Overview
This is a basic list cell renderer that will render the to_s value of anything. Using alignment one can use for numbers too. However, for booleans it will print true and false. If editing, you may want checkboxes
Direct Known Subclasses
Instance Method Summary collapse
- #getvalue ⇒ Object
- #init_vars ⇒ Object
-
#initialize(text = "", config = {}, &block) ⇒ ListCellRenderer
constructor
A new instance of ListCellRenderer.
-
#prepare_default_colors(focussed, selected) ⇒ Object
sets @color_pair and @attr.
- #repaint(graphic, r = @row, c = @col, row_index = -1,, value = @text, focussed = false, selected = false) ⇒ 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
Constructor Details
#initialize(text = "", config = {}, &block) ⇒ ListCellRenderer
Returns a new instance of ListCellRenderer.
24 25 26 27 28 29 30 31 |
# File 'lib/rbcurse/listcellrenderer.rb', line 24 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
#getvalue ⇒ Object
36 37 38 |
# File 'lib/rbcurse/listcellrenderer.rb', line 36 def getvalue @text end |
#init_vars ⇒ Object
32 33 34 35 |
# File 'lib/rbcurse/listcellrenderer.rb', line 32 def init_vars @justify ||= :left @display_length ||= 10 end |
#prepare_default_colors(focussed, selected) ⇒ Object
sets @color_pair and @attr
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rbcurse/listcellrenderer.rb', line 41 def prepare_default_colors focussed, selected @color_pair = get_color $datacolor #acolor =get_color $datacolor, @color || @parent.color, @bgcolor || @parent.bgcolor #unless @parent.nil? @attr = @row_attr || Ncurses::A_NORMAL ##@row_attr = Ncurses::A_NORMAL # added 2009-02-04 18:35 since overriding in rfe ## determine bg and fg and attr if selected @attr = Ncurses::A_BOLD if selected @color_pair =get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor unless @parent.nil? end if focussed @attr |= Ncurses::A_REVERSE end end |
#repaint(graphic, r = @row, c = @col, row_index = -1,, value = @text, focussed = false, selected = false) ⇒ Object
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rbcurse/listcellrenderer.rb', line 60 def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false #$log.debug "label :#{@text}, #{value}, #{r}, #{c} col= #{@color}, #{@bgcolor} acolor= #{acolor} j:#{@justify} dlL: #{@display_length} " prepare_default_colors focussed, selected lablist = [] value=value.to_s # ?? 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 value = value[0..@display_length-1] end end lablist << value end len = @display_length || value.length _height = @height || 1 str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05 # loop added for labels that are wrapped. # clear separately since value can change in status like labels #len -= @left_margin 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 =begin if @parent.search_found_ix == row_index if [email protected]_offset.nil? graphic.mvchgat(y=r, [email protected]_offset, @parent.find_offset1, Ncurses::A_NORMAL, $reversecolor, nil) end end =end end |