Skip to content

Commit bb51b72

Browse files
committed
Minor tweaks
1 parent 234fff3 commit bb51b72

File tree

5 files changed

+28
-35
lines changed

5 files changed

+28
-35
lines changed

Color Picker.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
E38D432F263AAE8500701B82 /* SettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D432E263AAE8500701B82 /* SettingsScreen.swift */; };
1717
E38D4331263AAEA900701B82 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4330263AAEA900701B82 /* Constants.swift */; };
1818
E38D4333263AB24E00701B82 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4332263AB24E00701B82 /* Utilities.swift */; };
19-
E38D4335263AEE3700701B82 /* ColorPickerScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4334263AEE3700701B82 /* ColorPickerScreen.swift */; };
19+
E38D4335263AEE3700701B82 /* MainScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4334263AEE3700701B82 /* MainScreen.swift */; };
2020
E390D734263B3C71005FCB34 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E390D733263B3C71005FCB34 /* AppState.swift */; };
2121
E390D736263C6ACD005FCB34 /* ColorPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E390D735263C6ACD005FCB34 /* ColorPanel.swift */; };
2222
E390D738263C74C2005FCB34 /* WelcomeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E390D737263C74C2005FCB34 /* WelcomeScreen.swift */; };
@@ -72,7 +72,7 @@
7272
E38D432E263AAE8500701B82 /* SettingsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScreen.swift; sourceTree = "<group>"; };
7373
E38D4330263AAEA900701B82 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
7474
E38D4332263AB24E00701B82 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
75-
E38D4334263AEE3700701B82 /* ColorPickerScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerScreen.swift; sourceTree = "<group>"; };
75+
E38D4334263AEE3700701B82 /* MainScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreen.swift; sourceTree = "<group>"; };
7676
E390D733263B3C71005FCB34 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
7777
E390D735263C6ACD005FCB34 /* ColorPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPanel.swift; sourceTree = "<group>"; };
7878
E390D737263C74C2005FCB34 /* WelcomeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeScreen.swift; sourceTree = "<group>"; };
@@ -166,7 +166,7 @@
166166
E38D4330263AAEA900701B82 /* Constants.swift */,
167167
E390D733263B3C71005FCB34 /* AppState.swift */,
168168
E3DFA8C82662514800D2623E /* Events.swift */,
169-
E38D4334263AEE3700701B82 /* ColorPickerScreen.swift */,
169+
E38D4334263AEE3700701B82 /* MainScreen.swift */,
170170
E390D735263C6ACD005FCB34 /* ColorPanel.swift */,
171171
E38D432E263AAE8500701B82 /* SettingsScreen.swift */,
172172
E390D737263C74C2005FCB34 /* WelcomeScreen.swift */,
@@ -335,7 +335,7 @@
335335
E38D4331263AAEA900701B82 /* Constants.swift in Sources */,
336336
E3DFA8C92662514800D2623E /* Events.swift in Sources */,
337337
E390D736263C6ACD005FCB34 /* ColorPanel.swift in Sources */,
338-
E38D4335263AEE3700701B82 /* ColorPickerScreen.swift in Sources */,
338+
E38D4335263AEE3700701B82 /* MainScreen.swift in Sources */,
339339
);
340340
runOnlyForDeploymentPostprocessing = 0;
341341
};

