![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | lee451 |
I’m trying to sort by ascending using a ScrollContainer, but I don’t think I’m doing it correctly.
In my scene I have this kind of parent-child relationship
Node (Main)
- ScrollContainer
-
- VBoxContainer
-
-
- HBoxContainer
-
-
-
-
- ColorRect
-
-
-
-
-
- TextEdit
-
-
-
-
-
- Button
-
-
Where I have multiple HBoxContainers in the VBoxContainer. The TextEdit control has different string values that I’m converting to floats in my custom sort function.
func _on_ScrollContainer_sort_children():
$ScrollContainer.get_node("VBoxContainer").get_children().sort_custom(MyCustomSorter, "sort")
class MyCustomSorter:
static func sort(a, b):
if float(a.get_node("TextEdit").text) < float(b.get_node("TextEdit").text):
print(a.get_node("TextEdit").text + " is less than " + b.get_node("TextEdit").text + " returned true")
else:
print(a.get_node("TextEdit").text + " is greater than or equal to " + b.get_node("TextEdit").text + " returned false")
return float(a.get_node("TextEdit").text) <= float(b.get_node("TextEdit").text)
The function seems to be getting called because it does print out to the console, but the controls don’t seem to be getting rearranged.
Am I doing this completely wrong? Is there example code out there that already does something like this? Did I miss a setting?
I appreciate any help.