From df469354ae0ba579a3a7b47056e74a2f90994cf8 Mon Sep 17 00:00:00 2001 From: LEO Yoon-Tsaw Date: Sat, 30 Oct 2021 14:42:33 -0400 Subject: [PATCH] Add bring to center action --- ChineseTime.xcodeproj/project.pbxproj | 4 ++-- ChineseTime/AppDelegate.swift | 3 +++ ChineseTime/WatchFace.swift | 16 +++++++++------- ChineseTime/en.lproj/Main.storyboard | 12 +++++++++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/ChineseTime.xcodeproj/project.pbxproj b/ChineseTime.xcodeproj/project.pbxproj index 35e9fe0..8fec36f 100644 --- a/ChineseTime.xcodeproj/project.pbxproj +++ b/ChineseTime.xcodeproj/project.pbxproj @@ -302,7 +302,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 24; + CURRENT_PROJECT_VERSION = 25; DEVELOPMENT_TEAM = 28HU5A7B46; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = ChineseTime/Info.plist; @@ -327,7 +327,7 @@ CODE_SIGN_IDENTITY = "-"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 24; + CURRENT_PROJECT_VERSION = 25; DEVELOPMENT_TEAM = 28HU5A7B46; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = ChineseTime/Info.plist; diff --git a/ChineseTime/AppDelegate.swift b/ChineseTime/AppDelegate.swift index fe3a8c1..32a2493 100644 --- a/ChineseTime/AppDelegate.swift +++ b/ChineseTime/AppDelegate.swift @@ -25,6 +25,9 @@ class AppDelegate: NSObject, NSApplicationDelegate { keepTopMenuItem.state = watchFace.isTop ? .on : .off } } + @IBAction func bringCenter(_ sender: Any) { + WatchFace.currentInstance?.setCenter() + } @IBAction func showHelp(_ sender: Any) { NSWorkspace.shared.open(URL(string: "https://github.com/LEOYoon-Tsaw/ChineseTime")!) diff --git a/ChineseTime/WatchFace.swift b/ChineseTime/WatchFace.swift index 960016f..2a5bca0 100644 --- a/ChineseTime/WatchFace.swift +++ b/ChineseTime/WatchFace.swift @@ -847,14 +847,20 @@ class WatchFace: NSWindow { self.isMovableByWindowBackground = true } } - func setTop(_ on: Bool) { if on { self.level = NSWindow.Level.floating } else { - self.level = NSWindow.Level.normal + self.level = NSWindow.Level(rawValue: NSWindow.Level.normal.rawValue - 1) } } + func setCenter() { + let windowRect = self.getCurrentScreen() + self.setFrame(NSMakeRect( + windowRect.midX - _view.watchLayout.watchSize.width / 2, + windowRect.midY - _view.watchLayout.watchSize.height / 2, + _view.watchLayout.watchSize.width, _view.watchLayout.watchSize.height), display: true) + } func getCurrentScreen() -> NSRect { var screenRect = NSScreen.main!.frame @@ -872,11 +878,7 @@ class WatchFace: NSWindow { func updateSize(with frame: NSRect?) { let watchDimension = _view.watchLayout.watchSize if frame == nil { - let windowRect = self.getCurrentScreen() - self.setFrame(NSMakeRect( - windowRect.midX - watchDimension.width / 2, - windowRect.midY - watchDimension.height / 2, - watchDimension.width, watchDimension.height), display: true) + setCenter() } else { self.setFrame(NSMakeRect( frame!.midX - watchDimension.width / 2, diff --git a/ChineseTime/en.lproj/Main.storyboard b/ChineseTime/en.lproj/Main.storyboard index ed1b0d7..6a54606 100644 --- a/ChineseTime/en.lproj/Main.storyboard +++ b/ChineseTime/en.lproj/Main.storyboard @@ -624,6 +624,12 @@ + + + + + + @@ -1211,8 +1217,8 @@ - - + + @@ -1330,7 +1336,7 @@ - +