bitwes / Gut

Godot Unit Test. Unit testing tool for Godot Game Engine.
1.81k stars 100 forks source link

On small resolutions the runner takes more space than available #657

Open Edearth opened 2 weeks ago

Edearth commented 2 weeks ago

Versions

The Bug

On small resolutions the runner takes more space than available in the screen. As a result, it appears cropped like this: image

I'm working on a game with a resolution of 384x216. I would expect the window gets resized correctly and I can see all of it. Like this: image

Steps To Reproduce

  1. In Godot, create a new project and a test
  2. In Godot, open Project > Project Settings > Display > Window
  3. Set Viewport Width to 384 and Viewport Height to 216.
  4. (Optionally, in GUT's settings, make sure Exit on Finish and Exit on Success are disabled)
bitwes commented 2 weeks ago

I could probably decrease custom_minimum_size.x on the normal gui (or add the min size logic from the script below). That doesn't really help you out that much though, since it would still be off screen. Maybe exposing the NormalGui and CompactGui nodes to GutHookScript would be the most versatile approach. This would allow you to do whatever you wanted to the gui nodes in a pre-hook script.

Here's a pre-run hook script that accesses some "private" variables to get to the normal gui and then alter it to fit on the screen. Try this out, and let me know if it solves the issue for you. If so, then making it easier to get to these gui nodes in a hook script is probably the best approach.

I usually put my hook scripts in res://test/resources. You need to add this in your .gutconfig and/or configure it in the editor as the pre-hook script.

image
extends GutHookScript

func run():
    var runner = gut.get_node("/root/GutRunner")
    var win_size = gut.get_viewport().get_visible_rect().size
    var norm_gui = runner._gui._normal_gui
    var min_size = Vector2(
        min(win_size.x, norm_gui.custom_minimum_size.x),
        min(win_size.y, norm_gui.custom_minimum_size.y)
    )
    norm_gui.custom_minimum_size = min_size
    norm_gui.size = min_size
    norm_gui.align_right()
bitwes commented 2 weeks ago

Or maybe I should just add that minimum size logic to _ready in the normal GUI.

Edearth commented 2 weeks ago

Oh, I hadn't even seen the hooks section in the documentation 🤦 I'm so sorry! I'll close the PR That worked like a charm, thank you so much!

If so, then making it easier to get to these gui nodes in a hook script is probably the best approach.

I completely agree! Do you have an idea of how do you want it to look like?

It might be a bad idea, but maybe there could be a singleton that stores references to the current runner and its GUI nodes?