Class: RubyCurses::BasicListCellRenderer
- Includes:
- ConfigSetup, Utils
- Defined in:
- lib/rbcurse/rbasiclistbox.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 I’ve copied this into ListCellRenderer and added justify, so use that.
selection related collapse
- #init_vars ⇒ Object
-
#initialize(text = "", config = {}, &block) ⇒ BasicListCellRenderer
constructor
A new instance of BasicListCellRenderer.
-
#repaint(graphic, r = @row, c = @col, row_index = -1,, value = @text, focussed = false, selected = false) ⇒ Object
paint a list box cell.
-
#select_colors(focussed, selected) ⇒ Object
sets @color_pair and @attr.
Methods included from Utils
#_process_key, #bind_key, #clean_string!, #get_color, #keycode_tos, #repeatm, #view, #wrap_text
Methods included from ConfigSetup
#cget, #config_setup, #configure, #variable_set
Constructor Details
#initialize(text = "", config = {}, &block) ⇒ BasicListCellRenderer
Returns a new instance of BasicListCellRenderer.
651 652 653 654 655 656 657 658 |
# File 'lib/rbcurse/rbasiclistbox.rb', line 651 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
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/rbcurse/rbasiclistbox.rb', line 659 def init_vars #@justify ||= :left #str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05 @display_length ||= 10 # create color pairs once for this 2010-09-26 20:53 @color_pair = get_color $datacolor @pairs = Hash.new(@color_pair) @attrs = Hash.new(Ncurses::A_NORMAL) color_pair = get_color $selectedcolor, @parent.selected_color, @parent.selected_bgcolor @pairs[:normal] = @color_pair @pairs[:selected] = color_pair @pairs[:focussed] = @pairs[:normal] @attrs[:selected] = $row_selected_attr @attrs[:focussed] = $row_focussed_attr end |
#repaint(graphic, r = @row, c = @col, row_index = -1,, value = @text, focussed = false, selected = false) ⇒ Object
paint a list box cell
@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, cell focussed, not focussed
@param [Boolean] cell selected or not
701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/rbcurse/rbasiclistbox.rb', line 701 def repaint graphic, r=@row,c=@col, row_index=-1,value=@text, focussed=false, selected=false select_colors focussed, selected value=value.to_s if !@display_length.nil? if value.length > @display_length value = value[0..@display_length-1] end end len = @display_length || value.length graphic.printstring r, c, "%-*s" % [len, value], @color_pair, @attr end |
#select_colors(focussed, selected) ⇒ Object
sets @color_pair and @attr
677 678 679 680 681 682 683 684 685 686 687 688 |
# File 'lib/rbcurse/rbasiclistbox.rb', line 677 def select_colors focussed, selected @color_pair = @pairs[:normal] @attr = $row_attr # give precedence to a selected row if selected @color_pair = @pairs[:selected] @attr = @attrs[:selected] elsif focussed @color_pair = @pairs[:focussed] @attr = @attrs[:focussed] end end |