Color Picker/App.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ struct AppMain: App {
2020
init() {
2121
setUpConfig()
2222

23+
// TODO: Change the default from LCH to OKLCH.
2324
// We set this so we can change it later on.
2425
SSApp.runOnce(identifier: "asdsadewr34323432432") {
2526
Defaults[.shownColorFormats] = Defaults[.shownColorFormats]

Color Picker/AppState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class AppState {
2626
colorPanel.center()
2727
colorPanel.makeMain()
2828

29-
let view = ColorPickerScreen(colorPanel: colorPanel)
29+
let view = MainScreen(colorPanel: colorPanel)
3030
// .environment(self)
3131
let accessoryView = NSHostingView(rootView: view)
3232
colorPanel.accessoryView = accessoryView

Color Picker/Events.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,5 @@ extension AppState {
4545
KeyboardShortcuts.onKeyUp(for: .toggleWindow) { [self] in
4646
colorPanel.toggle()
4747
}
48-
49-
if #unavailable(macOS 14) {
50-
// Workaround for the color picker window not becoming active after the settings window closes. (macOS 11.3)
51-
NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)
52-
.sink { [self] _ in
53-
DispatchQueue.main.async { [self] in
54-
if colorPanel.isVisible, SSApp.settingsWindow?.isVisible != true {
55-
colorPanel.makeKeyAndOrderFront(nil)
56-
}
57-
}
58-
}
59-
.store(in: &cancellables)
60-
}
6148
}
6249
}

Color Picker/ColorPickerScreen.swift renamed to Color Picker/MainScreen.swift

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import SwiftUI
22

3-
struct ColorPickerScreen: View {
3+
struct MainScreen: View {
44
@Default(.uppercaseHexColor) private var uppercaseHexColor
55
@Default(.hashPrefixInHexColor) private var hashPrefixInHexColor
66
@Default(.legacyColorSyntax) private var legacyColorSyntax
@@ -23,12 +23,7 @@ struct ColorPickerScreen: View {
2323
VStack {
2424
BarView()
2525
colorInputs
26-
if showAccessibilityColorName {
27-
Text(colorPanel.color.accessibilityName)
28-
.font(.system(largerText ? .title3 : .body))
29-
.textSelection(.enabled)
30-
.accessibilityHidden(true)
31-
}
26+
colorName
3227
}
3328
.padding(9)
3429
// 244 makes `HSL` always fit in the text field.
@@ -116,29 +111,39 @@ struct ColorPickerScreen: View {
116111
}
117112

118113
private var colorInputs: some View {
119-
ForEach(ColorFormat.allCases.filter(allowedValues: shownColorFormats)) { format in
114+
ForEach(ColorFormat.allCases.filter(allowedValues: shownColorFormats)) { colorFormat in
120115
ColorInputView(
121-
format: format,
122-
colorString: $colorStrings[format, default: ""],
116+
colorFormat: colorFormat,
117+
colorString: $colorStrings[colorFormat, default: ""],
123118
focusedTextField: $focusedTextField
124119
) { newColor in
125120
updateColorFromTextField(
126-
colorFormat: format,
121+
colorFormat: colorFormat,
127122
colorString: newColor
128123
)
129124
}
130125
}
131126
}
127+
128+
@ViewBuilder
129+
private var colorName: some View {
130+
if showAccessibilityColorName {
131+
Text(colorPanel.color.accessibilityName)
132+
.font(.system(largerText ? .title3 : .body))
133+
.textSelection(.enabled)
134+
.accessibilityHidden(true)
135+
}
136+
}
132137
}
133138

134139
#Preview {
135-
ColorPickerScreen(colorPanel: .shared)
140+
MainScreen(colorPanel: .shared)
136141
}
137142

138143
private struct ColorInputView: View {
139144
@Default(.largerText) private var largerText
140145

141-
let format: ColorFormat
146+
let colorFormat: ColorFormat
142147
@Binding var colorString: String
143148
@Binding var focusedTextField: ColorFormat?
144149
let updateColor: (String) -> Void
@@ -147,22 +152,22 @@ private struct ColorInputView: View {
147152
HStack {
148153
NativeTextField(
149154
text: $colorString,
150-
placeholder: format.title,
155+
placeholder: colorFormat.title,
151156
font: .monospacedSystemFont(ofSize: largerText ? 16 : 0, weight: .regular),
152-
isFocused: .conditionalSetOrClearBinding(to: format, with: $focusedTextField)
157+
isFocused: .conditionalSetOrClearBinding(to: colorFormat, with: $focusedTextField)
153158
)
154159
.controlSize(.large)
155160
.onChange(of: colorString) {
156161
updateColor(colorString)
157162
}
158-
Button("Copy \(format.title)", systemImage: "doc.on.doc.fill") {
163+
Button("Copy \(colorFormat.title)", systemImage: "doc.on.doc.fill") {
159164
colorString.copyToPasteboard()
160165
}
161166
.labelStyle(.iconOnly)
162167
.symbolRenderingMode(.hierarchical)
163168
.buttonStyle(.borderless)
164169
.contentShape(.rect)
165-
.keyboardShortcut(format.keyboardShortcutKey, modifiers: [.shift, .command])
170+
.keyboardShortcut(colorFormat.keyboardShortcutKey, modifiers: [.shift, .command])
166171
}
167172
}
168173
}

0 commit comments

Comments
 (0)