Skip to content

Commit

Permalink
Add ValueStepper to emulate UIStepper since UIStepper doesn't work wi…
Browse files Browse the repository at this point in the history
…th Mac Catalyst
  • Loading branch information
vincode-io committed Dec 30, 2023
1 parent 57c8972 commit 0a08c0b
Show file tree
Hide file tree
Showing 8 changed files with 558 additions and 62 deletions.
4 changes: 4 additions & 0 deletions Zavala.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
511EC2BF2B3F58E0002D89A5 /* SettingsSceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 511EC2BE2B3F58E0002D89A5 /* SettingsSceneDelegate.swift */; };
511EC2C12B3F5AA7002D89A5 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 511EC2C02B3F5AA7002D89A5 /* SettingsViewController.swift */; };
511EC2C52B3F8F29002D89A5 /* SettingsAdvancedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 511EC2C42B3F8F29002D89A5 /* SettingsAdvancedView.swift */; };
511EC2C72B409A5B002D89A5 /* ValueStepper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 511EC2C62B409A5B002D89A5 /* ValueStepper.swift */; };
512229682563507E008041AF /* EditorRowViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 512229672563507E008041AF /* EditorRowViewCell.swift */; };
5125D01A26BE181500703DA4 /* SpotlightIndexExtension.appex in Embed PlugIns */ = {isa = PBXBuildFile; fileRef = 515D452026BB553600228229 /* SpotlightIndexExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
5126E7572AEF484000015491 /* VinOutlineKit in Frameworks */ = {isa = PBXBuildFile; productRef = 5126E7562AEF484000015491 /* VinOutlineKit */; };
Expand Down Expand Up @@ -252,6 +253,7 @@
511EC2BE2B3F58E0002D89A5 /* SettingsSceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSceneDelegate.swift; sourceTree = "<group>"; };
511EC2C02B3F5AA7002D89A5 /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
511EC2C42B3F8F29002D89A5 /* SettingsAdvancedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAdvancedView.swift; sourceTree = "<group>"; };
511EC2C62B409A5B002D89A5 /* ValueStepper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ValueStepper.swift; sourceTree = "<group>"; };
512229672563507E008041AF /* EditorRowViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorRowViewCell.swift; sourceTree = "<group>"; };
51278E76257F37AC0034F1CB /* Dialog.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Dialog.storyboard; sourceTree = "<group>"; };
512D375025EEFC01000FA597 /* Zavala-dev.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Zavala-dev.entitlements"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -483,6 +485,7 @@
519184F227107FDA00B7E177 /* UITextView+.swift */,
51DEE82726FF951E006DAA56 /* UIWindowSceneDelegate+.swift */,
51E14F372560738E00320EDB /* UpdateSelectionOperation.swift */,
511EC2C62B409A5B002D89A5 /* ValueStepper.swift */,
);
path = Utility;
sourceTree = "<group>";
Expand Down Expand Up @@ -1107,6 +1110,7 @@
51F2859725AD11DB0019C573 /* CollectionsSearchContentConfiguration.swift in Sources */,
51918515271664FB00B7E177 /* AddRowsIntentHandler.swift in Sources */,
5115C0362605F96100416D67 /* MacOpenQuicklyDocumentsViewController.swift in Sources */,
511EC2C72B409A5B002D89A5 /* ValueStepper.swift in Sources */,
5142C295260AC78C0094571F /* OutlineFontConfig.swift in Sources */,
51C71C78273FFA6700F6C779 /* EditorRowContentView.swift in Sources */,
517A9E432605558700EF346A /* MacOpenQuicklyViewController.swift in Sources */,
Expand Down
118 changes: 75 additions & 43 deletions Zavala/Settings/Settings.storyboard

Large diffs are not rendered by default.

