Add custom color setting#188
Conversation
Introduce a user-configurable ruler color and wire it through UI, prefs, rendering, and tests. - Preferences UI: add a NSColorWell to PreferencesController.xib and expose outlet/action in PreferencesController to update prefs continuously. - Prefs: store rulerColor as an NSColor (archived/unarchived via keyed archiver), provide a default color and a defaultRulerFillColor accessor, and persist changes to UserDefaults. - AppDelegate: observe rulerColor changes and trigger ruler redraws; initialize prefs with defaultRulerFillColor. - RuleView: use prefs.rulerColor for fill and derive contrasting numbers/ticks/mouse/handle colors; add redrawForPreferenceChange and NSColor helpers (isLightColor, mixed) for color math. - Tests: add unit tests verifying default fill color and contrasting foreground derivation, plus color/luminance helpers. - Localization: add localized title for the new "Ruler Color" label in several .strings files. These changes enable users to pick a custom ruler color that is persisted and used to compute readable foreground/tick colors, with UI and tests updated accordingly.
Add a dedicated reset control and logic to restore the default ruler color. UI: preferences XIB now includes a reset button next to the color well, updated constraints/frames, and sets the window restorable attribute to NO. Localization: add "Reset ruler color" strings for multiple locales. Code: expose the reset button outlet, wire a resetRulerColor: IBAction that sets prefs.rulerColor to Prefs.defaultRulerFillColor, configure the button appearance/tool tip/accessibility (uses SF Symbol arrow.counterclockwise), make the color well the initial responder, and hide the reset button when the current color matches the default via a colorsMatch helper.
Adjust PreferencesController.xib button position and constraints (mark button as misplaced, tweak frame and leading constraint constant) to correct layout. Update RuleView.contrastingColor to store the mixed color in a variable and only apply boosted saturation for light fills, avoiding oversaturation for dark colors and simplifying the return logic.
There was a problem hiding this comment.
Pull request overview
Adds a user-configurable ruler fill color preference (with reset) and updates the ruler rendering to derive contrasting foreground/handle colors from the chosen fill. This fits into the existing Preferences UI + Prefs KVO bridge pattern and updates ruler redraw behavior when preferences change.
Changes:
- Add
Prefs.rulerColorpersistence, preferences UI controls (color well + reset), and localization strings. - Update ruler drawing colors to be derived dynamically from the chosen fill color (with contrast logic).
- Add unit tests validating default fill color and contrasting foreground behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| FreeRulerTests/RulerCoreTests.swift | Adds tests for default fill color and contrast derivation. |
| Free Ruler/RuleView.swift | Switches to preference-driven fill color and computed contrasting colors. |
| Free Ruler/Prefs.swift | Adds rulerColor preference with UserDefaults persistence via archiving. |
| Free Ruler/PreferencesController.swift | Adds color well + reset button wiring and UI behavior. |
| Free Ruler/Base.lproj/PreferencesController.xib | Adds/positions the new color controls in Preferences. |
| Free Ruler/Localizable.xcstrings | Adds localized string for “Reset ruler color”. |
| Free Ruler/de.lproj/PreferencesController.strings | Adds localized “Ruler Color” label. |
| Free Ruler/es.lproj/PreferencesController.strings | Adds localized “Ruler Color” label. |
| Free Ruler/fi.lproj/PreferencesController.strings | Adds localized “Ruler Color” label. |
| Free Ruler/ja.lproj/PreferencesController.strings | Adds localized “Ruler Color” label. |
| Free Ruler/zh-hans.lproj/PreferencesController.strings | Adds localized “Ruler Color” label. |
| Free Ruler/AppDelegate.swift | Redraws rulers when rulerColor changes; resets rulerColor in UI test reset. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
[codex] @copilot please take another look when you have a chance. The currently actionable review comments have been addressed and pushed. |
|
[codex] @copilot please take another look. I addressed the follow-up review comments and pushed the fixes. |
The four new review comments have been addressed in commit
|
[codex] Addressed in |
Force the app to use opaque (no-alpha) color picking for ruler colors and add a custom RulerColorWell UI. Changes include: - Add configureOpaqueColorPicking() and setColorPickingIgnoresAlpha(_:) (uses ObjC runtime to call the deprecated setIgnoresAlpha: switch) to ensure AppKit color wells ignore alpha. - Introduce RulerColorWell subclass with custom drawing, activation/mouse handling, and forced supportsAlpha = false to keep the color panel opaque. - Wire opaque color-picking setup into AppDelegate.applicationDidFinishLaunching and PreferencesController lifecycle (showWindow/init), and call configureOpaqueColorPicking at key points. - Subscribe to NSColorPanel.colorDidChangeNotification to update prefs.rulerColor when the color panel changes, and add cleanup in deinit. - Add closeRulerColorPanel() helper and ensure NSColorPanel is non-animated and uses continuous updates. These changes prevent users from selecting/transmitting alpha for ruler fills and keep the color panel behavior consistent across the app.
Ensure archived ruler colors are normalized when loaded by replacing the direct unarchive call with Prefs.rulerFillColor(fromArchivedData:), which returns a normalized color or the default. Add a helper to perform unarchiving + normalization. Also update the Preferences XIB to use the custom RulerColorWell class (Free_Ruler target) for the colorWell so the UI control is backed by the custom subclass.
Add a unit test that archives an NSColor with alpha 0.35 and verifies Prefs.rulerFillColor(fromArchivedData:) returns the same RGB values with alpha normalized to 1. Ensures colors loaded from archived preference data are made fully opaque for ruler fill.
|
[codex] @copilot please give another code review. do not make code changes. I addressed the four latest test-cleanup comments in commit |
[codex] The test-cleanup changes in One open item from the automated reviewer: |
|
[codex] @copilot please give another code review. do not make code changes. I addressed the latest screenshot preview label comment in commit |
|
[codex] @copilot please give another code review. do not make code changes. I addressed the Objective-C runtime import comment in commit |
[codex] Reviewed commit |
[codex] Reviewed the latest changes. |
Uh oh!
There was an error while loading. Please reload this page.