1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-27 15:57:02 +00:00

Fix some ways to create inconsistent Viewport sizes

In the editor, it was possible to set the size of a `SubViewport` even
in cases where a parent `SubViewportContainer` had stretch enabled.

This PR disables editing a `SubViewport.size` while the parent disallows
it and it makes necessary adjustments during `NOTIFICATION_ENTER_TREE`.
This commit is contained in:
Markus Sauermann
2023-02-13 00:34:16 +01:00
parent 72c5b56d04
commit 34a7fc7447
4 changed files with 26 additions and 14 deletions

View File

@@ -4263,6 +4263,11 @@ void SubViewport::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
SubViewportContainer *parent_svc = Object::cast_to<SubViewportContainer>(get_parent());
if (parent_svc) {
parent_svc->recalc_force_viewport_sizes();
}
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -4305,6 +4310,17 @@ void SubViewport::_bind_methods() {
BIND_ENUM_CONSTANT(UPDATE_ALWAYS);
}
void SubViewport::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "size") {
SubViewportContainer *parent_svc = Object::cast_to<SubViewportContainer>(get_parent());
if (parent_svc && parent_svc->is_stretch_enabled()) {
p_property.usage = PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY;
} else {
p_property.usage = PROPERTY_USAGE_DEFAULT;
}
}
}
SubViewport::SubViewport() {
RS::get_singleton()->viewport_set_size(get_viewport_rid(), get_size().width, get_size().height);
}