Refreshing Control Node When Window Size Changed

Godot Version

Godot 4.6

Question

I’m making a game in Godot where the size of the window changes when controlled in the settings. The issue is that the size and positioning of the containers does not change until the window is moved manually. How do I refresh the window to cause this change in code?

extends HBoxContainer

const hoveredScale = 0.45;
const unhoveredScale = 0.4;
const hoverChangeTime = 0.08;

var windowSizePresets = [Vector2i(3840, 2160), Vector2i(2560, 1440), Vector2i(1920, 1080), Vector2i(1280, 720), Vector2i(854, 480)];

func _on_settings_mouse_entered() -> void:
	var hoveredTween = get_tree().create_tween().set_trans(Tween.TRANS_BOUNCE);
	
	hoveredTween.tween_property(self, "scale", Vector2.ONE*hoveredScale, hoverChangeTime);

func _on_settings_mouse_exited() -> void:
	var unhoveredTween = get_tree().create_tween().set_trans(Tween.TRANS_BOUNCE);
	
	unhoveredTween.tween_property(self, "scale", Vector2.ONE*unhoveredScale, hoverChangeTime);

func _on_settings_button_button_up() -> void:
	%"Settings Background".visible = !%"Settings Background".visible;

func _on_window_size_button_item_selected(index: int) -> void:
	DisplayServer.window_set_size(windowSizePresets[index]);

Try using size_changed()

I’m sorry, I’m new to godot, how do I emit this in code?

I am a very novice programmer. At that time, I was solving a slightly different problem and remembered that I had used such a signal. Perhaps the documentation will help.

Yes, that makes sense, but I need to know what to do to make the Containers refresh, not just when to do it

In my demo, which I linked to, it is not containers that are updated, but vector images. It may be similar in principle. But I’m not sure — you have to try it.

I’m sorry, it didn’t work. I’ll wait until someone else has a solution.

Can you publish the MVP?

Like build or the godot project?

Of course.

I’ll take a look, but I don’t think I’ll be able to respond very quickly. When sharing the project, there’s no need to add the .godot folder — it’s created when the project is opened.

1 Like

You’re going to laugh. The window updates fine for me.

save-betta_2

I’m not going to laugh, I will instead celebrate. This is excellent.

Try deleting the .godot folder. Sometimes this helps with strange problems.

It’s a display issue with X11 I think

1 Like