Class: TerminalNotes::SearchField

Inherits:
Widget
  • Object
show all
Defined in:
lib/terminal-notes/search_field.rb

Constant Summary collapse

WIDTH =
0.5
HEIGHT =
5
POS_X =
0
POS_Y =
1
ALIGN =
:center

Constants inherited from Widget

Widget::TITLE_PADDING

Instance Attribute Summary

Attributes inherited from Widget

#height, #width, #window

Instance Method Summary collapse

Methods inherited from Widget

#draw, #redraw, #resize

Constructor Details

#initialize(parent:) ⇒ SearchField

Returns a new instance of SearchField.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/terminal-notes/search_field.rb', line 9

def initialize(parent:)
    super(parent: parent, title: "Search",
          width: WIDTH, height: HEIGHT,
          x: POS_X, y: POS_Y,
          align: ALIGN)

    @text_field = TextField.new(@parent,
        position: @position.dup.moveBy(2, 2),
        width:    @width - 4)

    @has_focus = false

    draw
end

Instance Method Details

#focusObject



28
29
30
31
# File 'lib/terminal-notes/search_field.rb', line 28

def focus
    @has_focus = true
    @text_field.draw
end

#on_key(key) ⇒ Object



41
42
43
44
# File 'lib/terminal-notes/search_field.rb', line 41

def on_key key
    return unless @has_focus
    @text_field.on_key(key)
end

#on_text_changed(&delegate) ⇒ Object



37
38
39
# File 'lib/terminal-notes/search_field.rb', line 37

def on_text_changed &delegate
    @text_field.on_text_changed { |p| delegate.call(p) }
end

#textObject



24
25
26
# File 'lib/terminal-notes/search_field.rb', line 24

def text
    @text_field.text
end

#unfocusObject



33
34
35
# File 'lib/terminal-notes/search_field.rb', line 33

def unfocus
    @has_focus = false
end