Skip to content

Commit 61c925f

Browse files
committed
Merge branch 'engine-scalling' into main-scene-v2
2 parents c185792 + 8b76fd8 commit 61c925f

6 files changed

Lines changed: 46 additions & 10 deletions

File tree

src/com/reco1l/andengine/buffered/UIBufferedComponent.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ abstract class UIBufferedComponent<T: IBuffer> : UIComponent() {
8383

8484
//region Draw pipeline
8585

86+
override fun onSizeChanged() {
87+
super.onSizeChanged()
88+
requestNewBuffer()
89+
}
90+
8691
override fun onHandleInvalidations() {
8792

8893
if (needsNewBuffer) {

src/com/reco1l/andengine/container/UIConstraintContainer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ open class UIConstraintContainer : UIContainer() {
3636
val targetHeight = target.transformedHeight
3737

3838
val cancelledX = padding.left + child.anchorPositionX
39-
val cancelledY = padding.right + child.anchorPositionY
39+
val cancelledY = padding.top + child.anchorPositionY
4040

4141
child.x = -cancelledX + targetX + targetWidth * child.anchor.x
4242
child.y = -cancelledY + targetY + targetHeight * child.anchor.y

src/com/reco1l/andengine/container/UIContainer.kt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,20 @@ open class UIContainer : UIComponent() {
2727
val x = max(0f, child.absoluteX)
2828
val y = max(0f, child.absoluteY)
2929

30-
contentWidth = max(contentWidth, x + child.width)
31-
contentHeight = max(contentHeight, y + child.height)
30+
// Use intrinsic size when child has relative sizing to avoid circular dependencies
31+
val childWidth = if (child is UIComponent && child.rawWidth in Size.relativeSizeRange) {
32+
child.intrinsicWidth
33+
} else {
34+
child.width
35+
}
36+
val childHeight = if (child is UIComponent && child.rawHeight in Size.relativeSizeRange) {
37+
child.intrinsicHeight
38+
} else {
39+
child.height
40+
}
41+
42+
contentWidth = max(contentWidth, x + childWidth)
43+
contentHeight = max(contentHeight, y + childHeight)
3244
}
3345
}
3446

src/com/reco1l/andengine/container/UILinearContainer.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.reco1l.andengine.container
22

33
import com.reco1l.andengine.component.*
44
import com.reco1l.andengine.container.Orientation.*
5+
import com.reco1l.andengine.theme.Size
56
import kotlin.math.*
67

78
open class UILinearContainer : UIContainer() {
@@ -35,13 +36,16 @@ open class UILinearContainer : UIContainer() {
3536
continue
3637
}
3738

39+
val childWidth = if (child.rawWidth in Size.relativeSizeRange) child.intrinsicWidth else child.width
40+
val childHeight = if (child.rawHeight in Size.relativeSizeRange) child.intrinsicHeight else child.height
41+
3842
when (orientation) {
3943

4044
Horizontal -> {
4145
child.x = contentWidth
4246

43-
contentWidth += child.width
44-
contentHeight = max(contentHeight, child.height)
47+
contentWidth += childWidth
48+
contentHeight = max(contentHeight, childHeight)
4549

4650
if (childCount > 1 && i < childCount - 1) {
4751
contentWidth += spacing
@@ -51,8 +55,8 @@ open class UILinearContainer : UIContainer() {
5155
Vertical -> {
5256
child.y = contentHeight
5357

54-
contentWidth = max(contentWidth, child.width)
55-
contentHeight += child.height
58+
contentWidth = max(contentWidth, childWidth)
59+
contentHeight += childHeight
5660

5761
if (childCount > 1 && i < childCount - 1) {
5862
contentHeight += spacing

src/com/reco1l/andengine/theme/Units.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ val Int.srem: Float
4545

4646
/**
4747
* Indicates that this float value is in percentage units.
48-
* It will be converted to a value between -4 and -3.
48+
* It will be converted to a value between -3 and -2.
4949
*/
5050
val Float.pct: Float
5151
get() = Size.relativeSizeRange.start + this.coerceAtLeast(0f).coerceAtMost(1f)

src/com/reco1l/andengine/ui/UIDropdown.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class UIDropdown(var trigger: UIComponent) : UIScrollableContainer() {
6767
scaleY = 0f
6868

6969
optionsContainer = linearContainer {
70+
width = Size.Full
7071
orientation = Orientation.Vertical
7172
shrink = false
7273
style = {
@@ -82,10 +83,24 @@ class UIDropdown(var trigger: UIComponent) : UIScrollableContainer() {
8283

8384
if (isExpanded) {
8485
val (sceneSpaceX, sceneSpaceY) = trigger.convertLocalToSceneCoordinates(0f, trigger.height)
86+
val (_, triggerTopY) = trigger.convertLocalToSceneCoordinates(0f, 0f)
87+
88+
val spaceBelow = parent.height - sceneSpaceY
89+
val expandUpwards = triggerTopY > spaceBelow && spaceBelow < optionsContainer.height
8590

8691
x = sceneSpaceX
87-
y = sceneSpaceY
88-
maxHeight = min(optionsContainer.height, parent.height - sceneSpaceY)
92+
93+
if (expandUpwards) {
94+
y = triggerTopY - min(optionsContainer.height, triggerTopY)
95+
scaleCenter = Anchor.BottomCenter
96+
maxHeight = min(optionsContainer.height, triggerTopY)
97+
} else {
98+
y = sceneSpaceY
99+
scaleCenter = Anchor.TopCenter
100+
maxHeight = min(optionsContainer.height, spaceBelow)
101+
}
102+
103+
minWidth = trigger.width
89104
}
90105

91106
super.onManagedDraw(gl, camera)

0 commit comments

Comments
 (0)