+2 votes

As the title says. I want to be able to resize the window, but only to a certain minimum. I know you can set resizable on/off, but what about this?

in Engine by (45 points)

1 Answer

+3 votes
Best answer

As of version 3.2 from this commit onward methods have been added to clamp the window min and max sizes, which would be the best answer to this.

From mrtnfchs comment below, the methods are the following:

OS.min_window_size = Vector2(min_x, min_y)
OS.max_window_size = Vector2(max_x, max_y)


In older versions a less than ideal way of accomplishing it would be to clamp the dimensions based on when the root viewport is being resized. (It is hacky and some flickering occurs.)

Relies on this method to manually update to the new sizes: http://docs.godotengine.org/en/latest/classes/class_os.html#class-os-set-window-size

var minX = 300
var minY = 300

func _ready():
    get_node("/root").connect("size_changed", self, "resize")

func resize():
    var currentSize = OS.get_window_size()

    if(currentSize.x < minX):
        OS.set_window_size(Vector2(minX, currentSize.y))

    if(currentSize.y < minY):
        OS.set_window_size(Vector2(currentSize.x, minY))
by (5,242 points)
edited by

Incidentally I actually did try to implement this mode, but I decided it looked bad enough to not justify it and just made the window non-resizable. Thanks anyway!

You're welcome.

Yeah it's certainly not pretty. From what I can tell it wasn't an intentional behavior. I couldn't find anything in their OS code on the windows side that exposes any functionality into GD Script for it.

There does exist in windows API such functionality.


You would have to compile your own module or modify the source and create a new method in the OS interface and implement it, which is probably far more work than settling with something like a modal window.

Use OS.min_window_size = Vector2(minx,miny) and OS.max_window_size = Vector2(maxx,maxy)

Thank you mrtnfchs. Your comment should be an answer so that I could mark it as "Best Answer".

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.