Class: UI::LabelWidget

Inherits:
Window show all
Defined in:
lib/ektoplayer/ui/widgets/labelwidget.rb

Instance Attribute Summary collapse

Attributes inherited from Window

#win

Attributes inherited from Widget

#pos, #size

Instance Method Summary collapse

Methods inherited from Window

#layout, #noutrefresh, #refresh

Methods inherited from Widget

#display, #events, #invisible!, #invisible?, #key_press, #keys, #layout, #lock, #mouse, #mouse_click, #mouse_event_transform, #mouse_section, #on_key_press, #on_widget_raise, #raise_widget, #refresh, #sub, #unlock, #visible!, #visible=, #visible?, #want_layout, #want_redraw, #want_refresh, #with_lock

Constructor Details

#initialize(text: '', attributes: 0, pad: {}, **opts) ⇒ LabelWidget

Returns a new instance of LabelWidget.



7
8
9
10
11
# File 'lib/ektoplayer/ui/widgets/labelwidget.rb', line 7

def initialize(text: '', attributes: 0, pad: {}, **opts)
   super(**opts)
   @text, @attributes, @pad = text.to_s, attributes, Hash.new(0)
   @pad.update pad
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/ektoplayer/ui/widgets/labelwidget.rb', line 5

def attributes
  @attributes
end

#padObject

Returns the value of attribute pad.



5
6
7
# File 'lib/ektoplayer/ui/widgets/labelwidget.rb', line 5

def pad
  @pad
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/ektoplayer/ui/widgets/labelwidget.rb', line 5

def text
  @text
end

Instance Method Details

#drawObject



28
29
30
31
32
33
34
# File 'lib/ektoplayer/ui/widgets/labelwidget.rb', line 28

def draw
   @win.erase
   @text.split(?\n).each_with_index do |l, i|
      @win.move(@pad[:top] + i, @pad[:left])
      @win.attron(@attributes) { @win << l }
   end
end

#fitObject



36
37
38
39
40
41
42
43
# File 'lib/ektoplayer/ui/widgets/labelwidget.rb', line 36

def fit
   self.size=(Size.new(
      height: @pad[:top] + @pad[:bottom] + 1 + @text.count(?\n),
      width:  @pad[:left] + @pad[:right] + @text.split(?\n).max.size
   ))

   self
end