I'm trying to create a control to let users input numbers. Actually, I'd like to have something exactly like what the inspector uses to let you specify numeric values, but that control does not seem to be exposed in the API so I'm trying to write the equivalent.
Below is the code I have so far. I have the text_submitted signal set up so that _on_text_submitted2 should be called. It works fine if I run the scene it as its own program. However, when I try to make an instance of it as a child in another component, the _on_text_submitted2() method is no longer called. Is the parent control somehow preventing this? How do I get my numeric text control to work.
extends LineEdit
class_name NumbericLineEdit
signal value_changed(value)
@export var value:float:
get:
return value
set(v):
if value == v:
return
value = v
text = "%s" % value
@export var step_size:float = 1
# Called when the node enters the scene tree for the first time.
func _ready():
text = "%s" % value
func _on_text_submitted2(new_text):
var regex = RegEx.new()
regex.compile("^[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)$")
var result:RegExMatch = regex.search(new_text)
if result:
value = float(new_text)
value_changed.emit(value)
text = "%s" % value