feat(ui): add resolution-aware scaling to main menu layout#23
feat(ui): add resolution-aware scaling to main menu layout#23Alexbeav wants to merge 6 commits intoalariq:masterfrom
Conversation
Implemented dynamic scaling logic in MainMenu::render() to make the main menu UI adapt to various screen resolutions. Scaling factors are now calculated based on a 1024x768 baseline, with optional caps for layout and font scaling. This improves usability at 1080p, 1440p, and 4K without breaking existing layout behavior.
- Manually center and scale copyright text based on resolution - Prevent duplicate rendering by disabling default GUI window draw - Ensures proper alignment at all resolutions, including 4K
|
Thank you for your feedback! I'm not an experienced coder and I'm trying to help out however I can. I'll apply your suggestions and reupload! |
Alexbeav
left a comment
There was a problem hiding this comment.
I agree with your proposed changes. Do you want to conclude the review and merge this PR?
Cheers!
|
no problem, but I do not see updated PR |
|
Hey @alariq, sorry for the delay it's been crazy here! I've applied your suggestions and pushed the changes. Let me know if there's anything else you'd like me to adjust. Thanks again! |
Reapplied and improved the main menu scaling implementation: Key enhancements: - Cached scaling calculations for performance (only recalculate on resolution change) - Added scaling limits (0.5x to 3.0x) to prevent extreme scaling - Improved copyright text centering with width constraints - Comprehensive documentation and comments - Baseline resolution: 1024x768 with support for 800x600 to 4K+ Technical improvements: - Separate X/Y scaling for layout flexibility - Uniform font scaling for readability - Responsive text scaling with screen width constraints - Static variable caching to avoid per-frame calculations Addresses main menu UI scaling issues at 1080p, 1440p, and 4K resolutions while maintaining backward compatibility with original 800x600 behavior. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Added comprehensive development log tracking changes and obstacles - Updated .gitignore to exclude: - 3rdparty/ (temporary build dependencies) - full_game/ (game files, not source) - mc2.dir/ and x64/ (build output directories)
There was a problem hiding this comment.
Pull Request Overview
This PR implements dynamic UI scaling for the main menu to adapt to various screen resolutions, enhancing usability at higher resolutions like 1080p, 1440p, and 4K while maintaining backward compatibility. The scaling system uses a 1024x768 baseline with configurable limits and performance optimizations.
- Enhanced the main menu rendering with resolution-aware scaling for copyright text
- Added static caching to avoid recalculating scale factors on every frame
- Implemented scaling limits and width constraints to prevent extreme scaling
- Includes comprehensive code formatting improvements throughout the file
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| devlog.md | Documents the UI scaling implementation process and PR review changes |
| code/mainmenu.cpp | Implements the core UI scaling functionality with enhanced copyright text rendering and extensive code formatting cleanup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // Enhanced copyright text rendering with resolution-aware scaling | ||
| const char* text = textObjects[1].text; | ||
| int textWidth = textObjects[1].font.width(text); | ||
| int centerX = Environment.screenWidth / 2; | ||
| int bottomY = Environment.screenHeight - 24; // Distance from bottom | ||
|
|
||
| // Only recalculate font scale when resolution changes | ||
| if (Environment.screenWidth != lastScreenWidth || Environment.screenHeight != lastScreenHeight) { |
There was a problem hiding this comment.
The font scaling calculation is performed inside the render() method, which is called every frame. Consider moving the scale factor calculation to a dedicated method that's only called when the resolution actually changes, or use a resolution change callback instead of checking every frame.
| float textScale = cachedFontScale; | ||
| if (textWidth * textScale > maxWidth) { | ||
| textScale = maxWidth / (float)textWidth; | ||
| } |
There was a problem hiding this comment.
Division by zero could occur if textWidth is 0. Add a check to ensure textWidth is greater than 0 before performing the division.
| float textScale = cachedFontScale; | |
| if (textWidth * textScale > maxWidth) { | |
| textScale = maxWidth / (float)textWidth; | |
| } | |
| float textScale = cachedFontScale; | |
| if (textWidth > 0 && textWidth * textScale > maxWidth) { | |
| textScale = maxWidth / (float)textWidth; | |
| } |
Implemented dynamic scaling logic in MainMenu::render() to make the main menu UI adapt to various screen resolutions. Scaling factors are now calculated based on a 1024x768 baseline, with optional caps for layout and font scaling. This improves usability at 1080p, 1440p, and 4K without breaking existing layout behavior.