Skip to content

Commit

Permalink
Improving how colors and SchemeContrast are handled - Related to #34
Browse files Browse the repository at this point in the history
  • Loading branch information
DamascenoRafael committed Mar 17, 2023
1 parent 65e5284 commit e5e190c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 13 deletions.
8 changes: 8 additions & 0 deletions reminders-menu-bar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
71E7126D2908EBD100DA97BD /* RemoveFocusFromFirstResponder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71E7126C2908EBD100DA97BD /* RemoveFocusFromFirstResponder.swift */; };
71ED5D6B290B6B3C00626185 /* RmbReminder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71ED5D6A290B6B3C00626185 /* RmbReminder.swift */; };
71F301FA259FB5CF00CDD81E /* UserPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71F301F9259FB5CF00CDD81E /* UserPreferences.swift */; };
71F36A9829C16B7A0099D337 /* RmbColorKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71F36A9729C16B7A0099D337 /* RmbColorKey.swift */; };
71F36A9A29C2BA0C0099D337 /* RmbColorScheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71F36A9929C2BA0C0099D337 /* RmbColorScheme.swift */; };
71F36AA029C3E79E0099D337 /* Color+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71F36A9F29C3E79E0099D337 /* Color+Extensions.swift */; };
71F84A4629541D6700C5A24D /* URL+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71F84A4529541D6700C5A24D /* URL+Extensions.swift */; };
71F9726A25981EDF00D0A118 /* NSTableView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71F9726925981EDF00D0A118 /* NSTableView+Extensions.swift */; };
96A54A6B29A3ADB70060403F /* DateParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A54A6A29A3ADB70060403F /* DateParser.swift */; };
Expand Down Expand Up @@ -146,7 +148,9 @@
71E7126C2908EBD100DA97BD /* RemoveFocusFromFirstResponder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoveFocusFromFirstResponder.swift; sourceTree = "<group>"; };
71ED5D6A290B6B3C00626185 /* RmbReminder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RmbReminder.swift; sourceTree = "<group>"; };
71F301F9259FB5CF00CDD81E /* UserPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserPreferences.swift; sourceTree = "<group>"; };
71F36A9729C16B7A0099D337 /* RmbColorKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RmbColorKey.swift; sourceTree = "<group>"; };
71F36A9929C2BA0C0099D337 /* RmbColorScheme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RmbColorScheme.swift; sourceTree = "<group>"; };
71F36A9F29C3E79E0099D337 /* Color+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+Extensions.swift"; sourceTree = "<group>"; };
71F84A4529541D6700C5A24D /* URL+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "URL+Extensions.swift"; sourceTree = "<group>"; };
71F9726925981EDF00D0A118 /* NSTableView+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSTableView+Extensions.swift"; sourceTree = "<group>"; };
8206522829B779B500CE522F /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Localizable.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -314,6 +318,7 @@
7151CC9A265E0388002D7F1D /* Localizable.strings */,
71B1836726AE145700A5C397 /* InfoPlist.strings */,
714C497F267FA56F00721516 /* remindersLocalized.swift */,
71F36A9729C16B7A0099D337 /* RmbColorKey.swift */,
71F36A9929C2BA0C0099D337 /* RmbColorScheme.swift */,
);
path = Resources;
Expand Down Expand Up @@ -349,6 +354,7 @@
71F84A4529541D6700C5A24D /* URL+Extensions.swift */,
71E712692908C6D100DA97BD /* NilCoalescingBindingOverload.swift */,
96A54A6C29A3B1A90060403F /* String+Extensions.swift */,
71F36A9F29C3E79E0099D337 /* Color+Extensions.swift */,
71E5C75429B7D45600568292 /* UserDefaults+Extensions.swift */,
);
path = Extensions;
Expand Down Expand Up @@ -507,6 +513,7 @@
71A4163725CED8FE00CA4F81 /* GithubService.swift in Sources */,
71D6B98028E25B9F0004EEBB /* AppCommands.swift in Sources */,
7141456325CF9693006695B2 /* Release.swift in Sources */,
71F36A9829C16B7A0099D337 /* RmbColorKey.swift in Sources */,
71E7126A2908C6D100DA97BD /* NilCoalescingBindingOverload.swift in Sources */,
71E51D5825BFB8CF009A4B56 /* AboutView.swift in Sources */,
7115461924C0C280007781E2 /* RemindersService.swift in Sources */,
Expand All @@ -523,6 +530,7 @@
71ED5D6B290B6B3C00626185 /* RmbReminder.swift in Sources */,
7156444226031CA9005E81FD /* Array+Extension.swift in Sources */,
71F301FA259FB5CF00CDD81E /* UserPreferences.swift in Sources */,
71F36AA029C3E79E0099D337 /* Color+Extensions.swift in Sources */,
71A3834625BDD2AC00975B4C /* EKReminder+Extensions.swift in Sources */,
71B4AD6625B9118000214219 /* NoReminderItemsView.swift in Sources */,
714E6F6125CCF66000BA0099 /* Constants.swift in Sources */,
Expand Down
8 changes: 8 additions & 0 deletions reminders-menu-bar/Extensions/Color+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import SwiftUI

