Skip to content

feat(ui): add resolution-aware scaling to main menu layout#23

Open
Alexbeav wants to merge 6 commits intoalariq:masterfrom
Alexbeav:ui-scaling
Open

feat(ui): add resolution-aware scaling to main menu layout#23
Alexbeav wants to merge 6 commits intoalariq:masterfrom
Alexbeav:ui-scaling

Conversation

@Alexbeav
Copy link

@Alexbeav Alexbeav commented Apr 4, 2025

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.

Alexbeav added 2 commits April 5, 2025 00:42
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
@Alexbeav
Copy link
Author

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!

Copy link
Author

@Alexbeav Alexbeav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your proposed changes. Do you want to conclude the review and merge this PR?

Cheers!

@alariq
Copy link
Owner

alariq commented Jun 30, 2025

no problem, but I do not see updated PR

@Alexbeav
Copy link
Author

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!

Alexbeav and others added 3 commits July 15, 2025 15:23
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)
Copilot AI review requested due to automatic review settings September 11, 2025 16:51
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +781 to +788
// 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) {
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +808 to +811
float textScale = cachedFontScale;
if (textWidth * textScale > maxWidth) {
textScale = maxWidth / (float)textWidth;
}
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero could occur if textWidth is 0. Add a check to ensure textWidth is greater than 0 before performing the division.

Suggested change
float textScale = cachedFontScale;
if (textWidth * textScale > maxWidth) {
textScale = maxWidth / (float)textWidth;
}
float textScale = cachedFontScale;
if (textWidth > 0 && textWidth * textScale > maxWidth) {
textScale = maxWidth / (float)textWidth;
}

Copilot uses AI. Check for mistakes.
Copy link
Author

@Alexbeav Alexbeav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented your comments @alariq

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants