Class: Canis::Scrollbar
- Defined in:
- lib/canis/core/widgets/scrollbar.rb
Overview
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #config, #curpos, #focussed, #form, #handler, #id, #key_label, #parent_component, #row_offset, #state
Instance Method Summary collapse
-
#initialize(form, config = {}, &block) ⇒ Scrollbar
constructor
TODO: if parent passed, we shold bind to ON_ENTER and get current_index, so no extra work is required.
-
#repaint ⇒ Object
repaint the scrollbar Taking the data from parent as late as possible in case parent resized, or moved around by a container.
Methods inherited from Widget
#action_manager, #bgcolor, #color, #color_pair, #command, #destroy, #focus, #focusable, #focusable?, #getvalue, #getvalue_for_paint, #handle_key, #hide, #init_vars, #modified?, #move, #on_enter, #on_leave, #override_graphic, #process_key, #property_set, #remove, #repaint_all, #repaint_required, #rowcol, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #unbind_key
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rb_getstr, #warn
Methods included from Utils
#ORIG_process_key, #ORIGbind_key, #ORIGkeycode_tos, #_process_key, #bind_composite_mapping, #bind_key, #bind_keys, #check_composite_mapping, #create_logger, #define_key, #define_prefix_command, #execute_mapping, #get_attrib, #get_color, #key, #key_tos, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #view, #xxxbind_composite_mapping
Methods included from ConfigSetup
Methods included from EventHandler
#bind, #event?, #event_list, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(form, config = {}, &block) ⇒ Scrollbar
TODO: if parent passed, we shold bind to ON_ENTER and get current_index, so no extra work is required.
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 |
# File 'lib/canis/core/widgets/scrollbar.rb', line 38 def initialize form, config={}, &block # setting default first or else Widget will place its BW default #@color, @bgcolor = ColorMap.get_colors_for_pair $bottomcolor super @color_pair = get_color $datacolor, @color, @bgcolor @scroll_pair = get_color $bottomcolor, :green, :white #$log.debug "SCROLLBAR COLOR cp #{@color_pair} sp #{@scroll_pair} " if $log.debug? @window = form.window @editable = false @focusable = false @repaint_required = true @orientation = :V if @parent @parent.bind :ENTER_ROW do |p| # textview sent self, textpad sends textactionevent if p.instance_of? TextActionEvent p = p.source end # parent must implement row_count, and have a @current_index raise StandardError, "Parent (#{p.class.to_s}) must implement row_count" unless p.respond_to? :row_count self.current_index = p.current_index @repaint_required = true #requred otherwise at end when same value sent, prop handler # will not be fired (due to optimization). end # in some cases, on leaving a listbox or other component redraws itself to reduce # selected or highlighted object, so the scrollbar gets overwritten. We need to repaint it. @parent.bind :LEAVE do |p| @repaint_required = true end end end |
Instance Method Details
#repaint ⇒ Object
repaint the scrollbar Taking the data from parent as late as possible in case parent resized, or moved around by a container.
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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/canis/core/widgets/scrollbar.rb', line 75 def repaint if @parent @row = @parent.row+1 @col = @parent.col + @parent.width - 1 @length = @parent.height - 2 @list_length = @parent.row_count @current_index ||= @parent.current_index @border_attrib ||= @parent.border_attrib end raise ArgumentError, "current_index must be provided" unless @current_index raise ArgumentError, "list_length must be provided" unless @list_length my_win = @form ? @form.window : @target_window @graphic = my_win unless @graphic return unless @repaint_required # 2016-01-14 - replacing 1 with space in mvvline since junk is showing up in some cases. space_char = " ".codepoints.first # first print a right side vertical line #bc = $bottomcolor # dark blue bc = $datacolor bordercolor = @border_color || bc borderatt = @border_attrib || Ncurses::A_REVERSE #$log.debug "SCROLL bordercolor #{bordercolor} , #{borderatt} " if $log.debug? @graphic.attron(Ncurses.COLOR_PAIR(bordercolor) | borderatt) #$log.debug " XXX SCROLL #{@row} #{@col} #{@length} " @graphic.mvvline(@row+0, @col, space_char, @length-0) @graphic.attroff(Ncurses.COLOR_PAIR(bordercolor) | borderatt) # now calculate and paint the scrollbar pht = @length listlen = @list_length * 1.0 @current_index = 0 if @current_index < 0 @current_index = listlen-1 if @current_index >= listlen sclen = (pht/listlen)* @length sclen = 1 if sclen < 1 # sometimes 0.7 for large lists 100 items 2011-10-1 scloc = (@current_index/listlen)* @length scloc = (@length - sclen) if scloc > @length - sclen # don't exceed end if @current_index == @list_length - 1 scloc = @length - sclen + 0 # earlier 1, but removed since sclen min 1 2011-10-1 end @graphic.attron(Ncurses.COLOR_PAIR(@scroll_pair) | borderatt) r = @row + scloc c = @col + 0 #$log.debug " XXX SCROLLBAR #{r} #{c} #{sclen} " @graphic.mvvline(r, c, space_char, sclen) @graphic.attroff(Ncurses.COLOR_PAIR(@scroll_pair) | borderatt) @repaint_required = false end |