extension Color {
static func rmbColor(for colorKey: RmbColorKey, and colorSchemeContrast: ColorSchemeContrast) -> Color {
let isTransparencyEnabled = UserPreferences.shared.backgroundIsTransparent && colorSchemeContrast == .standard
return colorKey.color(withTransparency: isTransparencyEnabled)
}
}
43 changes: 43 additions & 0 deletions reminders-menu-bar/Resources/RmbColorKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import SwiftUI

enum RmbColorKey: String {
case buttonHover
case backgroundTheme
case textFieldBackground // textFieldBackgroundTransparent

private var transparencyPostfix: String { "Transparent" }

private var hasTransparencyPostfixString: Bool {
switch self {
case .textFieldBackground:
return true
default:
return false
}
}

private var hasTransparencyOpacityOption: Bool {
switch self {
case .backgroundTheme:
return true
default:
return false
}
}

func color(withTransparency isTransparencyEnabled: Bool) -> Color {
guard isTransparencyEnabled else {
return Color(rawValue)
}

if hasTransparencyPostfixString {
return Color(rawValue + transparencyPostfix)
}

if hasTransparencyOpacityOption {
return Color(rawValue).opacity(0.3)
}

return Color(rawValue)
}
}
3 changes: 2 additions & 1 deletion reminders-menu-bar/Views/CalendarTitle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import EventKit

