Merge pull request #68406 from zaevi/fix_web_auto_resize

Fix viewport doesn't auto-resize on Web.
This commit is contained in:
Rémi Verschelde 2022-11-08 17:46:57 +01:00 committed by GitHub
commit 60e25835a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -54,7 +54,15 @@ DisplayServerWeb *DisplayServerWeb::get_singleton() {
// Window (canvas)
bool DisplayServerWeb::check_size_force_redraw() {
return godot_js_display_size_update() != 0;
bool size_changed = godot_js_display_size_update() != 0;
if (size_changed && !rect_changed_callback.is_null()) {
Variant size = Rect2i(Point2i(), window_get_size()); // TODO use window_get_position if implemented.
Variant *vp = &size;
Variant ret;
Callable::CallError ce;
rect_changed_callback.callp((const Variant **)&vp, 1, ret, ce);
}
return size_changed;
}
void DisplayServerWeb::fullscreen_change_callback(int p_fullscreen) {
@ -903,7 +911,7 @@ ObjectID DisplayServerWeb::window_get_attached_instance_id(WindowID p_window) co
}
void DisplayServerWeb::window_set_rect_changed_callback(const Callable &p_callable, WindowID p_window) {
// Not supported.
rect_changed_callback = p_callable;
}
void DisplayServerWeb::window_set_window_event_callback(const Callable &p_callable, WindowID p_window) {

View File

@ -60,6 +60,7 @@ private:
WindowMode window_mode = WINDOW_MODE_WINDOWED;
ObjectID window_attached_instance_id = {};
Callable rect_changed_callback;
Callable window_event_callback;
Callable input_event_callback;
Callable input_text_callback;