From de0d991018cf91163c1a4bfd8c9cb1ac93d7f094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 27 May 2019 00:19:50 +0200 Subject: [PATCH] Platform: add EmscriptenApplication::setContainerCssClass(). --- doc/platforms-html5.dox | 3 ++- src/Magnum/Platform/EmscriptenApplication.cpp | 7 +++++++ src/Magnum/Platform/EmscriptenApplication.h | 12 ++++++++++++ .../Platform/Test/EmscriptenApplicationTest.cpp | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/platforms-html5.dox b/doc/platforms-html5.dox index 56520dfab..c52ef830c 100644 --- a/doc/platforms-html5.dox +++ b/doc/platforms-html5.dox @@ -329,7 +329,8 @@ the @cb{.css} div#sizer @ce will center it, following the canvas width. If you need more advanced styling, check out [m.css](http://mcss.mosra.cz). @note It's also possible to modify the container CSS classes from the C++ side - using @ref Platform::Sdl2Application::setContainerCssClass(). + using @ref Platform::EmscriptenApplication::setContainerCssClass() / + @ref Platform::Sdl2Application::setContainerCssClass(). @section platforms-html5-events Controlling event behavior diff --git a/src/Magnum/Platform/EmscriptenApplication.cpp b/src/Magnum/Platform/EmscriptenApplication.cpp index def76f07b..c1c839350 100644 --- a/src/Magnum/Platform/EmscriptenApplication.cpp +++ b/src/Magnum/Platform/EmscriptenApplication.cpp @@ -382,6 +382,13 @@ Vector2i EmscriptenApplication::framebufferSize() const { } #endif +void EmscriptenApplication::setContainerCssClass(const std::string& cssClass) { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" + EM_ASM_({document.getElementById('container').className = AsciiToString($0);}, cssClass.data()); + #pragma GCC diagnostic pop +} + void EmscriptenApplication::swapBuffers() { emscripten_webgl_commit_frame(); } diff --git a/src/Magnum/Platform/EmscriptenApplication.h b/src/Magnum/Platform/EmscriptenApplication.h index 91a74fb32..67da4dd57 100644 --- a/src/Magnum/Platform/EmscriptenApplication.h +++ b/src/Magnum/Platform/EmscriptenApplication.h @@ -447,6 +447,18 @@ class EmscriptenApplication { */ Vector2 devicePixelRatio() const { return _devicePixelRatio; } + /** + * @brief Set container CSS class + * + * Assigns given CSS class to the @cb{.html}
@ce. + * Useful for example to change aspect ratio of the view or stretch it + * to cover the full page. See @ref platforms-html5-layout for more + * information about possible values. Note that this replaces any + * existing class, to set multiple classes separate them with + * whitespace. + */ + void setContainerCssClass(const std::string& cssClass); + /** * @brief Swap buffers * diff --git a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp index f442a8c4b..8a4033cf2 100644 --- a/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp +++ b/src/Magnum/Platform/Test/EmscriptenApplicationTest.cpp @@ -99,6 +99,9 @@ struct EmscriptenApplicationTest: Platform::Application { } else if(event.key() == KeyEvent::Key::Esc) { Debug{} << "stopping text input"; stopTextInput(); + } else if(event.key() == KeyEvent::Key::F) { + Debug{} << "toggling fullscreen"; + setContainerCssClass((_fullscreen ^= true) ? "fullsize" : ""); } event.setAccepted(); @@ -125,6 +128,8 @@ struct EmscriptenApplicationTest: Platform::Application { event.setAccepted(); } + private: + bool _fullscreen = false; }; }}}