Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Option to add child at First position to ViewComponent #1362

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -214,7 +221,11 @@ class ViewComponent : Component() {
}
}

group.children += child
if(addLast) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addLast is currently being used to add groups to parent -- in-game groups go first, developer groups go last, so we cannot use it to manage group children.

Perhaps we can generalise this to something like addChild(index: Int, node: Node, isTransformApplied: Boolean) with the default implementation being just addChild(node: Node, isTransformApplied: Boolean) which adds it last.

group.children += child
} else {
group.children.add(0, child)
}
}

private fun removeFromGroup(group: Group, child: Node) {
Expand Down
Loading