Class: RubyCurses::Viewport
Overview
A viewport or porthole throgh which one can see portions of underlying object such as textarea, table or a form, usually the underlying data is larger than what can be displayed and thus must be seen through a viewport. TODO -
Constant Summary
Constants included from Io
Io::ERROR_COLOR_PAIR, Io::FOOTER_COLOR_PAIR, Io::LINEONE, Io::MAIN_WINDOW_COLOR_PAIR
Instance Attribute Summary collapse
-
#cascade_changes ⇒ Object
Returns the value of attribute cascade_changes.
Attributes inherited from Widget
#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #parent_component, #row_offset, #rows_panned, #state
Instance Method Summary collapse
-
#fire_state_changed ⇒ Object
should this be in widget ? inform listeners that state has changed.
-
#get_pad_top_left ⇒ Object
instead of using row and col to increment, try using this, since this is what’s actually incremented.
- #getvalue ⇒ Object
-
#handle_key(ch) ⇒ Object
most likely should just return an unhandled and not try being intelligent should viewport handle keys or should parent do so directly to child.
-
#height(*val) ⇒ Object
set height a container must pass down changes in size to it’s children + 2010-02-04 18:06 - i am not sure about this.
- #init_vars ⇒ Object
-
#initialize(form, config = {}, &block) ⇒ Viewport
constructor
attr_reader :top_margin, :left_margin.
-
#paint ⇒ Object
$log.debug “TV after loop : curpos #@curpos blen: #@[email protected]”.
-
#repaint ⇒ Object
viewport.
-
#set_view(ch) ⇒ Object
set the component to be viewed.
-
#set_view_position(r, c) ⇒ Object
Set the row and col of the child, that the viewport starts displaying.
- #set_view_size(h, w) ⇒ Object
-
#width(*val) ⇒ Object
set width a container must pass down changes in size to it’s children added 2010-01-16 23:55.
Methods inherited from Widget
#changed, #click, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue_for_paint, #height=, #hide, #leave, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_form_col, #set_form_row, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width=
Methods included from Io
#askchoice, #askyesno, #askyesnocancel, #clear_error, #clear_this, #get_string, #newaskyesno, #old_print_header, #old_print_top_right, #print_action, #print_error, #print_footer_help, #print_header, #print_headers, #print_help, #print_help_page, #print_in_middle, #print_key_labels, #print_key_labels_row, #print_screen_labels, #print_status, #print_this, #print_top_right, #rbgetstr, #warn
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
Methods included from EventHandler
#bind, #fire_handler, #fire_property_change
Constructor Details
#initialize(form, config = {}, &block) ⇒ Viewport
attr_reader :top_margin, :left_margin
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rbcurse/rviewport.rb', line 42 def initialize form, config={}, &block @focusable = false @editable = false #@top_margin = @left_margin = 1 # 2010-02-06 23:27 reduce in scrollpane @row = 1 # 1 # 0 2010-02-06 22:46 so we don't write on scrollpanes border @col = 1 # 1 # 0 2010-02-06 22:47 super #@row_offset = @col_offset = 1 #@orig_col = @col init_vars @_events.push :STATE_CHANGE end |
Instance Attribute Details
#cascade_changes ⇒ Object
Returns the value of attribute cascade_changes.
39 40 41 |
# File 'lib/rbcurse/rviewport.rb', line 39 def cascade_changes @cascade_changes end |
Instance Method Details
#fire_state_changed ⇒ Object
should this be in widget ? inform listeners that state has changed
199 200 201 202 |
# File 'lib/rbcurse/rviewport.rb', line 199 def fire_state_changed @sce = ChangeEvent.new(self) if @sce.nil? fire_handler :STATE_CHANGE, @sce end |
#get_pad_top_left ⇒ Object
instead of using row and col to increment, try using this, since this is what’s actually incremented.
109 110 111 112 |
# File 'lib/rbcurse/rviewport.rb', line 109 def get_pad_top_left p = @child.get_buffer() return p.pminrow, p.pmincol end |
#getvalue ⇒ Object
123 124 125 |
# File 'lib/rbcurse/rviewport.rb', line 123 def getvalue # TODO ??? end |
#handle_key(ch) ⇒ Object
most likely should just return an unhandled and not try being intelligent should viewport handle keys or should parent do so directly to child
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/rbcurse/rviewport.rb', line 128 def handle_key ch # if this gets key it should just hand it to child if @child != nil ret = @child.handle_key ch # 2010-01-19 19:26 commenting off repaint to see. return :UNHANDLED if ret == :UNHANDLED # moved below return so only if table handles @repaint_required=true # added 2009-12-27 22:25 BUFFERED WHY ?? else return :UNHANDLED end return 0 #$log.debug "TV after loop : curpos #{@curpos} blen: #{@buffer.length}" end |
#height(*val) ⇒ Object
set height a container must pass down changes in size to it’s children + 2010-02-04 18:06 - i am not sure about this. When viewport is set then it passes down + changes to child which user did not intend. Maybe in splitpane it is okay but other cases? + Perhaps its okay if scrollpane gets larger than child, not otherwise. added 2010-01-16 23:55
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rbcurse/rviewport.rb', line 152 def height(*val) return @height if val.empty? oldvalue = @height || 0 super @height = val[0] return if @child == nil delta = @height - oldvalue return if delta == 0 @repaint_required = true if @child.height.nil? @child.height = @height $log.warn " viewport setting child #{@child.name} to default h of #{@height} -- child is usually larger. " else if @cascade_changes $log.debug "warn!! viewport adding #{delta} to child ht #{child.height} " @child.height += delta end end end |
#init_vars ⇒ Object
54 55 56 57 58 |
# File 'lib/rbcurse/rviewport.rb', line 54 def init_vars #@curpos = @pcol = @toprow = @current_index = 0 should_create_buffer = true @border_width = 2 end |
#paint ⇒ Object
$log.debug “TV after loop : curpos #@curpos blen: #RubyCurses::Viewport.@[email protected]”
142 143 144 145 |
# File 'lib/rbcurse/rviewport.rb', line 142 def paint @repaint_required = false @repaint_all = false end |
#repaint ⇒ Object
viewport
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rbcurse/rviewport.rb', line 113 def repaint # viewport return unless @repaint_required # should call child's repaint onto pad # then this should return clipped pad $log.debug "VP calling child #{@child.name} repaint" #x @graphic.wclear # required otherwise bottom of scrollpane had old rows still repeated. 2010-01-17 22:51 @child.repaint_all @child.repaint paint end |
#set_view(ch) ⇒ Object
set the component to be viewed
60 61 62 |
# File 'lib/rbcurse/rviewport.rb', line 60 def set_view ch @child = ch end |
#set_view_position(r, c) ⇒ Object
Set the row and col of the child, that the viewport starts displaying. Used to initialize the view, and later if scrolling. Initially would be set to 0,0.
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 |
# File 'lib/rbcurse/rviewport.rb', line 76 def set_view_position r,c return false if r < 0 or c < 0 # 2010-02-04 19:29 TRYING -2 for borders $log.debug " set_view if #{r} +1+ #{@height} - #{@border_width} )} >=#{@child.height} " # 2010-02-12 15:33 XXX made > into >= and added +1 since -1 in set_buffering # testscrollp was crashing out when child height exceeded if r+ (@height+1-@border_width) >= @child.height # basically r + (:bottom - :screen_top) < @child.height #if r+ (@height) >= @child.height $log.debug " set_view_position : trying to exceed ht #{r} + #{@height} > #{@child.height} returned false" return false end # testscrollp was printing junk on right end. Why the 1? if c+ (@width+1-@border_width) >=@child.width #if c+ (@width) >[email protected] $log.debug " set_view_position : trying to exceed width #{c} + #{@width} . returned false" return false end $log.debug " VP row #{@row} col #{@col}, now will be #{r} , #{c} " row(r) # commnting off 2010-02-06 22:47 col(c) # commnting off 2010-02-06 22:47 # next call sets pminrow and pmincol $log.debug " VP setting child buffer pmin to #{r} #{c} " @child.get_buffer().set_pad_top_left(r, c) # replaced this on 2010-02-26 11:49 HOPE IT WORKS XXX #@child.fire_property_change("row", r, r) # XXX quick dirty, this should happen @child.repaint_required(true) @repaint_required = true #fire_handler :PROPERTY_CHANGE, self fire_state_changed return true end |
#set_view_size(h, w) ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/rbcurse/rviewport.rb', line 63 def set_view_size h,w # calling the property shoudl uniformally trigger fire_property_change $log.debug " setting viewport to h #{h} , w #{w} " height(h) width(w) fire_state_changed #fire_handler :PROPERTY_CHANGE, self # XXX should it be an event STATE_CHANGE with details end |
#width(*val) ⇒ Object
set width a container must pass down changes in size to it’s children added 2010-01-16 23:55
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/rbcurse/rviewport.rb', line 174 def width(*val) return @width if val.empty? oldvalue = @width || 0 super @width = val[0] return if @child == nil delta = @width - oldvalue return if delta == 0 @repaint_required = true # another safeguard if user did not enter. usesomething sensible 2010-01-17 15:23 if @child.width.nil? @child.width = @width $log.warn " viewport setting child #{@child.name} to default w of #{@width}. Usually child is larger. " else ## sometime we are needless increasing. this happens when we set viewport and ##+ child has been set. Or may do only if scrollpane is getting larger than child ##+ largely a situation with splitpanes. if @cascade_changes $log.debug "warn!! viewport adding #{delta} to child wt #{child.width} " @child.width += delta end end end |