Improve canvas resize handling (partial fix for #88 and #59)#111
Open
itsthisjustin wants to merge 3 commits intoDavidobot:masterfrom
Open
Improve canvas resize handling (partial fix for #88 and #59)#111itsthisjustin wants to merge 3 commits intoDavidobot:masterfrom
itsthisjustin wants to merge 3 commits intoDavidobot:masterfrom
Conversation
This commit adds partial support for canvas resizing in response to browser window size changes, addressing issues Davidobot#88 and Davidobot#59. ## Changes: **JavaScript (index.html):** - Added resizeCanvas() function that monitors canvas size changes - Updates canvas element dimensions when browser window resizes - Triggers SDL resize events to notify the engine - Handles window resize, fullscreen changes, and periodic checks **CSS (love.css):** - Made canvas responsive with max-width: 100% and max-height: 100vh - Maintains aspect ratio while adapting to window size **Documentation (readme.md):** - Added comprehensive note about canvas resizing (Note Davidobot#9) - Clearly documents current limitations - Explains that game viewport doesn't scale (engine limitation) - References upstream issues Davidobot#88 and Davidobot#59 ## What This Fixes: ✅ Canvas element no longer cuts off when window resizes ✅ Better responsive behavior for different screen sizes ✅ Improved fullscreen handling ## Known Limitations: - Game content renders at size specified in conf.lua - Canvas resizes but game viewport doesn't scale to fill it - love.window.setMode() from game code still won't work - love.resize() callback may not be triggered These limitations would require engine-level changes to SDL/Emscripten integration to fully resolve. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Fixed goFullScreen() to use correct API method names (requestFullscreen vs requestFullScreen) - Added mobile device detection to use CSS-based fullscreen on mobile (more reliable than Fullscreen API) - Auto-fullscreen on mobile devices when game finishes loading - Desktop browsers continue to use native Fullscreen API - Updated all HTML templates (release, compat, sample) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Made all UI elements (header, footer, canvas, loading screen) fully responsive - Added CSS media queries for mobile devices (768px and 480px breakpoints) - Fixed desktop fullscreen to hide header via CSS :fullscreen pseudo-class - Fixed mobile fullscreen to properly fill 100vh by: - Setting actual canvas buffer dimensions to window.innerWidth/innerHeight - Removing all CSS max-width/max-height constraints (set to 'none') - Hiding footer and header elements - Setting body background to black to prevent color bleed-through - Loading screen now scales dynamically based on container width - Footer is now fixed at bottom and centered on all devices 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Author
Additional Changes - Mobile Responsive DesignAdded comprehensive mobile responsive design and fullscreen improvements: Mobile Responsiveness
Fullscreen ImprovementsDesktop:
Mobile:
These changes ensure a seamless fullscreen experience across all devices while maintaining proper mobile responsiveness when not in fullscreen mode. |
9832b3b to
c76c5f5
Compare
Author
|
Sorry did not mean to push that mobile keyboard support thing. Stupid claude was way too eager there. I've reverted it. |
Author
|
Also if anyone wants to test how this works, I've built my game with it at https://playknave.com (try opening this on your phone) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds partial support for canvas resizing in response to browser window size changes, addressing the limitations described in issues #88 and #59.
Changes Made
JavaScript (index.html - both release and compat)
resizeCanvas()function that monitors and responds to canvas size changesCSS (love.css - both release and compat)
max-width: 100%andmax-height: 100vhDocumentation (readme.md)
What This Fixes
✅ Canvas element no longer cuts off content when window resizes
✅ Better responsive behavior for different screen sizes
✅ Improved fullscreen handling
✅ Canvas adapts to browser window size changes
Known Limitations
This is a partial fix that improves the current behavior but doesn't fully resolve the underlying limitation:
conf.lua(e.g., 1280x720)love.window.setMode()from game code still won't dynamically resize the canvaslove.resize()callback may not be triggered on canvas size changesThese remaining limitations exist because SDL/Emscripten in the current LÖVE build doesn't properly handle dynamic canvas resizing without deeper engine-level modifications.
Why This Approach?
A complete fix would require:
emscripten_set_canvas_element_size()calls to the window moduleThis PR provides immediate value by fixing the "content cutoff" issue while being honest about what still needs engine-level work.
Testing
Tested with a production game (Knave) deployed to Cloudflare Pages. The canvas now properly resizes with the browser window instead of cutting off content.
Backwards Compatibility
✅ Fully backwards compatible - existing games will work exactly as before, but will now handle window resizing better.
Related Issues
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com