Class: RubyCurses::Divider
- Defined in:
- lib/rbcurse/core/widgets/divider.rb
Overview
This is a horizontal or vertical bar (like a scrollbar), at present attached to a widget that is focusable, and allows user to press arrow keys. It highlights on focus, the caller can expand and contract components in a container or even screen, based on arrow movements. This allows for a visual resizing of components. NOTE: since this can be deactivated, containers need to check focusable before passing focus in
2010-10-07 23:56 made focusable false by default. Add divider to
FocusManager when creating, so F3 can be used to set focusable
See rvimsplit.rb for example
Instance Attribute Summary
Attributes inherited from Widget
#_object_created, #col_offset, #cols_panned, #config, #curpos, #focussed, #form, #id, #key_label, #parent_component, #row_offset, #rows_panned, #state
Instance Method Summary collapse
- #convert_attrib_to_sym(attr) ⇒ Object
-
#deactivate_all(tf = true) ⇒ Object
deactivate all dividers The application has to provide a key or button to activate all or just this one.
-
#h? ⇒ Boolean
is this a horizontal divider.
- #handle_key(ch) ⇒ Object
-
#initialize(form, config = {}, &block) ⇒ Divider
constructor
TODO: if parent passed, we shold bind to ON_ENTER and get current_index, so no extra work is required.
-
#map_keys ⇒ Object
end.
- #on_enter ⇒ Object
- #on_leave ⇒ Object
-
#repaint ⇒ Object
repaint the scrollbar Taking the data from parent as late as possible in case parent resized, or moved around by a container.
-
#set_form_col ⇒ Object
set the cursor on first point of bar.
- #set_form_row ⇒ Object
-
#v? ⇒ Boolean
is this a vertical divider.
Methods inherited from Widget
#action_manager, #changed, #click, #color_pair, #command, #destroy, #enter, #event_list, #focus, #get_preferred_size, #getvalue, #getvalue_for_paint, #height, #height=, #hide, #init_vars, #leave, #modified?, #move, #override_graphic, #process_key, #remove, #repaint_all, #repaint_required, #rowcol, #set_buffer_modified, #set_buffering, #set_form, #set_modified, #setformrowcol, #setrowcol, #show, #text_variable, #unbind_key, #width, #width=
Methods included from Io
#__create_footer_window, #clear_this, #get_file, #print_this, #rb_getchar, #rb_gets, #rbgetstr, #warn
Methods included from Utils
#OLDdefine_key, #_process_key, #bind_key, #bind_keys, #clean_string!, #define_key, #define_prefix_command, #display_app_help, #get_attrib, #get_color, #keycode_tos, #last_line, #one_line_window, #parse_formatted_text, #print_key_bindings, #repeatm, #run_command, #shell_out, #shell_output, #suspend, #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) ⇒ Divider
TODO: if parent passed, we shold bind to ON_ENTER and get current_index, so no extra work is required.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 51 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 @height = 1 @color_pair = get_color $datacolor, @color, @bgcolor @scroll_pair = get_color $bottomcolor, :green, :white #@window = form.window @editable = false # you can set to true upon creation, or use F3 on vimsplit to # toggle focusable @focusable = false @repaint_required = true @_events.push(:DRAG_EVENT) map_keys unless @parent raise ArgumentError, "row col and length should be provided" if !@row || !@col || !@length end #if @parent #@parent.bind :ENTER_ROW do |p| ## parent must implement row_count, and have a @current_index #raise StandardError, "Parent 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 #end end |
Instance Method Details
#convert_attrib_to_sym(attr) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 155 def convert_attrib_to_sym attr case attr when 'reverse' Ncurses::A_REVERSE when 'bold' Ncurses::A_BOLD when 'normal' Ncurses::A_NORMAL when 'blink' Ncurses::A_BLINK when 'underline' Ncurses::A_UNDERLINE else Ncurses::A_REVERSE end end |
#deactivate_all(tf = true) ⇒ Object
deactivate all dividers The application has to provide a key or button to activate all or just this one.
174 175 176 177 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 174 def deactivate_all tf=true $deactivate_dividers = tf @focusable = !tf end |
#h? ⇒ Boolean
is this a horizontal divider
251 252 253 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 251 def h? @side == :right || @side == :left end |
#handle_key(ch) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 178 def handle_key ch # all dividers have been deactivated if $deactivate_dividers || !@focusable @focusable = false return :UNHANDLED end case @side when :right, :left case ch when KEY_RIGHT fire_handler :DRAG_EVENT, DragEvent.new(self, ch) when KEY_LEFT fire_handler :DRAG_EVENT, DragEvent.new(self, ch) else ret = process_key ch, self return ret if ret == :UNHANDLED end set_form_col when :top, :bottom case ch when KEY_UP fire_handler :DRAG_EVENT, DragEvent.new(self, ch) when KEY_DOWN fire_handler :DRAG_EVENT, DragEvent.new(self, ch) else ret = process_key ch, self return ret if ret == :UNHANDLED end set_form_col else end @repaint_required = true return 0 end |
#map_keys ⇒ Object
end
80 81 82 83 84 85 86 87 88 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 80 def map_keys if !defined? $deactivate_dividers $deactivate_dividers = false end # deactivate only this bar bind_key(?f) {@focusable=false; } # deactivate all bars, i've had nuff! bind_key(?F) {deactivate_all(true)} end |
#on_enter ⇒ Object
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 212 def on_enter if $deactivate_dividers || !@focusable @focusable = false return :UNHANDLED end # since it is over border of component, we need to repaint @focussed = true @repaint_required = true repaint end |
#on_leave ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 222 def on_leave @focussed = false @repaint_required = true repaint # TODO: we should review this since its not over the parent any longer if @parent # since it is over border of component, we need to clear @parent.repaint_required # if we don't paint now, parent paints over other possible dividers @parent.repaint end end |
#repaint ⇒ Object
repaint the scrollbar Taking the data from parent as late as possible in case parent resized, or moved around by a container. NOTE: sometimes if this is inside another object, the divider repaints but then is wiped out when that objects print_border is called. So such an obkect (e.g. vimsplit) should call repaint after its has done its own repaint. that does mean the repaint happens twice during movement
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 98 def repaint woffset = 2 coffset = 1 if @parent woffset = 0 if @parent.suppress_borders @border_attrib ||= @parent.border_attrib case @side when :right @row = @parent.row+1 @col = @parent.col + @parent.width - 0 @length = @parent.height - woffset when :left @row = @parent.row+1 @col = @parent.col+0 #+ @parent.width - 1 @length = @parent.height - woffset when :top @row = @parent.row+0 @col = @parent.col + @parent.col_offset #+ @parent.width - 1 @length = @parent.width - woffset when :bottom @row = @parent.row+@parent.height-0 #1 @col = @parent.col+@parent.col_offset #+ @parent.width - 1 @length = @parent.width - woffset end else # row, col and length should be passed end my_win = @form ? @form.window : @target_window @graphic = my_win unless @graphic raise "graphic is nil in divider, perhaps form was nil when creating" unless @graphic return unless @repaint_required # first print a right side vertical line #bc = $bottomcolor # dark blue bc = get_color($datacolor, :cyan, :black) bordercolor = @border_color || bc borderatt = @border_attrib || Ncurses::A_REVERSE if @focussed bordercolor = $promptcolor || bordercolor end borderatt = convert_attrib_to_sym(borderatt) if borderatt.is_a? Symbol @graphic.attron(Ncurses.COLOR_PAIR(bordercolor) | borderatt) $log.debug " XXX DIVIDER #{@row} #{@col} #{@length} " case @side when :right, :left @graphic.mvvline(@row, @col, 1, @length) when :top, :bottom @graphic.mvhline(@row, @col, 1, @length) end @graphic.attroff(Ncurses.COLOR_PAIR(bordercolor) | borderatt) _paint_marker #alert "divider repaint at #{row} #{col} " @repaint_required = false end |
#set_form_col ⇒ Object
set the cursor on first point of bar
240 241 242 243 244 245 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 240 def set_form_col return unless @focusable # need to set it to first point, otherwise it could be off the widget r,c = rowcol setrowcol r, c end |
#set_form_row ⇒ Object
234 235 236 237 238 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 234 def set_form_row return unless @focusable r,c = rowcol setrowcol r, c end |
#v? ⇒ Boolean
is this a vertical divider
247 248 249 |
# File 'lib/rbcurse/core/widgets/divider.rb', line 247 def v? @side == :top || @side == :bottom end |