-
Notifications
You must be signed in to change notification settings - Fork 60
feat: added better foreground color calculations when using custom color picker #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- added `ColorTheme` enum with associated colors - introduced `ThemeConstants` for theme-related constants - created `ColorPickerView` for selecting custom colors - updated `GeneralSettingsView` to include color scheme selector - integrated notifications for theme changes - enhanced `Color` extension with brightness and saturation adjustments
- added adaptive foreground color properties to `ColorTheme` and `Theme` - updated `SearchEngine` and `GeneralSettingsView` to use adaptive foreground colors - improved `Color` extension with luminance calculation and adaptive foreground methods - refactored color handling for better theme integration
There was a problem hiding this 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 pull request introduces a comprehensive color theme system enabling users to select from predefined color schemes or create custom themes through an interactive color picker. The changes ensure adaptive foreground colors for improved accessibility and visual consistency across the application.
- Added ColorTheme enum with multiple built-in themes and custom option with persistent storage
- Integrated color picker UI for custom color selection with live preview capabilities
- Enhanced color utilities with luminance calculation and adaptive foreground color determination
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| ColorPickerView.swift | New interactive color picker component with HSB controls and hex input |
| SearchEngineService.swift | Updated to use adaptive foreground colors for search engine icons |
| AppearanceManager.swift | Extended to manage color theme persistence and notifications |
| GeneralSettingsView.swift | Added color scheme selector UI with custom color picker integration |
| SearchEngine.swift | Modified to use adaptive foreground color as fallback |
| Color+Hex.swift | Enhanced with color adjustment, luminance calculation, and adaptive foreground utilities |
| Theme.swift | Restructured to support color themes with adaptive foreground properties |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| DragGesture() | ||
| .onChanged { value in | ||
| let linearValue = min(max(0, value.location.x / geometry.size.width), 1) | ||
| brightness = max(0.35, linearToNonLinearBrightness(linearValue)) |
Copilot
AI
Sep 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 0.35 appears multiple times (lines 37, 56) as a minimum brightness value. Consider defining this as a constant at the top of the struct for better maintainability.
| private func nonLinearBrightnessToLinear(_ brightness: Double) -> Double { | ||
| // Use a power curve: y = x^2 for more precision in bright values | ||
| // This maps 0.5 brightness to 0.25 slider position, 0.8 to 0.64, etc. | ||
| return pow(brightness, 2.0) | ||
| } | ||
|
|
||
| // Convert linear slider position (0-1) to non-linear brightness (0-1) | ||
| private func linearToNonLinearBrightness(_ linear: Double) -> Double { | ||
| // Inverse of the power curve: y = x^0.5 | ||
| // This maps 0.25 slider to 0.5 brightness, 0.64 to 0.8, etc. | ||
| return pow(linear, 0.5) | ||
| } |
Copilot
AI
Sep 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic numbers 2.0 and 0.5 for the power curve calculations should be defined as constants to make the relationship between these functions clearer and easier to modify.
|
|
||
| hue = Double(normalizedAngle) | ||
| // Apply inverse non-linear mapping to saturation for more precision in desaturated colors | ||
| saturation = Double(pow(normalizedDistance, 2.0)) |
Copilot
AI
Sep 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another magic number 2.0 used for saturation mapping. This should be consistent with the brightness power curve constants or defined separately if intentionally different.
|
|
||
| // Generate a darker version for dark mode | ||
| let lightHex = newColor.toHex() ?? "#f3e5d6" | ||
| let darkColor = newColor.adjusted(brightness: 0.3, saturation: 1.2) |
Copilot
AI
Sep 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic numbers 0.3 and 1.2 for brightness and saturation adjustments should be defined as constants, possibly in ThemeConstants, to make the dark mode color generation logic more transparent and configurable.
This pull request introduces a comprehensive color theme system for the application, enabling users to select from a variety of color schemes—including a customizable option—and ensuring adaptive foreground colors for improved accessibility and visual consistency. The changes span theme management, UI integration, and color utility enhancements.
Theme system and color customization:
ColorThemeenum andThemeConstantsstruct toTheme.swift, supporting multiple built-in color themes and a "Custom" option. The theme now adapts its colors based on user selection, with custom colors stored inUserDefaultsand updated via notifications.GeneralSettingsView.swift, allowing users to pick a theme or define a custom color using a color picker. Custom colors are persisted and trigger live theme updates.AppearanceManager.swiftto manage and persist the selected color theme, broadcasting changes viaNotificationCenterfor reactive updates throughout the app.Adaptive and contrasting colors:
Color+Hex.swiftwith utility methods for adjusting brightness/saturation, calculating luminance, and determining adaptive/contrasting foreground colors for accessibility. These are used throughout the theme system and UI components.Theme propagation and environment integration:
Themestruct and its environment key to support color theme and update triggers, ensuring theme changes propagate reactively via SwiftUI's environment system. [1] [2]Themestruct for various UI backgrounds, improving consistency and readability throughout the app.