Implement onViewportResized Handler
Description
There is currently no way, without polling, for a user to listen for viewport resize/game window resize changes in Lua. This MR addes an onViewportResized engine handler to menu and player scripts. The callback provides the new width and height as separate parameters.
The most prominent use case for this is user-scaling UIs, snapping their own UIs to the window, re-positioning their UI, or resizing their UI for responsiveness. This is part of a set of changes to provide a better user experience with the OpenMW Lua UI API.
Additionally, the docs have been updated to reflect this new engine handler.
The newer engine handlers and events have opted to use a past tense verbiage for naming, and I believe this is fitting because this signifies the resize has already happened. If this is disagreeable, I'll make the change to present tense.
Checklist
- I have read the CONTRIBUTING guidelines
- My code builds and runs locally
- I have included steps to replicate/confirm the changes below
- I have attached necessary supporting files or assets
Steps to Test/Replicate
Add the following Lua code to a menu or player script, then resize the viewport:
return {
engineHandlers = {
onViewportResized = function(width, height)
print("Viewport resized to: " .. width .. "x" .. height);
end
}
}