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
#col_offset, #cols_panned, #config, #curpos, #ext_col_offset, #ext_row_offset, #form, #id, #parent_component, #row_offset, #rows_panned, #should_create_buffer, #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
#OLDbind_key, #buffer_to_screen, #buffer_to_window, #create_buffer, #destroy, #destroy_buffer, #focus, #get_buffer, #get_color, #get_preferred_size, #getvalue_for_paint, #height=, #hide, #is_double_buffered?, #modified?, #move, #on_enter, #on_leave, #override_graphic, #printstring, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #safe_create_buffer, #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
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 EventHandler
#bind, #fire_handler, #fire_property_change
Methods included from DSL
Constructor Details
#initialize(form, config = {}, &block) ⇒ Viewport
attr_reader :top_margin, :left_margin
42 43 44 45 46 47 48 49 50 51 52 |
# 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 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
198 199 200 201 |
# File 'lib/rbcurse/rviewport.rb', line 198 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.
108 109 110 111 |
# File 'lib/rbcurse/rviewport.rb', line 108 def get_pad_top_left p = @child.get_buffer() return p.pminrow, p.pmincol end |
#getvalue ⇒ Object
122 123 124 |
# File 'lib/rbcurse/rviewport.rb', line 122 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
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/rbcurse/rviewport.rb', line 127 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
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/rbcurse/rviewport.rb', line 151 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
53 54 55 56 57 |
# File 'lib/rbcurse/rviewport.rb', line 53 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]”
141 142 143 144 |
# File 'lib/rbcurse/rviewport.rb', line 141 def paint @repaint_required = false @repaint_all = false end |
#repaint ⇒ Object
viewport
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rbcurse/rviewport.rb', line 112 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
59 60 61 |
# File 'lib/rbcurse/rviewport.rb', line 59 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.
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 |
# File 'lib/rbcurse/rviewport.rb', line 75 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
62 63 64 65 66 67 68 69 |
# File 'lib/rbcurse/rviewport.rb', line 62 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_CHANGED 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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/rbcurse/rviewport.rb', line 173 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 |