Make stretch_shrink
(in SubViewportContainer) work in both ways: shrink and expand
#7288
Labels
stretch_shrink
(in SubViewportContainer) work in both ways: shrink and expand
#7288
Describe the project you are working on
Currently porting my 3.5 game to 4.1, faced the issue of viewport scaling
Describe the problem or limitation you are having in your project
Godot's 3.5 viewport scaling doesn't work in Godot 4.X because of changed viewport structure
In SubViewportContainer, there's a variable
stretch_shrink
, which makes viewport scale smaller if you set a bigger int. It's not possible to make viewport scale bigger with this variable, because you can't set the value smaller than the default 1 (otherwise throws an error:scene/gui/subviewport_container.cpp:72 - Condition "p_shrink < 1" is true.
), therefore this scaling feature works only in one way, but for me the viewport scale is required to be able to both expand and shrinkDescribe the feature / enhancement and how it helps to overcome the problem or limitation
Just a few changes in the initial code, just make it recieve any positive float value and set the viewport scale in percent
I think it should work with these changes:
1. Source link
2. Source link
3. Source link
c->set_size_force(get_size() / shrink);
c->set_size_force(get_size() * scale);
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
For example:
0.15 value = 15% viewport scale
1.0 value = 100% viewport scale
3.1 value = 310% viewport scale
If this enhancement will not be used often, can it be worked around with a few lines of script?
I haven't found a way yet, I was trying to make the official method work in Godot 4.X by fixing errors and trying slightly different approaches (even changing the order of nodes changes the result for some reason), but the result wasn't unequivocal, it was broken in different ways (for example, it scales in a bigger way, but when scaled back it changed the viewport size on the screen, not scale)
So I think it's technically possible to implement in Godot 4.X in some way, but I'm sure it won't be made in just a few lines of script
Is there a reason why this should be core and not an add-on in the asset library?
For much easier way of scaling the viewport on runtime with only one variable responsible for that
The text was updated successfully, but these errors were encountered: