Changing the `.scale` of most views does not affec...
# korge
j
Changing the
.scale
of most views does not affect the output of
getBounds()
(SolidRect for example). But changing the
.scale
of
Text
views does (slightly) -- is that expected?
Barebones repro:
Copy code
class TestScene : Scene() {
    override suspend fun Container.sceneInit() {
        val left = 200
        val right = 700
        solidRect(5, 300) {
            xy( left - 5, 100)
        }
        solidRect(5, 300) {
            xy( right, 100)
        }

        val redBox = solidRect(100, 100, Colors.RED) {
            xy(500, 500)
        }

        val text = text("This is a Message") {
            xy(left, 200)
            fontSize = 32.0
        }
        println("redBox")
        println("bounds = ${redBox.getBounds()}")
        redBox.scale = 0.2
        println("==0.2==")
        println("bounds = ${redBox.getBounds()}")
        redBox.scale = 2.0
        println("==2.0==")
        println("bounds = ${redBox.getBounds()}")
        redBox.scale = 1.0
        println("==1.0==")
        println("bounds = ${redBox.getBounds()}")

        println("=default==")
        println("bounds = ${text.getBounds()}")
        text.scale = 0.2
        println("==0.2==")
        println("bounds = ${text.getBounds()}")
        text.scale = 2.0
        println("==2.0==")
        println("bounds = ${text.getBounds()}")
        text.scale = 1.0
        println("==1.0==")
        println("bounds = ${text.getBounds()}")

        val desiredWidth = right - left
        keys {
            down(<http://Key.SPACE|Key.SPACE>) {
                text.text = "word".repeat(Random.nextInt(1, 15))
                val actualWidth = text.getBounds().width
                text.scale =  desiredWidth / actualWidth
            }
        }
    }
d
How much is slightly?
j
Copy code
redBox
bounds = Rectangle(x=0, y=0, width=100, height=100)
==0.2==
bounds = Rectangle(x=0, y=0, width=100, height=100)
==2.0==
bounds = Rectangle(x=0, y=0, width=100, height=100)
==1.0==
bounds = Rectangle(x=0, y=0, width=100, height=100)
=default==
bounds = Rectangle(x=0.7486979166666667, y=0, width=233.7391304347826, height=31.304347826086957)
==0.2==
bounds = Rectangle(x=0.14973958333333334, y=0, width=250.43478260869566, height=41.73913043478261)
==2.0==
bounds = Rectangle(x=1.4973958333333335, y=0, width=231.65217391304347, height=29.217391304347824)
==1.0==
bounds = Rectangle(x=0.7486979166666667, y=0, width=233.7391304347826, height=31.304347826086957)
d
I have to check what do other game libraries. But I guess it should be consistent between views
And that change is not small,
ahh I think I know what could be happening
if you use textOld that doesn't happen right?
j
is it due to like glyph padding or something?
let me try
d
I think it is because text by default scales its content so the text looks vectorial and is sharp
j
correct, does not happen with textOld:
Copy code
redBox
bounds = Rectangle(x=0, y=0, width=100, height=100)
==0.2==
bounds = Rectangle(x=0, y=0, width=100, height=100)
==2.0==
bounds = Rectangle(x=0, y=0, width=100, height=100)
==1.0==
bounds = Rectangle(x=0, y=0, width=100, height=100)
=default==
bounds = Rectangle(x=0, y=0, width=238, height=16)
==0.2==
bounds = Rectangle(x=0, y=0, width=238, height=16)
==2.0==
bounds = Rectangle(x=0, y=0, width=238, height=16)
==1.0==
bounds = Rectangle(x=0, y=0, width=238, height=16)
d
if you are not using a bitmap font, it should render stuff to a texture, and it computes the global scale to decide at which resolution the text is going to be rendererd
can you try to set autoScaling to false?
j
yep! I believe I'm using the default font rn
aha, autoscaling = false also does not change the bounds:
Copy code
=default==
bounds = Rectangle(x=1.5625, y=0, width=232, height=30)
==0.2==
bounds = Rectangle(x=1.5625, y=0, width=232, height=30)
==2.0==
bounds = Rectangle(x=1.5625, y=0, width=232, height=30)
==1.0==
bounds = Rectangle(x=1.5625, y=0, width=232, height=30)
and switching to autoScaling = false in my actual project also fixed the bug. Thanks!
👍 1
d
Can you open an issues with this problem at github, so we don't forget about it? I think we should keep the bounds consisent
j
Will do! Thanks for your help.
d
Thanks to you!