-
-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathSearchBar.gd
39 lines (28 loc) · 958 Bytes
/
SearchBar.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
tool
extends HBoxContainer
signal next_match_requested(text)
var is_active: bool setget set_is_active
var search_text: String setget set_search_text
onready var _line_edit := $LineEdit as LineEdit
onready var _next_button := $NextButton as Button
func _ready() -> void:
set_is_active(false)
_line_edit.connect("text_entered", self, "set_search_text")
_next_button.connect("pressed", self, "_request_next_match")
func set_search_text(text: String) -> void:
if text == search_text:
return
search_text = text
if not search_text.empty():
emit_signal("next_match_requested", search_text)
func set_is_active(value: bool) -> void:
is_active = value
if not is_inside_tree():
yield(self, "ready")
_line_edit.editable = is_active
_next_button.disabled = not is_active
func _request_next_match() -> void:
if search_text.empty():
search_text = _line_edit.text
if not search_text.empty():
emit_signal("next_match_requested", search_text)