From b1d9ecf43943ccad1665bfb3467901d1069ea58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Rene=CC=81=20Lavoie?= <> Date: Thu, 21 Mar 2024 10:29:35 -0400 Subject: [PATCH] feat: Option to add child at First position to ViewComponent --- .../fxgl/entity/components/ViewComponent.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fxgl-entity/src/main/kotlin/com/almasb/fxgl/entity/components/ViewComponent.kt b/fxgl-entity/src/main/kotlin/com/almasb/fxgl/entity/components/ViewComponent.kt index ba827dc7e..9cdd849f6 100644 --- a/fxgl-entity/src/main/kotlin/com/almasb/fxgl/entity/components/ViewComponent.kt +++ b/fxgl-entity/src/main/kotlin/com/almasb/fxgl/entity/components/ViewComponent.kt @@ -163,10 +163,17 @@ class ViewComponent : Component() { * Add a child node to this view. */ @JvmOverloads fun addChild(node: Node, isTransformApplied: Boolean = true) { + addChild(node, isTransformApplied, true) + } + + /** + * Add a child node to this view. + */ + fun addChild(node: Node, isTransformApplied: Boolean, addLast: Boolean) { if (isTransformApplied) { - addToGroup(viewRoot, node) + addToGroup(viewRoot, node, addLast) } else { - addToGroup(viewRootNoTransform, node) + addToGroup(viewRootNoTransform, node, addLast) } if (node is View) @@ -205,7 +212,7 @@ class ViewComponent : Component() { removeFromGroup(devRoot, node) } - private fun addToGroup(group: Group, child: Node, addLast: Boolean = false) { + private fun addToGroup(group: Group, child: Node, addLast: Boolean) { if (!(parent as Group).children.contains(group)) { if (addLast) { parent.children += group @@ -214,7 +221,11 @@ class ViewComponent : Component() { } } - group.children += child + if(addLast) { + group.children += child + } else { + group.children.add(0, child) + } } private fun removeFromGroup(group: Group, child: Node) {