Skip to content
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

feat: extract subviews on extension #186

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions ControlRoom.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
3C13FF952BEF499400060A5C /* NotificationsFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C13FF942BEF499400060A5C /* NotificationsFormView.swift */; };
3C13FF972BEF4AAE00060A5C /* PickersFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C13FF962BEF4AAE00060A5C /* PickersFormView.swift */; };
3C13FF992BEF4C9200060A5C /* ColorPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C13FF982BEF4C9200060A5C /* ColorPickerView.swift */; };
3C13FF9B2BEF4D5100060A5C /* PathToTerminalTextFieldView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C13FF9A2BEF4D5100060A5C /* PathToTerminalTextFieldView.swift */; };
3CF07C312BEF48D200770363 /* TogglesFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3CF07C302BEF48D200770363 /* TogglesFormView.swift */; };
41C44ACD2616FCB50016B1E4 /* FFMPEGConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 41C44ACC2616FCB50016B1E4 /* FFMPEGConverter.swift */; };
510871F225C317830009E39F /* SimulatorAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 510871F125C317830009E39F /* SimulatorAction.swift */; };
511BA57D23F3FFEA00E3E660 /* ControlRoomApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 511BA57C23F3FFEA00E3E660 /* ControlRoomApp.swift */; };
Expand Down Expand Up @@ -95,6 +100,11 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
3C13FF942BEF499400060A5C /* NotificationsFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationsFormView.swift; sourceTree = "<group>"; };
3C13FF962BEF4AAE00060A5C /* PickersFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PickersFormView.swift; sourceTree = "<group>"; };
3C13FF982BEF4C9200060A5C /* ColorPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorPickerView.swift; sourceTree = "<group>"; };
3C13FF9A2BEF4D5100060A5C /* PathToTerminalTextFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathToTerminalTextFieldView.swift; sourceTree = "<group>"; };
3CF07C302BEF48D200770363 /* TogglesFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TogglesFormView.swift; sourceTree = "<group>"; };
41C44ACC2616FCB50016B1E4 /* FFMPEGConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FFMPEGConverter.swift; sourceTree = "<group>"; };
510871F125C317830009E39F /* SimulatorAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimulatorAction.swift; sourceTree = "<group>"; };
511BA57923F3FFEA00E3E660 /* Control Room.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Control Room.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -418,6 +428,11 @@
isa = PBXGroup;
children = (
55AF68B423F9CFD600C5D87A /* SettingsView.swift */,
3CF07C302BEF48D200770363 /* TogglesFormView.swift */,
3C13FF942BEF499400060A5C /* NotificationsFormView.swift */,
3C13FF962BEF4AAE00060A5C /* PickersFormView.swift */,
3C13FF982BEF4C9200060A5C /* ColorPickerView.swift */,
3C13FF9A2BEF4D5100060A5C /* PathToTerminalTextFieldView.swift */,
);
path = "Settings UI";
sourceTree = "<group>";
Expand Down Expand Up @@ -629,13 +644,16 @@
55AF68B723F9D2E200C5D87A /* UIState.swift in Sources */,
511BA59223F4031F00E3E660 /* ControlView.swift in Sources */,
5534158223FE0539005C0A41 /* Contributors.swift in Sources */,
3C13FF9B2BEF4D5100060A5C /* PathToTerminalTextFieldView.swift in Sources */,
511BA57F23F3FFEA00E3E660 /* MainView.swift in Sources */,
551F8D0023F5CB3A0006D1BD /* SimCtl+Types.swift in Sources */,
511BA5A023F4197200E3E660 /* StatusBarView.swift in Sources */,
51AB56EB2A141C57002B5A67 /* ColorHistoryController.swift in Sources */,
ACDF076823F7E91A00597B3B /* ApplicationType.swift in Sources */,
3C13FF952BEF499400060A5C /* NotificationsFormView.swift in Sources */,
51AB56E92A141055002B5A67 /* ColorsView.swift in Sources */,
51B0242325C3106E0042394E /* AppSummaryView.swift in Sources */,
3C13FF992BEF4C9200060A5C /* ColorPickerView.swift in Sources */,
51AB56ED2A143B90002B5A67 /* Double-Rounding.swift in Sources */,
55DF68BB23F8BE8D00E717D3 /* CreateSimulatorActionSheet.swift in Sources */,
515E56DF2A14499B003B4F5A /* XcodeColorSet.swift in Sources */,
Expand Down Expand Up @@ -671,6 +689,7 @@
51B0241625C30EEF0042394E /* CLLocationCoordinate2D-Identifiable.swift in Sources */,
5534157E23FE04FA005C0A41 /* AboutView.swift in Sources */,
511BA59023F4030D00E3E660 /* LoadingView.swift in Sources */,
3CF07C312BEF48D200770363 /* TogglesFormView.swift in Sources */,
511BA59623F408F800E3E660 /* LoadingFailedView.swift in Sources */,
510871F225C317830009E39F /* SimulatorAction.swift in Sources */,
55AF68B523F9CFD600C5D87A /* SettingsView.swift in Sources */,
Expand All @@ -679,6 +698,7 @@
551F8CF523F4AF7B0006D1BD /* SearchField.swift in Sources */,
AC472CCF240D46D7007FF521 /* KeyedEncodingContainer-NotEmpty.swift in Sources */,
51AB56E72A140D53002B5A67 /* NSColor-Conversions.swift in Sources */,
3C13FF972BEF4AAE00060A5C /* PickersFormView.swift in Sources */,
5FA79DA92A5752A9006F5477 /* XcodeHelper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -857,8 +877,11 @@
MARKETING_VERSION = 3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.hackingwithswift.ControlRoom;
PRODUCT_NAME = "Control Room";
SUPPORTED_PLATFORMS = "macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 7;
};
name = Debug;
};
Expand Down Expand Up @@ -890,7 +913,10 @@
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.hackingwithswift.ControlRoom;
PRODUCT_NAME = "Control Room";
SUPPORTED_PLATFORMS = "macosx xros xrsimulator";
SUPPORTS_MACCATALYST = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = 7;
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "69c39523ac0471922b625cc56b8722155cfd2afd660bdd4f5ff67335b5b87714",
"pins" : [
{
"identity" : "keyboardshortcuts",
Expand All @@ -10,5 +11,5 @@
}
}
],
"version" : 2
"version" : 3
}
32 changes: 32 additions & 0 deletions ControlRoom/Settings UI/ColorPickerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// ColorPickerView.swift
// ControlRoom
//
// Created by Elliot Knight on 11/05/2024.
// Copyright © 2024 Paul Hudson. All rights reserved.
//

import SwiftUI

struct ColorPickerView: View {
/// Whether hex strings should be printed in uppercase or not.
@AppStorage("CRColorPickerUppercaseHex") var uppercaseHex = true

/// How many decimal places to use for rounding picked colors.
@AppStorage("CRColorPickerAccuracy") var colorPickerAccuracy = 2

var body: some View {
VStack {
Toggle("Uppercase Hex Strings", isOn: $uppercaseHex)
.padding(.bottom)

Text("Set the maximum number of decimal places to use when generating code for picked simulator colors. The default is 2.")
Stepper("Decimal Places: \(colorPickerAccuracy)", value: $colorPickerAccuracy, in: 0...5)
.pickerStyle(.segmented)
}
}
}

#Preview {
ColorPickerView()
}
31 changes: 31 additions & 0 deletions ControlRoom/Settings UI/NotificationsFormView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// NotificationsFormView.swift
// ControlRoom
//
// Created by Elliot Knight on 11/05/2024.
// Copyright © 2024 Paul Hudson. All rights reserved.
//

import SwiftUI
import KeyboardShortcuts

struct NotificationsFormView: View {
var body: some View {
Form {
makeKeyboardShortcut(title: "Resend last push notification", for: .resendLastPushNotification)
makeKeyboardShortcut(title: "Restart last selected app", for: .restartLastSelectedApp)
makeKeyboardShortcut(title: "Reopen last URL", for: .reopenLastURL)
}
}

private func makeKeyboardShortcut(title: String, for name: KeyboardShortcuts.Name) -> some View {
HStack {
Text(title)
KeyboardShortcuts.Recorder(for: name)
}
}
}

#Preview {
NotificationsFormView()
}
28 changes: 28 additions & 0 deletions ControlRoom/Settings UI/PathToTerminalTextFieldView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// PathToTerminalTextFieldView.swift
// ControlRoom
//
// Created by Elliot Knight on 11/05/2024.
// Copyright © 2024 Paul Hudson. All rights reserved.
//

import SwiftUI

struct PathToTerminalTextFieldView: View {
@EnvironmentObject var preferences: Preferences

var body: some View {
Form {
TextField(
"Path to Terminal",
text: $preferences.terminalAppPath
)
.textFieldStyle(.roundedBorder)
}
}
}

#Preview {
PathToTerminalTextFieldView()
.environmentObject(Preferences())
}
69 changes: 69 additions & 0 deletions ControlRoom/Settings UI/PickersFormView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// PickersFormView.swift
// ControlRoom
//
// Created by Elliot Knight on 11/05/2024.
// Copyright © 2024 Paul Hudson. All rights reserved.
//

import SwiftUI

struct PickersFormView: View {
/// The user's settings for capturing
@AppStorage("captureSettings") var captureSettings = CaptureSettings(imageFormat: .png, videoFormat: .h264, display: .internal, mask: .ignored)

/// Whether the user wants us to render device bezels around their screenshots.
/// Note: this requires a mask of alpha, so we enforce that when true.
@AppStorage("renderChrome") var renderChrome = false

var body: some View {
Form {
Picker("Screenshot Format:", selection: $captureSettings.imageFormat) {
ForEach(SimCtl.IO.ImageFormat.allCases, id: \.self) { type in
Text(type.rawValue.uppercased()).tag(type)
}
}

Picker("Video Format:", selection: $captureSettings.videoFormat) {
ForEach(SimCtl.IO.VideoFormat.all, id: \.self) { item in
if item == .divider {
Divider()
} else {
Text(item.name).tag(item)
}
}
}

Picker("Display:", selection: $captureSettings.display) {
ForEach(SimCtl.IO.Display.allCases, id: \.self) { display in
Text(display.rawValue.capitalized).tag(display)
}
}

Picker("Mask:", selection: $captureSettings.mask) {
ForEach(SimCtl.IO.Mask.allCases, id: \.self) { mask in
Text(mask.rawValue.capitalized).tag(mask)
}
}
.disabled(renderChrome)

Toggle(isOn: $renderChrome.onChange(updateChromeSettings)) {
VStack(alignment: .leading) {
Text("Add device chrome to screenshots")
Text("This is an experimental feature and may not function properly yet.")
.font(.caption)
}
}
}
}

private func updateChromeSettings() {
if renderChrome {
captureSettings.mask = .alpha
}
}
}

#Preview {
PickersFormView()
}
Loading
Loading