Skip to content

Commit 1042cf7

Browse files
authored
Fix centering calculations using scaledWidth and scaledHeight (#2341)
* Fix centering calculations using scaledHeight * Fix centerXBetween to use scaledWidth instead of height
1 parent 772b4df commit 1042cf7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

korge/src/korlibs/korge/view/align/ViewAlignExt.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import korlibs.korge.view.*
55

66
/** Chainable method returning this that sets [this] View in the middle between [x1] and [x2] */
77
fun <T : View> T.centerXBetween(x1: Double, x2: Double): T {
8-
this.x = (x2 + x1 - this.width) / 2
8+
this.x = (x2 + x1 - this.scaledWidth) / 2
99
return this
1010
}
1111
fun <T : View> T.centerXBetween(x1: Float, x2: Float): T = centerXBetween(x1.toDouble(), x2.toDouble())
1212
fun <T : View> T.centerXBetween(x1: Int, x2: Int): T = centerXBetween(x1.toDouble(), x2.toDouble())
1313

1414
/** Chainable method returning this that sets [this] View in the middle between [y1] and [y2] */
1515
fun <T : View> T.centerYBetween(y1: Double, y2: Double): T {
16-
this.y = (y2 + y1 - this.height) / 2
16+
this.y = (y2 + y1 - this.scaledHeight) / 2
1717
return this
1818
}
1919
fun <T : View> T.centerYBetween(y1: Float, y2: Float): T = centerYBetween(y1.toDouble(), y2.toDouble())

0 commit comments

Comments
 (0)