From 3dbbe60376e4f6055bfc11e28b069f61ab37525c Mon Sep 17 00:00:00 2001 From: Asdqwe Date: Sun, 20 Oct 2024 19:29:32 -0300 Subject: [PATCH] Adds MaximizeWindow() and RestoreWindow() implementation for PLATFORM_WEB (#4397) --- src/platforms/rcore_web.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/platforms/rcore_web.c b/src/platforms/rcore_web.c index 35c15a6b..73513d8e 100644 --- a/src/platforms/rcore_web.c +++ b/src/platforms/rcore_web.c @@ -74,6 +74,8 @@ typedef struct { GLFWwindow *handle; // GLFW window handle (graphic device) bool ourFullscreen; // Internal var to filter our handling of fullscreen vs the user handling of fullscreen + int unmaximizedWidth; // Internal var to store the unmaximized window (canvas) width + int unmaximizedHeight; // Internal var to store the unmaximized window (canvas) height } PlatformData; //---------------------------------------------------------------------------------- @@ -317,7 +319,16 @@ void ToggleBorderlessWindowed(void) // Set window state: maximized, if resizable void MaximizeWindow(void) { - TRACELOG(LOG_WARNING, "MaximizeWindow() not available on target platform"); + if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) + { + platform.unmaximizedWidth = CORE.Window.screen.width; + platform.unmaximizedHeight = CORE.Window.screen.height; + + const int tabWidth = EM_ASM_INT( { return window.innerWidth; }, 0); + const int tabHeight = EM_ASM_INT( { return window.innerHeight; }, 0); + + if (tabWidth && tabHeight) glfwSetWindowSize(platform.handle, tabWidth, tabHeight); + } } // Set window state: minimized @@ -329,7 +340,10 @@ void MinimizeWindow(void) // Set window state: not minimized/maximized void RestoreWindow(void) { - TRACELOG(LOG_WARNING, "RestoreWindow() not available on target platform"); + if (glfwGetWindowAttrib(platform.handle, GLFW_RESIZABLE) == GLFW_TRUE) + { + if (platform.unmaximizedWidth && platform.unmaximizedHeight) glfwSetWindowSize(platform.handle, platform.unmaximizedWidth, platform.unmaximizedHeight); + } } // Set window configuration state using flags