Class: Umbra::Label
Overview
a text label. when creating use text=
to set text. Optionally use justify
and width
.
Instance Attribute Summary collapse
-
#mnemonic ⇒ Object
alt-key that passes focus to related field.
-
#related_widget ⇒ Object
field related to this label.
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
-
#getvalue ⇒ Object
get the value for the label.
-
#initialize(config = {}, &block) ⇒ Label
constructor
A new instance of Label.
-
#on_enter ⇒ Object
Added 2011-10-22 to prevent some naive components from putting focus here.
- #on_leave ⇒ Object
-
#print_label(win, row, col, format, value, _color, _attr) ⇒ Object
The mwthod that finally prints the label text.
-
#repaint ⇒ Object
NOTE: width can be nil, i have not set a default, containers asking width can crash.
Methods inherited from Widget
#_form=, #color_pair, #command, #getvalue_for_paint, #handle_key, #height, #highlight_attr, #init_vars, #modified?, #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) ⇒ Label
Returns a new instance of Label.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/umbra/label.rb', line 24 def initialize config={}, &block @text = config.fetch(:text, "NOTFOUND") @editable = false @focusable = false # we have some processing for when a form is attached, registering a hotkey #register_events :FORM_ATTACHED super @justify ||= :left @name ||= @text @width ||= @text.length # 2018-04-14 - added for messageboxes @repaint_required = true end |
Instance Attribute Details
#mnemonic ⇒ Object
alt-key that passes focus to related field
21 22 23 |
# File 'lib/umbra/label.rb', line 21 def mnemonic @mnemonic end |
#related_widget ⇒ Object
field related to this label. See mnemonic
.
22 23 24 |
# File 'lib/umbra/label.rb', line 22 def @related_widget end |
Instance Method Details
#getvalue ⇒ Object
get the value for the label
39 40 41 |
# File 'lib/umbra/label.rb', line 39 def getvalue @text end |
#on_enter ⇒ Object
Added 2011-10-22 to prevent some naive components from putting focus here.
96 97 98 |
# File 'lib/umbra/label.rb', line 96 def on_enter raise "Cannot enter Label" end |
#on_leave ⇒ Object
99 100 101 |
# File 'lib/umbra/label.rb', line 99 def on_leave raise "Cannot leave Label" end |
#print_label(win, row, col, format, value, _color, _attr) ⇒ Object
The mwthod that finally prints the label text. Override this to do any customised printing such as multiple colors.
92 93 94 |
# File 'lib/umbra/label.rb', line 92 def print_label(win, row, col, format, value, _color, _attr) win.printstring row, col, format % [value], _color, _attr end |
#repaint ⇒ Object
NOTE: width can be nil, i have not set a default, containers asking width can crash. WHY NOT ?
46 47 48 49 50 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 80 81 82 83 84 85 86 87 88 |
# File 'lib/umbra/label.rb', line 46 def repaint return unless @repaint_required raise "Label row or col is nil #{@row} , #{@col}, #{@text} " if @row.nil? || @col.nil? #r,c = rowcol r = self.row c = self.col $log.debug "label repaint #{r} #{c} #{@text} " # value often nil so putting blank, but usually some application error value = getvalue_for_paint || "" if value.is_a? Array value = value.join " " end # ensure we do not exceed # ## TODO do this in the format commented on 2018-05-22 - _width = self.width #if _width #if value.length > _width #value = value[0.._width-1] #end #end len = _width || value.length acolor = @color_pair || 0 #str = @justify.to_sym == :right ? "%*s" : "%-*s" # added 2008-12-22 19:05 str = @justify.to_sym == :right ? "%#{len}.#{len}s" : "%-#{len}.#{len}s" # added 2008-12-22 19:05 # clear the area @graphic.printstring r, c, " " * len , acolor, @attr if @justify.to_sym == :center padding = (_width - value.length)/2 value = " "*padding + value + " "*padding # so its cleared if we change it midway end ## move this into paint_label or something so we can override. # try a block which was passed earlier which gets a string TODO #@graphic.printstring r, c, str % [value], acolor, @attr print_label @graphic, r, c, str , value, acolor, @attr if @mnemonic ulindex = value.index(@mnemonic) || value.index(@mnemonic.swapcase) @graphic.mvchgat(y=r, x=c+ulindex, max=1, BOLD|UNDERLINE, acolor, nil) end @repaint_required = false end |