fix: make FanCurveControl DPI-aware - #31
Conversation
Convert hardcoded constants (PointRadius, margins) to scale with DeviceDpi for proper high-DPI display support.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Caution Review failedPull request was closed or merged during review WalkthroughReplaced five fixed pixel constants in FanCurveControl.cs with dynamic properties that scale values using Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 file)
Reviewed by trinity-large-thinking · 139,950 tokens |
There was a problem hiding this comment.
Code Review
This pull request introduces DPI scaling for the fan curve control's margins and point radius by replacing static constants with dynamic properties. The review feedback suggests using the built-in LogicalToDeviceUnits method for more efficient and accurate scaling, and recommends extending this scaling to other hardcoded pixel values throughout the file.
| private int PointRadius => (int)(6 * (DeviceDpi / 96f)); | ||
| private int MarginLeft => (int)(40 * (DeviceDpi / 96f)); | ||
| private int MarginBottom => (int)(30 * (DeviceDpi / 96f)); | ||
| private int MarginRight => (int)(20 * (DeviceDpi / 96f)); | ||
| private int MarginTop => (int)(20 * (DeviceDpi / 96f)); |
There was a problem hiding this comment.
The current implementation recalculates the scaled values every time these properties are accessed. Since they are used frequently within OnPaint (including inside loops) and event handlers, this introduces redundant floating-point calculations. Additionally, casting to int truncates the result, which can lead to slight rendering inaccuracies compared to rounding.
A more efficient and idiomatic approach in Windows Forms (available since .NET Framework 4.7) is to use the built-in LogicalToDeviceUnits method. This method handles the scaling logic and rounding correctly.
Also, note that to achieve full DPI awareness, you should consider applying similar scaling to other hardcoded pixel values in the file, such as pen widths (e.g., line 101) and text offsets (e.g., lines 88, 93, 131).
private int PointRadius => LogicalToDeviceUnits(6);
private int MarginLeft => LogicalToDeviceUnits(40);
private int MarginBottom => LogicalToDeviceUnits(30);
private int MarginRight => LogicalToDeviceUnits(20);
private int MarginTop => LogicalToDeviceUnits(20);
Summary
Summary by CodeRabbit