43 changes: 25 additions & 18 deletions Zavala/Settings/SettingsFontConfigViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class SettingsFontConfigViewController: UITableViewController {

var field: OutlineFontField?
var config: OutlineFontConfig?
weak var delegate: SettingsFontConfigViewControllerDelegate?

@IBOutlet weak var doneBarButtonItem: UIBarButtonItem!
@IBOutlet weak var fontNameLabel: UILabel!
@IBOutlet weak var fontSizeLabel: UILabel!
@IBOutlet weak var fontSizeStepper: UIStepper!
@IBOutlet weak var cancelBarButtonItem: UIBarButtonItem!
@IBOutlet weak var saveBarButtonItem: UIBarButtonItem!

@IBOutlet weak var fontButton: UIButton!
@IBOutlet weak var fontValueStepper: ValueStepper!
@IBOutlet weak var sampleTextLabel: UILabel!

override func viewDidLoad() {
Expand All @@ -29,38 +29,45 @@ class SettingsFontConfigViewController: UITableViewController {
if let field,
let outlineFonts = AppDefaults.shared.outlineFonts,
!outlineFonts.rowFontConfigs.keys.contains(field) {
doneBarButtonItem.title = AppStringAssets.addControlLabel
saveBarButtonItem.title = AppStringAssets.addControlLabel
}

if UIDevice.current.userInterfaceIdiom == .mac {
fontValueStepper.widthAnchor.constraint(equalToConstant: 80).isActive = true
fontValueStepper.heightAnchor.constraint(equalToConstant: 19).isActive = true
} else {
fontValueStepper.widthAnchor.constraint(equalToConstant: 149).isActive = true
fontValueStepper.heightAnchor.constraint(equalToConstant: 29).isActive = true
}

navigationItem.title = field?.displayName
fontNameLabel.text = config?.name
fontSizeLabel.text = String(config?.size ?? 0)
// fontSizeStepper.value = Double(config?.size ?? 0)
fontButton.setTitle(config?.name, for: .normal)
fontValueStepper.value = Double(config?.size ?? 0)

updateUI()
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 && indexPath.row == 0 {
let controller = UIFontPickerViewController()
controller.delegate = self
present(controller, animated: true)
}
tableView.selectRow(at: nil, animated: true, scrollPosition: .none)
}

@IBAction func changeFont(_ sender: Any) {
let controller = UIFontPickerViewController()
controller.delegate = self
present(controller, animated: true)
}

@IBAction func fontSizeChanged(_ sender: Any) {
let stepValue = Int(fontSizeStepper.value)
let stepValue = Int(fontValueStepper.value)
config?.size = stepValue
fontSizeLabel.text = String(stepValue)
updateUI()
}

@IBAction func cancel(_ sender: Any) {
dismiss(animated: true)
}

@IBAction func done(_ sender: Any) {
@IBAction func save(_ sender: Any) {
guard let field = field, let config = config else { return }

var fontDefaults = AppDefaults.shared.outlineFonts
Expand All @@ -79,7 +86,7 @@ extension SettingsFontConfigViewController: UIFontPickerViewControllerDelegate {
func fontPickerViewControllerDidPickFont(_ viewController: UIFontPickerViewController) {
guard let fontName = viewController.selectedFontDescriptor?.fontAttributes[.family] as? String else { return }
viewController.dismiss(animated: true)
fontNameLabel.text = fontName
fontButton.setTitle(fontName, for: .normal)
config?.name = fontName
updateUI()
}
Expand Down
10 changes: 9 additions & 1 deletion Zavala/Settings/SettingsFontsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ struct SettingsFontConfigView: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> UINavigationController {
let navController = UIStoryboard.settings.instantiateViewController(withIdentifier: "SettingsFontConfigViewControllerNav") as! UINavigationController
navController.modalPresentationStyle = .formSheet
navController.preferredContentSize = CGSize(width: 350, height: 350)

if UIDevice.current.userInterfaceIdiom == .mac {
navController.preferredContentSize = CGSize(width: 300, height: 175)
} else {
let contentWidth = UIFontMetrics(forTextStyle: .body).scaledValue(for: 400)
let contentHeight = UIFontMetrics(forTextStyle: .body).scaledValue(for: 250)
navController.preferredContentSize = CGSize(width: contentWidth, height: contentHeight)
}

let controller = navController.topViewController as! SettingsFontConfigViewController
controller.field = fieldConfig?.field
controller.config = fieldConfig?.config
Expand Down
4 changes: 4 additions & 0 deletions Zavala/Settings/SettingsSceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ class SettingsSceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
updateUserInterfaceStyle()

#if targetEnvironment(macCatalyst)
window?.windowScene?.titlebar?.titleVisibility = .hidden
window?.windowScene?.title = AppStringAssets.settingsControlLabel
#endif

window?.windowScene?.sizeRestrictions?.minimumSize = Self.windowSize
window?.windowScene?.sizeRestrictions?.maximumSize = Self.windowSize

Expand Down
1 change: 1 addition & 0 deletions Zavala/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct SettingsView: View {
.onAppear {
let navigationAppearance = UINavigationBarAppearance()
navigationAppearance.configureWithOpaqueBackground()
UINavigationBar.appearance().scrollEdgeAppearance = navigationAppearance
UINavigationBar.appearance().standardAppearance = navigationAppearance
}

Expand Down
2 changes: 2 additions & 0 deletions Zavala/Settings/SettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class SettingsViewController: UIViewController {
view.addChildAndPin(settingsViewController.view)
addChild(settingsViewController)

#if targetEnvironment(macCatalyst)
appDelegate.appKitPlugin?.configureSettings(view.window?.nsWindow)
#endif
}

}
Loading

0 comments on commit 0a08c0b

Please sign in to comment.