aboutsummaryrefslogtreecommitdiff
path: root/option_set/option_set.gd
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-02-18 01:34:43 +0000
committerdam <dam@gudinoff>2022-02-18 01:34:43 +0000
commit283c0f2d84420bd02550dd4404b306d427fd58af (patch)
tree3999ad958556bcccba63b5fca05880accdc827f3 /option_set/option_set.gd
parent48a26128f175047528fcc1c96590f1a7bbc281eb (diff)
downloadsurgery-log-283c0f2d84420bd02550dd4404b306d427fd58af.tar.zst
surgery-log-283c0f2d84420bd02550dd4404b306d427fd58af.zip
Implemented custom option set control. Fixed option sets text input zone being hidden below the button.
Diffstat (limited to 'option_set/option_set.gd')
-rw-r--r--option_set/option_set.gd23
1 files changed, 22 insertions, 1 deletions
diff --git a/option_set/option_set.gd b/option_set/option_set.gd
index e9cac3f..62d10d0 100644
--- a/option_set/option_set.gd
+++ b/option_set/option_set.gd
@@ -1,6 +1,7 @@
extends Control
class_name OptionSet
+var options: Array
var text: String setget set_text, get_text
func set_text(var value: String):
@@ -9,7 +10,27 @@ func set_text(var value: String):
func get_text() -> String:
return input.text
+onready var input := get_node("input") as LineEdit
+onready var button := get_node("options") as Button # @DAM Maybe rename this. Also requires renaming on stage.
+onready var popup := get_node("/root/main/popup_list") as PopupList
-onready var input := get_node("input") as LineEdit
+func _ready():
+ assert(popup != null, "OptionSet failed to get 'popup' node.")
+
+ input.connect("focus_entered", input, "set", ["caret_position", input.max_length])
+ input.connect("focus_exited", input, "deselect")
+
+
+func show_options(options_array: Array):
+ options = options_array
+ popup.connect("item_selected", self, "option_selected", [], CONNECT_ONESHOT)
+ popup.popup_options(options)
+
+
+func option_selected(index: int):
+ if index >= 0 && index < options.size():
+ input.text = options[index]
+ input.caret_position = input.max_length
+ button.release_focus()