Add bonsplitUIScale environment key for UI scaling#24
Add bonsplitUIScale environment key for UI scaling#24DreaminDani wants to merge 1 commit intomanaflow-ai:mainfrom
Conversation
Allows host apps to inject a scale factor that Bonsplit tab bar views use to multiply font sizes, enabling configurable UI scaling. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis pull request introduces a UI scale environment mechanism for Bonsplit SwiftUI views. A new environment key with a default scale of 1.0 is added, allowing host applications to inject custom scaling factors that automatically scale font and icon sizes across TabBarView, TabDragPreview, and TabItemView. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 Tip CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required. |
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="Sources/Bonsplit/Internal/Views/TabItemView.swift">
<violation number="1" location="Sources/Bonsplit/Internal/Views/TabItemView.swift:238">
P2: Scaled shortcut hint text uses an unscaled width measurement, so larger `bonsplitUIScale` values can clip the hint label.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| if let shortcutHintLabel { | ||
| Text(shortcutHintLabel) | ||
| .font(.system(size: max(8, TabBarMetrics.titleFontSize - 2), weight: .semibold, design: .rounded)) | ||
| .font(.system(size: max(8, (TabBarMetrics.titleFontSize - 2) * uiScale), weight: .semibold, design: .rounded)) |
There was a problem hiding this comment.
P2: Scaled shortcut hint text uses an unscaled width measurement, so larger bonsplitUIScale values can clip the hint label.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At Sources/Bonsplit/Internal/Views/TabItemView.swift, line 238:
<comment>Scaled shortcut hint text uses an unscaled width measurement, so larger `bonsplitUIScale` values can clip the hint label.</comment>
<file context>
@@ -234,7 +235,7 @@ struct TabItemView: View {
if let shortcutHintLabel {
Text(shortcutHintLabel)
- .font(.system(size: max(8, TabBarMetrics.titleFontSize - 2), weight: .semibold, design: .rounded))
+ .font(.system(size: max(8, (TabBarMetrics.titleFontSize - 2) * uiScale), weight: .semibold, design: .rounded))
.monospacedDigit()
.lineLimit(1)
</file context>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Sources/Bonsplit/Internal/Views/TabItemView.swift (1)
227-231:⚠️ Potential issue | 🟡 MinorPotential layout mismatch:
shortcutHintWidthuses unscaled font size.The
shortcutHintWidthfunction calculates width using the base font size withoutuiScale, but the actual rendered text at line 238 uses the scaled font size. This mismatch could cause the hint label to be clipped or have excess padding whenuiScale != 1.0.🔧 Proposed fix to scale the width calculation
private func shortcutHintWidth(for label: String) -> CGFloat { - let font = NSFont.systemFont(ofSize: max(8, TabBarMetrics.titleFontSize - 2), weight: .semibold) + let font = NSFont.systemFont(ofSize: max(8, (TabBarMetrics.titleFontSize - 2) * uiScale), weight: .semibold) let textWidth = (label as NSString).size(withAttributes: [.font: font]).width return ceil(textWidth) + 8 }Also applies to: 238-238
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Sources/Bonsplit/Internal/Views/TabItemView.swift` around lines 227 - 231, shortcutHintWidth currently measures text using an unscaled NSFont which mismatches the rendered, scaled font; update shortcutHintWidth(for:) to compute a scaled font size using uiScale (e.g. let size = max(8, (TabBarMetrics.titleFontSize - 2) * uiScale)) when creating the NSFont for measurement, and also scale the extra padding (the +8) by uiScale so the measured width matches the actual rendered label; reference: shortcutHintWidth, TabBarMetrics.titleFontSize, and uiScale.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@Sources/Bonsplit/Internal/Views/TabItemView.swift`:
- Around line 227-231: shortcutHintWidth currently measures text using an
unscaled NSFont which mismatches the rendered, scaled font; update
shortcutHintWidth(for:) to compute a scaled font size using uiScale (e.g. let
size = max(8, (TabBarMetrics.titleFontSize - 2) * uiScale)) when creating the
NSFont for measurement, and also scale the extra padding (the +8) by uiScale so
the measured width matches the actual rendered label; reference:
shortcutHintWidth, TabBarMetrics.titleFontSize, and uiScale.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a82f55ca-544f-49ff-bcd2-8c69610df537
📒 Files selected for processing (4)
Sources/Bonsplit/Internal/Views/TabBarView.swiftSources/Bonsplit/Internal/Views/TabDragPreview.swiftSources/Bonsplit/Internal/Views/TabItemView.swiftSources/Bonsplit/Public/UIScaleEnvironment.swift
|
I don't see a "contributing" guide anywhere. Should I address these AI comments before this is ready to merge? |
Summary
bonsplitUIScaleSwiftUI environment key that host apps can inject to scale tab bar font sizesDependency for: manaflow-ai/cmux#1387
Test plan
bonsplitUIScaleis not injected (default 1.0).environment(\.bonsplitUIScale, 1.5)on a BonsplitView — verify tab titles, icons, and close buttons scale up🤖 Generated with Claude Code
Summary by cubic
Adds a public SwiftUI environment key
bonsplitUIScaleso host apps can scale tab bar typography and icons. Defaults to 1.0, so there’s no change unless injected.New Features
EnvironmentValues.bonsplitUIScale(default 1.0) to multiply Bonsplit font sizes.Migration
.environment(\.bonsplitUIScale, 1.5)onBonsplitView(or root) to scale up.Written for commit 2a7565b. Summary will update on new commits.
Summary by CodeRabbit