Skip to content

Commit

Permalink
Fix padding not being applied properly in LinearContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
Reco1I committed Dec 27, 2024
1 parent 933cb9d commit 9ecb8c7
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/com/reco1l/andengine/container/LinearContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 9ecb8c7

Please sign in to comment.