Class: RETerm::Components::Label

Inherits:
RETerm::Component show all
Defined in:
lib/reterm/components/label.rb

Overview

Simply renders text to window

Constant Summary

Constants included from LogHelpers

LogHelpers::LOG_FILE

Instance Attribute Summary collapse

Attributes inherited from RETerm::Component

#activatable, #activate_focus, #highlight_focus, #window

Instance Method Summary collapse

Methods inherited from RETerm::Component

#activatable?, #activate!, #activate_focus?, #cdk?, #colored?, #colors=, #deactivate!, #deactivate?, #distance_from, #extra_padding, #finalize!, #highlight_focus?, #reactivate!, #resize, #sync!, #sync_getch

Methods included from KeyBindings

#bind_key, #invoke_key_bindings, #key_bindings, #key_bound?

Methods included from LogHelpers

#logger

Methods included from EventDispatcher

#dispatch, #handle

Constructor Details

#initialize(args = {}) ⇒ Label

Initialize the Label component

Parameters:

  • args (Hash) (defaults to: {})

    label params

Options Hash (args):

  • :text (String)

    text of the label



12
13
14
15
# File 'lib/reterm/components/label.rb', line 12

def initialize(args={})
  super
  @text    = args[:text] || ""
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/reterm/components/label.rb', line 6

def text
  @text
end

Instance Method Details

#draw!Object



25
26
27
28
# File 'lib/reterm/components/label.rb', line 25

def draw!
  padding = " " * [0, window.cols - @text.size-2].max
  window.mvaddstr(0, 0, @text + padding)
end

#eraseObject



30
31
32
33
34
# File 'lib/reterm/components/label.rb', line 30

def erase
  padding = " " * [0, window.cols - @text.size-2].max
  window.mvaddstr(0, 0, " " * (@text + padding).size)
  window.refresh
end

#requested_colsObject



21
22
23
# File 'lib/reterm/components/label.rb', line 21

def requested_cols
  @text.size + 1
end

#requested_rowsObject



17
18
19
# File 'lib/reterm/components/label.rb', line 17

def requested_rows
  2
end