Skip to content

Commit

Permalink
Fix viewport doesn't auto-resize on Web.
Browse files Browse the repository at this point in the history
  • Loading branch information
zaevi committed Nov 8, 2022
1 parent 40ed34f commit bc9bf00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions platform/web/display_server_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions platform/web/display_server_web.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class DisplayServerWeb : public DisplayServer {
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;
Expand Down

0 comments on commit bc9bf00

Please sign in to comment.