Class: Umbra::LabeledField
- Defined in:
- lib/umbra/labeledfield.rb
Overview
A widget that has an entry Field
and an associated String
. This stores a String
and prints it before the Field
. This label is gauranteed to print to the left of the Field. This label prints on lrow
and lcol
if supplied, else it will print on the left of the field at col
minus the width of the label.
It is initialized exactly like a Field, with the addition of ‘:label` (and optionally label_color_pair,
label_attr, and lcol, lrow)
Instance Attribute Summary collapse
-
#mnemonic ⇒ Object
mnemonic of field which shows up on label.
-
#related_widget ⇒ Object
to keep sync with label.
Attributes inherited from Field
#above, #below, #buffer, #datatype, #editable, #field_col, #mask, #maxlen, #null_allowed, #original_value, #overwrite_mode, #valid_range, #valid_regex, #values
Attributes inherited from Widget
#col, #col_offset, #curpos, #focusable, #graphic, #handler, #key_label, #modified, #name, #repaint_required, #row, #row_offset, #state
Instance Method Summary collapse
-
#initialize(config = {}, &block) ⇒ LabeledField
constructor
A new instance of LabeledField.
- #label ⇒ Object
-
#repaint ⇒ Object
paint the widget, called by
Form
.
Methods inherited from Field
#cursor_backward, #cursor_end, #cursor_forward, #cursor_home, #delete_at, #delete_curr_char, #delete_eol, #delete_prev_char, #getvalue, #handle_key, #in_range?, #init_vars, #map_keys, #modified?, #on_enter, #on_leave, #putc, #putch, #restore_original_value, #text, #text=, #type=, #undo_delete_eol
Methods inherited from Widget
#_form=, #color_pair, #command, #getvalue, #getvalue_for_paint, #handle_key, #height, #highlight_attr, #init_vars, #modified?, #on_enter, #on_leave, #repaint_all, #rowcol, #set_form_col, #set_form_row, #text, #touch, #variable_set, #visible, #width
Methods included from KeyMappingHandler
#_process_key, #bind_key, #bind_keys, #process_key, #unbind_key
Methods included from EventHandler
#bind_event, #event?, #fire_handler, #fire_property_change, #register_events
Constructor Details
#initialize(config = {}, &block) ⇒ LabeledField
Returns a new instance of LabeledField.
54 55 56 57 |
# File 'lib/umbra/labeledfield.rb', line 54 def initialize config={}, &block @related_widget = self super end |
Instance Attribute Details
#mnemonic ⇒ Object
mnemonic of field which shows up on label
52 53 54 |
# File 'lib/umbra/labeledfield.rb', line 52 def mnemonic @mnemonic end |
#related_widget ⇒ Object
to keep sync with label
53 54 55 |
# File 'lib/umbra/labeledfield.rb', line 53 def @related_widget end |
Instance Method Details
#label ⇒ Object
35 |
# File 'lib/umbra/labeledfield.rb', line 35 attr_property :label |
#repaint ⇒ Object
paint the widget, called by Form
.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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/umbra/labeledfield.rb', line 60 def repaint #:nodoc: return unless @repaint_required _lrow = @lrow || @row # the next was nice, but in some cases this goes out of screen. and the container # only sets row and col for whatever is added, it does not know that lcol has to be # taken into account _lcol = @lcol || (@col - @label.length - 2) if _lcol < 1 @lcol = @col @col = @lcol + @label.length + 2 _lcol = @lcol end =begin # This actually uses the col of the field, and pushes field ahead. We need to get the above to work. unless @lcol @lcol = @col @col = @lcol + @label.length + 2 end _lcol = @lcol =end lcolor = @label_color_pair || CP_BLACK lattr = @label_attr || NORMAL # this gives the effect of `pine` (aka alpine) email client, of highlighting the label # when the field is in focus. if @state == :HIGHLIGHTED lcolor = @label_highlight_color_pair || lcolor lattr = @label_highlight_attr || lattr end $log.debug " repaint labeledfield lrow: #{_lrow} lcol #{_lcol} " # print the label @graphic.printstring _lrow, _lcol, @label, lcolor, lattr # print the mnemonic if @mnemonic index = label.index(@mnemonic) || label.index(@mnemonic.swapcase) if index y = _lcol + index x = _lrow @graphic.mvchgat(x, y, max=1, FFI::NCurses::A_BOLD|UNDERLINE, FFI::NCurses.COLOR_PAIR(lcolor || 1), nil) end end # print the field super end |