class Umbra::Label

a text label. when creating use text= to set text. Optionally use justify and width.

Attributes

mnemonic[RW]

Public Class Methods

new(config={}) click to toggle source
Calls superclass method
# 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

Public Instance Methods

getvalue() click to toggle source

get the value for the label

# File lib/umbra/label.rb, line 39
def getvalue
  @text
end
on_enter() click to toggle source

Added 2011-10-22 to prevent some naive components from putting focus here.

# File lib/umbra/label.rb, line 96
def on_enter
  raise "Cannot enter Label"
end
on_leave() click to toggle source
# File lib/umbra/label.rb, line 99
def on_leave
  raise "Cannot leave Label"
end
print_label(win, row, col, format, value, _color, _attr) click to toggle source

The mwthod that finally prints the label text. Override this to do any customised printing such as multiple colors.

repaint() click to toggle source

NOTE: width can be nil, i have not set a default, containers asking width can crash. WHY NOT ?

# 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