From 9ecb8c7030189c53fe6f96d22a27ff7a83a4b1ee Mon Sep 17 00:00:00 2001 From: Geronimo Ferruccio Date: Fri, 27 Dec 2024 00:09:46 -0300 Subject: [PATCH] Fix padding not being applied properly in LinearContainer --- .../andengine/container/LinearContainer.kt | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/com/reco1l/andengine/container/LinearContainer.kt b/src/com/reco1l/andengine/container/LinearContainer.kt index 266c61caf..9f2dd9080 100644 --- a/src/com/reco1l/andengine/container/LinearContainer.kt +++ b/src/com/reco1l/andengine/container/LinearContainer.kt @@ -36,29 +36,42 @@ open class LinearContainer : Container() { contentWidth = 0f contentHeight = 0f - if (mChildren != null) { + for (i in 0 until childCount) { - for (i in mChildren.indices) { + val child = getChild(i) ?: continue + if (child !is ExtendedEntity) { + continue + } + + when (orientation) { + + Horizontal -> { + child.x = contentWidth + + contentWidth += child.getDrawWidth() + contentHeight = max(contentHeight, child.getDrawHeight()) - val child = mChildren.getOrNull(i) ?: continue - if (child !is ExtendedEntity) { - continue + if (i == 0) { + contentWidth += getPadding().left + } + + if (i < childCount - 1) { + contentWidth += spacing + } } - val spacing = if (i == mChildren.size - 1) 0f else spacing + Vertical -> { + child.y = contentHeight - when (orientation) { + contentWidth = max(contentWidth, child.getDrawWidth()) + contentHeight += child.getDrawHeight() - Horizontal -> { - child.x = contentWidth - contentWidth += child.getDrawWidth() + spacing - contentHeight = max(contentHeight, child.getDrawHeight()) + if (i == 0) { + contentHeight += getPadding().top } - Vertical -> { - child.y = contentHeight - contentWidth = max(contentWidth, child.getDrawWidth()) - contentHeight += child.getDrawHeight() + spacing + if (i < childCount - 1) { + contentHeight += spacing } } }