Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 26, 2024
1 parent 234fff3 commit bb51b72
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Color Picker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
E38D432F263AAE8500701B82 /* SettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D432E263AAE8500701B82 /* SettingsScreen.swift */; };
E38D4331263AAEA900701B82 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4330263AAEA900701B82 /* Constants.swift */; };
E38D4333263AB24E00701B82 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4332263AB24E00701B82 /* Utilities.swift */; };
E38D4335263AEE3700701B82 /* ColorPickerScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4334263AEE3700701B82 /* ColorPickerScreen.swift */; };
E38D4335263AEE3700701B82 /* MainScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E38D4334263AEE3700701B82 /* MainScreen.swift */; };
E390D734263B3C71005FCB34 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E390D733263B3C71005FCB34 /* AppState.swift */; };
E390D736263C6ACD005FCB34 /* ColorPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E390D735263C6ACD005FCB34 /* ColorPanel.swift */; };
E390D738263C74C2005FCB34 /* WelcomeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = E390D737263C74C2005FCB34 /* WelcomeScreen.swift */; };
Expand Down Expand Up @@ -72,7 +72,7 @@
E38D432E263AAE8500701B82 /* SettingsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScreen.swift; sourceTree = "<group>"; };
E38D4330263AAEA900701B82 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
E38D4332263AB24E00701B82 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = "<group>"; };
E38D4334263AEE3700701B82 /* ColorPickerScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerScreen.swift; sourceTree = "<group>"; };
E38D4334263AEE3700701B82 /* MainScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreen.swift; sourceTree = "<group>"; };
E390D733263B3C71005FCB34 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
E390D735263C6ACD005FCB34 /* ColorPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPanel.swift; sourceTree = "<group>"; };
E390D737263C74C2005FCB34 /* WelcomeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeScreen.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -166,7 +166,7 @@
E38D4330263AAEA900701B82 /* Constants.swift */,
E390D733263B3C71005FCB34 /* AppState.swift */,
E3DFA8C82662514800D2623E /* Events.swift */,
E38D4334263AEE3700701B82 /* ColorPickerScreen.swift */,
E38D4334263AEE3700701B82 /* MainScreen.swift */,
E390D735263C6ACD005FCB34 /* ColorPanel.swift */,
E38D432E263AAE8500701B82 /* SettingsScreen.swift */,
E390D737263C74C2005FCB34 /* WelcomeScreen.swift */,
Expand Down Expand Up @@ -335,7 +335,7 @@
E38D4331263AAEA900701B82 /* Constants.swift in Sources */,
E3DFA8C92662514800D2623E /* Events.swift in Sources */,
E390D736263C6ACD005FCB34 /* ColorPanel.swift in Sources */,
E38D4335263AEE3700701B82 /* ColorPickerScreen.swift in Sources */,
E38D4335263AEE3700701B82 /* MainScreen.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions Color Picker/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct AppMain: App {
init() {
setUpConfig()

// TODO: Change the default from LCH to OKLCH.
// We set this so we can change it later on.
SSApp.runOnce(identifier: "asdsadewr34323432432") {
Defaults[.shownColorFormats] = Defaults[.shownColorFormats]
Expand Down
2 changes: 1 addition & 1 deletion Color Picker/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class AppState {
colorPanel.center()
colorPanel.makeMain()

let view = ColorPickerScreen(colorPanel: colorPanel)
let view = MainScreen(colorPanel: colorPanel)
// .environment(self)
let accessoryView = NSHostingView(rootView: view)
colorPanel.accessoryView = accessoryView
Expand Down
13 changes: 0 additions & 13 deletions Color Picker/Events.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,5 @@ extension AppState {
KeyboardShortcuts.onKeyUp(for: .toggleWindow) { [self] in
colorPanel.toggle()
}

if #unavailable(macOS 14) {
// Workaround for the color picker window not becoming active after the settings window closes. (macOS 11.3)
NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)
.sink { [self] _ in
DispatchQueue.main.async { [self] in
if colorPanel.isVisible, SSApp.settingsWindow?.isVisible != true {
colorPanel.makeKeyAndOrderFront(nil)
}
}
}
.store(in: &cancellables)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftUI

struct ColorPickerScreen: View {
struct MainScreen: View {
@Default(.uppercaseHexColor) private var uppercaseHexColor
@Default(.hashPrefixInHexColor) private var hashPrefixInHexColor
@Default(.legacyColorSyntax) private var legacyColorSyntax
Expand All @@ -23,12 +23,7 @@ struct ColorPickerScreen: View {
VStack {
BarView()
colorInputs
if showAccessibilityColorName {
Text(colorPanel.color.accessibilityName)
.font(.system(largerText ? .title3 : .body))
.textSelection(.enabled)
.accessibilityHidden(true)
}
colorName
}
.padding(9)
// 244 makes `HSL` always fit in the text field.
Expand Down Expand Up @@ -116,29 +111,39 @@ struct ColorPickerScreen: View {
}

private var colorInputs: some View {
ForEach(ColorFormat.allCases.filter(allowedValues: shownColorFormats)) { format in
ForEach(ColorFormat.allCases.filter(allowedValues: shownColorFormats)) { colorFormat in
ColorInputView(
format: format,
colorString: $colorStrings[format, default: ""],
colorFormat: colorFormat,
colorString: $colorStrings[colorFormat, default: ""],
focusedTextField: $focusedTextField
) { newColor in
updateColorFromTextField(
colorFormat: format,
colorFormat: colorFormat,
colorString: newColor
)
}
}
}

@ViewBuilder
private var colorName: some View {
if showAccessibilityColorName {
Text(colorPanel.color.accessibilityName)
.font(.system(largerText ? .title3 : .body))
.textSelection(.enabled)
.accessibilityHidden(true)
}
}
}

#Preview {
ColorPickerScreen(colorPanel: .shared)
MainScreen(colorPanel: .shared)
}

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

let format: ColorFormat
let colorFormat: ColorFormat
@Binding var colorString: String
@Binding var focusedTextField: ColorFormat?
let updateColor: (String) -> Void
Expand All @@ -147,22 +152,22 @@ private struct ColorInputView: View {
HStack {
NativeTextField(
text: $colorString,
placeholder: format.title,
placeholder: colorFormat.title,
font: .monospacedSystemFont(ofSize: largerText ? 16 : 0, weight: .regular),
isFocused: .conditionalSetOrClearBinding(to: format, with: $focusedTextField)
isFocused: .conditionalSetOrClearBinding(to: colorFormat, with: $focusedTextField)
)
.controlSize(.large)
.onChange(of: colorString) {
updateColor(colorString)
}
Button("Copy \(format.title)", systemImage: "doc.on.doc.fill") {
Button("Copy \(colorFormat.title)", systemImage: "doc.on.doc.fill") {
colorString.copyToPasteboard()
}
.labelStyle(.iconOnly)
.symbolRenderingMode(.hierarchical)
.buttonStyle(.borderless)
.contentShape(.rect)
.keyboardShortcut(format.keyboardShortcutKey, modifiers: [.shift, .command])
.keyboardShortcut(colorFormat.keyboardShortcutKey, modifiers: [.shift, .command])
}
}
}
Expand Down

0 comments on commit bb51b72

Please sign in to comment.