Class: Canis::ListRenderer
- Inherits:
-
AbstractTextPadRenderer
- Object
- AbstractTextPadRenderer
- Canis::ListRenderer
- Defined in:
- lib/canis/core/widgets/listbox.rb
Overview
Takes care of rendering the list. In the case of a List we take care of selected indices. Also, focussed row is shown in bold, although we can make that optional and configurable A user wanting a different rendering of listboxes may either extend this class or completely replace it and set it as the renderer.
Instance Attribute Summary collapse
-
#left_margin_text ⇒ Object
text to be placed in the left margin.
- #row_focussed_attr ⇒ Object
Attributes inherited from AbstractTextPadRenderer
#attr, #color_pair, #content_cols, #cp, #list, #source
Instance Method Summary collapse
-
#_clear_row(pad, lineno) ⇒ Object
clear row before writing so previous contents are erased and don’t show through I could do this everytime i write but trying to make it faster and only call this if
fire_row_changed
is called. -
#initialize(source) ⇒ ListRenderer
constructor
A new instance of ListRenderer.
-
#pre_render ⇒ Object
This is called prior to render_all, and may not be called when a single row is rendered as in fire_row_changed.
-
#render(pad, lineno, text) ⇒ Object
– NOTE: in some cases like testlistbox.rb if a line is updated then the newly printed value may not overwrite the entire line, addstr seems to only write the text no more Fixed with
clear_row
++.
Methods inherited from AbstractTextPadRenderer
Constructor Details
#initialize(source) ⇒ ListRenderer
Returns a new instance of ListRenderer.
225 226 227 228 229 230 231 232 233 |
# File 'lib/canis/core/widgets/listbox.rb', line 225 def initialize source @source = source # internal width based on both borders - earlier internal_width which we need @int_w = 3 # 3 leaves a blank black in popuplists as in testlistbox.rb F4 # setting it as 2 means that in some cases, the next line first character # gets overwritten with traversal #@int_w = 2 end |
Instance Attribute Details
#left_margin_text ⇒ Object
text to be placed in the left margin. This requires that a left margin be set in the source object.
222 223 224 |
# File 'lib/canis/core/widgets/listbox.rb', line 222 def left_margin_text @left_margin_text end |
#row_focussed_attr ⇒ Object
223 224 225 |
# File 'lib/canis/core/widgets/listbox.rb', line 223 def row_focussed_attr @row_focussed_attr end |
Instance Method Details
#_clear_row(pad, lineno) ⇒ Object
clear row before writing so previous contents are erased and don’t show through I could do this everytime i write but trying to make it faster and only call this if fire_row_changed
is called. NOTE: in clear_row one is supposed to clear to the width of the pad, not window
otherwise on scrolling you might get black bg if you have some other color bg.
This is mostly important if you have a bgcolor that is different from the terminal
bgcolor.
313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/canis/core/widgets/listbox.rb', line 313 def _clear_row pad, lineno raise "unused" @color_pair ||= get_color($datacolor, @source.color, @source.bgcolor) cp = @color_pair att = NORMAL @_clearstring ||= " " * (@source.width - @left_margin - @int_w) # with int_w = 3 we get that one space in popuplist # added attr on 2014-05-02 - 00:16 otherwise a list inside a white bg messagebox shows # empty rows in black bg. FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att) FFI::NCurses.mvwaddstr(pad,lineno, @left_margin, @_clearstring) FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att) end |
#pre_render ⇒ Object
This is called prior to render_all, and may not be called when a single row is rendered
as in fire_row_changed
236 237 238 239 240 241 242 243 244 |
# File 'lib/canis/core/widgets/listbox.rb', line 236 def pre_render super @selected_indices = @source.selected_indices @left_margin = @source.left_margin @bg = @source.bgcolor @fg = @source.color @attr = NORMAL @row_focussed_attr ||= $row_focussed_attr end |
#render(pad, lineno, text) ⇒ Object
– NOTE: in some cases like testlistbox.rb if a line is updated then the newly printed value may not overwrite the entire line, addstr seems to only write the text no more Fixed with clear_row
++
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/canis/core/widgets/listbox.rb', line 255 def render pad, lineno, text sele = false =begin bg = @source.bgcolor fg = @source.color att = NORMAL cp = get_color($datacolor, fg, bg) =end bg = @bg || @source.bgcolor fg = @fg || @source.color att = @attr || NORMAL cp = get_color($datacolor, fg, bg) if @selected_indices.include? lineno # print selected row in reverse sele = true fg = @source.selected_color || fg bg = @source.selected_bgcolor || bg att = @source.selected_attr || REVERSE cp = get_color($datacolor, fg, bg) elsif lineno == @source.current_index # print focussed row in different attrib if @source.should_show_focus # bold was supposed to be if the object loses focus, but although render is called # however, padrefresh is not happening since we do not paint on exiting a widget att = BOLD if @source.focussed att = @row_focussed_attr end end # take current index into account as BOLD # and oldindex as normal end FFI::NCurses.wattron(pad,FFI::NCurses.COLOR_PAIR(cp) | att) FFI::NCurses.mvwaddstr(pad, lineno, 0, @left_margin_text) if @left_margin_text FFI::NCurses.mvwaddstr(pad, lineno, @left_margin, text) FFI::NCurses.wattroff(pad,FFI::NCurses.COLOR_PAIR(cp) | att) # the above only sets the attrib under the text not the whole line, we # need the whole line to be REVERSE # Strangely in testlistbox1 unselecting removes the entire lines REVERSE # but in testlistbox.rb the previous selected lines REV only partially goes # so we have to make the entire line in current attrib sele = true if sele FFI::NCurses.mvwchgat(pad, y=lineno, x=@left_margin, @source.width - @left_margin - @int_w, att, cp, nil) end end |