aboutsummaryrefslogtreecommitdiff
path: root/option_set
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
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')
-rw-r--r--option_set/option_set.gd23
-rw-r--r--option_set/option_set.tscn3
2 files changed, 24 insertions, 2 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()
diff --git a/option_set/option_set.tscn b/option_set/option_set.tscn
index fc2aff5..bf15806 100644
--- a/option_set/option_set.tscn
+++ b/option_set/option_set.tscn
@@ -15,7 +15,8 @@ anchor_right = 1.0
anchor_bottom = 1.0
margin_right = -100.0
size_flags_horizontal = 3
-placeholder_text = "option set placeholder"
+text = "placeholder"
+max_length = 4096
caret_blink = true
caret_blink_speed = 0.5
__meta__ = {