struct CalendarTitle: View {
@ObservedObject var userPreferences = UserPreferences.shared
@Environment(\.colorSchemeContrast) private var colorSchemeContrast

var calendar: EKCalendar
@State var calendarFolderIsHovered = false
Expand All @@ -27,7 +28,7 @@ struct CalendarTitle: View {
.padding(5)
}
.buttonStyle(BorderlessButtonStyle())
.background(calendarFolderIsHovered ? Color("buttonHover") : nil)
.background(calendarFolderIsHovered ? Color.rmbColor(for: .buttonHover, and: colorSchemeContrast) : nil)
.cornerRadius(6)
.onHover { isHovered in
calendarFolderIsHovered = isHovered
Expand Down
3 changes: 2 additions & 1 deletion reminders-menu-bar/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import EventKit
struct ContentView: View {
@EnvironmentObject var remindersData: RemindersData
@ObservedObject var userPreferences = UserPreferences.shared
@Environment(\.colorSchemeContrast) private var colorSchemeContrast

var body: some View {
VStack(spacing: 0) {
Expand Down Expand Up @@ -44,7 +45,7 @@ struct ContentView: View {
.onAppear {
remindersData.update()
}
.background(Color("backgroundTheme").opacity(userPreferences.backgroundIsTransparent ? 0.3 : 1.0).padding(-80))
.background(Color.rmbColor(for: .backgroundTheme, and: colorSchemeContrast).padding(-80))
}

private func filteredReminders(_ reminders: [EKReminder]) -> [EKReminder] {
Expand Down
7 changes: 2 additions & 5 deletions reminders-menu-bar/Views/FormNewReminderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import EventKit
struct FormNewReminderView: View {
@EnvironmentObject var remindersData: RemindersData
@ObservedObject var userPreferences = UserPreferences.shared
@Environment(\.colorSchemeContrast) private var colorSchemeContrast

@State var rmbReminder = RmbReminder()
@State var isShowingDueDateOptions = false
Expand All @@ -16,11 +17,7 @@ struct FormNewReminderView: View {
.padding(.vertical, 8)
.padding(.horizontal, 8)
.padding(.leading, 22)
.background(
userPreferences.backgroundIsTransparent ?
Color("textFieldBackgroundTransparent") :
Color("textFieldBackground")
)
.background(Color.rmbColor(for: .textFieldBackground, and: colorSchemeContrast))
.cornerRadius(8)
.textFieldStyle(PlainTextFieldStyle())
.overlay(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
struct SettingsBarFilterMenu: View {
@EnvironmentObject var remindersData: RemindersData
@ObservedObject var userPreferences = UserPreferences.shared
@Environment(\.colorSchemeContrast) private var colorSchemeContrast

@State var filterIsHovered = false

Expand Down Expand Up @@ -39,7 +40,7 @@ struct SettingsBarFilterMenu: View {
.menuStyle(BorderlessButtonMenuStyle())
.frame(width: 32, height: 16)
.padding(3)
.background(filterIsHovered ? Color("buttonHover") : nil)
.background(filterIsHovered ? Color.rmbColor(for: .buttonHover, and: colorSchemeContrast) : nil)
.cornerRadius(4)
.onHover { isHovered in
filterIsHovered = isHovered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
struct SettingsBarGearMenu: View {
@EnvironmentObject var remindersData: RemindersData
@ObservedObject var userPreferences = UserPreferences.shared
@Environment(\.colorSchemeContrast) private var colorSchemeContrast

@State var gearIsHovered = false

Expand Down Expand Up @@ -72,7 +73,7 @@ struct SettingsBarGearMenu: View {
.menuStyle(BorderlessButtonMenuStyle())
.frame(width: 32, height: 16)
.padding(3)
.background(gearIsHovered ? Color("buttonHover") : nil)
.background(gearIsHovered ? Color.rmbColor(for: .buttonHover, and: colorSchemeContrast) : nil)
.cornerRadius(4)
.onHover { isHovered in
gearIsHovered = isHovered
Expand Down Expand Up @@ -121,21 +122,26 @@ struct SettingsBarGearMenu: View {

Divider()

let isIncreasedContrastEnabled = colorSchemeContrast == .increased
let isTransparencyEnabled = userPreferences.backgroundIsTransparent && !isIncreasedContrastEnabled

Button(action: {
userPreferences.backgroundIsTransparent = false
}) {
let isSelected = !userPreferences.backgroundIsTransparent
let isSelected = !isTransparencyEnabled
SelectableView(title: rmbLocalized(.appAppearanceMoreOpaqueOptionButton),
isSelected: isSelected)
}
.disabled(isIncreasedContrastEnabled)

Button(action: {
userPreferences.backgroundIsTransparent = true
}) {
let isSelected = userPreferences.backgroundIsTransparent
let isSelected = isTransparencyEnabled
SelectableView(title: rmbLocalized(.appAppearanceMoreTransparentOptionButton),
isSelected: isSelected)
}
.disabled(isIncreasedContrastEnabled)
} label: {
Text(rmbLocalized(.appAppearanceMenu))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI

struct SettingsBarToggleButton: View {
@ObservedObject var userPreferences = UserPreferences.shared
@Environment(\.colorSchemeContrast) private var colorSchemeContrast

@State var toggleIsHovered = false

Expand All @@ -14,7 +15,7 @@ struct SettingsBarToggleButton: View {
.padding(.horizontal, 4)
}
.buttonStyle(BorderlessButtonStyle())
.background(toggleIsHovered ? Color("buttonHover") : nil)
.background(toggleIsHovered ? Color.rmbColor(for: .buttonHover, and: colorSchemeContrast) : nil)
.cornerRadius(4)
.onHover { isHovered in
toggleIsHovered = isHovered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import SwiftUI

struct UpcomingRemindersTitle: View {
@ObservedObject var userPreferences = UserPreferences.shared
@Environment(\.colorSchemeContrast) private var colorSchemeContrast

@State var intervalButtonIsHovered = false

Expand Down Expand Up @@ -32,7 +33,7 @@ struct UpcomingRemindersTitle: View {
.menuStyle(BorderlessButtonMenuStyle())
.padding(.vertical, 5)
.padding(.horizontal, 10)
.background(intervalButtonIsHovered ? Color("buttonHover") : nil)
.background(intervalButtonIsHovered ? Color.rmbColor(for: .buttonHover, and: colorSchemeContrast) : nil)
.cornerRadius(6)
.onHover { isHovered in
intervalButtonIsHovered = isHovered
Expand Down

0 comments on commit e5e190c

Please sign in to comment.