Class: TextFieldWidget

Inherits:
Object
  • Object
show all
Defined in:
lib/widget/text-field-widget.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(screen, value, x, y, w, h) ⇒ TextFieldWidget

Returns a new instance of TextFieldWidget.



4
5
6
7
8
9
10
11
12
# File 'lib/widget/text-field-widget.rb', line 4

def initialize(screen, value, x, y, w, h)
    @active = false
    @screen = screen
    @value  = value
    @x      = x
    @y      = y
    @w      = w
    @h      = h
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



2
3
4
# File 'lib/widget/text-field-widget.rb', line 2

def active
  @active
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/widget/text-field-widget.rb', line 3

def value
  @value
end

Instance Method Details

#drawObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/widget/text-field-widget.rb', line 29

def draw
    @value ||= ""
    value = @value

    if(value.empty?)
        (0..@h).each do |x|
            value += "_"*@w+"\n"
        end
    end

    @screen.setpos(@y,@x)
    @screen.attron Curses::A_BOLD if @active
    @screen.addstr(value)
    @screen.attroff Curses::A_BOLD if @active
end

#handle(chr) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/widget/text-field-widget.rb', line 14

def handle(chr)
    if(chr.class == String && chr.match(/[[:print:]\n]/))
        @value += chr
        true
    elsif(chr == Curses::KEY_ENTER || chr == 13)
        @value += "\n"
        true
    elsif(chr == Curses::KEY_BACKSPACE || chr == 127)
        @value = @value[0..-2]
        true
    else
        false
    end
end