Skip to content

Commit

Permalink
Dynamic Icon in Welcome
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Jan 30, 2024
1 parent 8ba08a7 commit 9d36300
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 71 deletions.
12 changes: 10 additions & 2 deletions Chinendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
B39B9DC62B57578300D29D60 /* Decoration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B39B9DC52B57578300D29D60 /* Decoration.swift */; };
B39B9DC72B57578300D29D60 /* Decoration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B39B9DC52B57578300D29D60 /* Decoration.swift */; };
B39B9DC82B57578300D29D60 /* Decoration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B39B9DC52B57578300D29D60 /* Decoration.swift */; };
B3AE9B0D2B68924300958D58 /* Icon.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3AE9B0C2B68924300958D58 /* Icon.swift */; };
B3AE9B0E2B68924300958D58 /* Icon.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3AE9B0C2B68924300958D58 /* Icon.swift */; };
B3AE9B0F2B68924300958D58 /* Icon.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3AE9B0C2B68924300958D58 /* Icon.swift */; };
B3BCCEE82A48746000F5745E /* Setting.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3BCCEE72A48746000F5745E /* Setting.swift */; };
B3BEB4C32A48994C000751D5 /* WatchFace.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3BEB4C22A48994C000751D5 /* WatchFace.swift */; };
B3BEB4C42A489A0A000751D5 /* WatchFaceBasics.swift in Sources */ = {isa = PBXBuildFile; fileRef = B36D2F782A047A2000005162 /* WatchFaceBasics.swift */; };
Expand Down Expand Up @@ -368,6 +371,7 @@
B39B905F2B017AB10083D05A /* Chinendar.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Chinendar.entitlements; sourceTree = "<group>"; };
B39B90612B01809A0083D05A /* layout.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = layout.txt; sourceTree = "<group>"; };
B39B9DC52B57578300D29D60 /* Decoration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Decoration.swift; sourceTree = "<group>"; };
B3AE9B0C2B68924300958D58 /* Icon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Icon.swift; sourceTree = "<group>"; };
B3BCCEE72A48746000F5745E /* Setting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Setting.swift; sourceTree = "<group>"; };
B3BEB4C22A48994C000751D5 /* WatchFace.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchFace.swift; sourceTree = "<group>"; };
B3BFA2562A05E0590018F99E /* WatchConnectivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchConnectivity.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -518,6 +522,7 @@
children = (
B36D2F782A047A2000005162 /* WatchFaceBasics.swift */,
B3E1D6E32A0ACD7800F2905A /* WatchFaceView.swift */,
B3AE9B0C2B68924300958D58 /* Icon.swift */,
B3F85EAC2A4A5A0B00F8B40B /* HoverView.swift */,
B32243EF2A0DBEF400E7AED5 /* SwiftUIUtilities.swift */,
B39086112A0317CB00943F2B /* RoundedRect.swift */,
Expand Down Expand Up @@ -1001,6 +1006,7 @@
B39B90562B0179440083D05A /* WatchFaceBasics.swift in Sources */,
B33635262B02FA7B00BA83F7 /* Setting.swift in Sources */,
B39B90662B0181D50083D05A /* RingSetting.swift in Sources */,
B3AE9B0F2B68924300958D58 /* Icon.swift in Sources */,
B39B905A2B0179580083D05A /* Environments.swift in Sources */,
B39B90572B0179470083D05A /* WatchFaceView.swift in Sources */,
B38387A92B08319500A04588 /* Welcome.swift in Sources */,
Expand Down Expand Up @@ -1047,6 +1053,7 @@
B329992E2A4F9C8500B71579 /* LocationManager.swift in Sources */,
B3F85EAE2A4A5A0B00F8B40B /* HoverView.swift in Sources */,
9E6E10CD2AA6410A004CEDBE /* TaskGroup.swift in Sources */,
B3AE9B0E2B68924300958D58 /* Icon.swift in Sources */,
B3515CF129F6149500E6BCDC /* iOSApp.swift in Sources */,
B328333C2A46687D00E36989 /* ColorSetting.swift in Sources */,
9E90D7F02A9EABD100855F2C /* Environments.swift in Sources */,
Expand Down Expand Up @@ -1199,6 +1206,7 @@
9E9889EF2A79EABF0066414A /* WatchPanel.swift in Sources */,
B34DA20929FDC0B200562449 /* Utilities.swift in Sources */,
9ECDCA052A50B6D100E11161 /* Documentation.swift in Sources */,
B3AE9B0D2B68924300958D58 /* Icon.swift in Sources */,
9E90D7EF2A9EABD100855F2C /* Environments.swift in Sources */,
9ECDCA032A50B6CB00E11161 /* ColorSetting.swift in Sources */,
9E71FD042A50BD2A00C9CA78 /* Location.swift in Sources */,
Expand Down Expand Up @@ -1689,7 +1697,7 @@
D2E4E0F326F7C73F002F3716 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APP_BUILD = 117;
APP_BUILD = 119;
APP_VERSION = 5.3;
ASSETCATALOG_COMPILER_APPICON_NAME = "";
ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOL_FRAMEWORKS = SwiftUI;
Expand Down Expand Up @@ -1769,7 +1777,7 @@
D2E4E0F426F7C73F002F3716 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
APP_BUILD = 117;
APP_BUILD = 119;
APP_VERSION = 5.3;
ASSETCATALOG_COMPILER_APPICON_NAME = "";
ASSETCATALOG_COMPILER_GENERATE_ASSET_SYMBOL_FRAMEWORKS = SwiftUI;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h1><a href="https://apps.apple.com/us/app/lunar-time/id1587810157?itscg=30200&amp;itsct=apps_box_appicon" style="width: 1.5em; height: 1.5em; border-radius: 22%; overflow: hidden; display: inline-block; vertical-align: middle"><img src="iOS/Assets.xcassets/Image.imageset/icon 360.png" alt="Chinendar" height="50px" style="width: 1.5em; height: 1.5em; border-radius: 22%; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 20px;"></a><p>華曆/Chinendar</p></h1>
<h1><a href="https://apps.apple.com/us/app/lunar-time/id1587810157?itscg=30200&amp;itsct=apps_box_appicon" style="width: 1.5em; height: 1.5em; border-radius: 22%; overflow: hidden; display: inline-block; vertical-align: middle"><img src="macOS/Assets.xcassets/AppIcon.appiconset/mac 256.png" alt="Chinendar" height="50px" style="width: 1.5em; height: 1.5em; border-radius: 22%; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 20px;"></a><p>華曆/Chinendar</p></h1>

<a href="https://apps.apple.com/us/app/lunar-time/id1587810157?itsct=apps_box_badge&amp;itscg=30200" style="display: inline-block; overflow: hidden; border-radius: 13px; width: 120px; height: 40px;"><img src="https://tools.applemediaservices.com/api/badges/download-on-the-app-store/black/en-us?size=250x83&amp;releaseDate=1682553600" alt="Download on the App Store" style="border-radius: 13px; width: 120; height: 40px;"></a>

Expand Down
17 changes: 14 additions & 3 deletions Shared/Setting/ThemesList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ struct ThemesList: View {
@State private var newName = ""
@State private var errorMsg = ""
@State private var target: ThemeData? = nil
var targetName: String {
if let name = target?.name {
if name == AppInfo.defaultName {
return NSLocalizedString("常用", comment: "")
} else {
return name
}
} else {
return ""
}
}
private var invalidName: Bool {
let diviceName = target?.deviceName ?? currentDeviceName
return !validateName(newName, onDevice: diviceName)
Expand Down Expand Up @@ -293,7 +304,7 @@ struct ThemesList: View {
} message: {
Text("不得爲空,不得重名", comment: "no blank, no duplicate name")
}
.alert((target != nil && !target!.isNil) ? (NSLocalizedString("換爲:", comment: "Confirm to select theme message") + target!.name!) : NSLocalizedString("換不得", comment: "Cannot switch theme"), isPresented: $switchAlert) {
.alert((target != nil && !target!.isNil) ? (NSLocalizedString("換爲:", comment: "Confirm to select theme message") + targetName) : NSLocalizedString("換不得", comment: "Cannot switch theme"), isPresented: $switchAlert) {
Button(NSLocalizedString("容吾三思", comment: "Cancel adding Settings"), role: .cancel) { target = nil }
Button(NSLocalizedString("吾意已決", comment: "Confirm Resetting Settings"), role: .destructive) {
if let target = target, !target.isNil {
Expand All @@ -314,7 +325,7 @@ struct ThemesList: View {
}
}
}
.alert((target != nil && !target!.isNil) ? (NSLocalizedString("刪:", comment: "Confirm to delete theme message") + target!.name!) : NSLocalizedString("刪不得", comment: "Cannot delete theme"), isPresented: $deleteAlert) {
.alert((target != nil && !target!.isNil) ? (NSLocalizedString("刪:", comment: "Confirm to delete theme message") + targetName) : NSLocalizedString("刪不得", comment: "Cannot delete theme"), isPresented: $deleteAlert) {
Button(NSLocalizedString("容吾三思", comment: "Cancel adding Settings"), role: .cancel) { target = nil }
Button(NSLocalizedString("吾意已決", comment: "Confirm Resetting Settings"), role: .destructive) {
if let target = target {
Expand Down Expand Up @@ -345,7 +356,7 @@ struct ThemesList: View {
.fileExporter(isPresented: $isExporting,
document: TextDocument(target?.code),
contentType: .text,
defaultFilename: target?.name.map {"\($0).txt"}) { result in
defaultFilename: "\(targetName).txt") { result in
target = nil
if case .failure(let error) = result {
errorMsg = error.localizedDescription
Expand Down
51 changes: 51 additions & 0 deletions Shared/Views/Icon.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// Icon.swift
// Chinendar
//
// Created by Leo Liu on 1/29/24.
//

import SwiftUI

struct Icon: View {
static let frameOffset: CGFloat = 0.03
@Environment(\.colorScheme) var colorScheme
let watchLayout: WatchLayout
let widthScale = 1.5

init(watchLayout: WatchLayout) {
self.watchLayout = watchLayout
}

var body: some View {
let coreColor = colorScheme == .dark ? watchLayout.innerColorDark : watchLayout.innerColor
let backColor = colorScheme == .dark ? watchLayout.backColorDark : watchLayout.backColor
let clearColor = CGColor(gray: 0, alpha: 0)
let shadowDirection = 0.62

GeometryReader { proxy in

let size = proxy.size
let shortEdge = min(size.width, size.height)
let cornerSize = watchLayout.cornerRadiusRatio * shortEdge
let outerBound = RoundedRect(rect: CGRect(origin: .zero, size: size), nodePos: cornerSize, ankorPos: cornerSize * 0.2)
let firstRingOuter = outerBound.shrink(by: ZeroRing.width * shortEdge * widthScale)
let secondRingOuter = firstRingOuter.shrink(by: Ring.paddedWidth * shortEdge * widthScale)
let innerBound = secondRingOuter.shrink(by: Ring.paddedWidth * shortEdge * widthScale)

ZStack {

Ring(width: Ring.paddedWidth * widthScale, viewSize: size, compact: false, ticks: ChineseCalendar.Ticks(), startingAngle: 0, angle: 0.3, textFont: WatchFont(watchLayout.textFont), textColor: clearColor, alpha: watchLayout.shadeAlpha, majorTickAlpha: 1, minorTickAlpha: 1, majorTickColor: clearColor, minorTickColor: clearColor, backColor: backColor, gradientColor: watchLayout.firstRing, outerRing: firstRingOuter, marks: [], shadowDirection: shadowDirection, entityNotes: nil, shadowSize: watchLayout.shadowSize, highlightType: .flicker, offset: .zero)
Ring(width: Ring.paddedWidth * widthScale, viewSize: size, compact: false, ticks: ChineseCalendar.Ticks(), startingAngle: 0, angle: 0.45, textFont: WatchFont(watchLayout.textFont), textColor: clearColor, alpha: watchLayout.shadeAlpha, majorTickAlpha: 1, minorTickAlpha: 1, majorTickColor: clearColor, minorTickColor: clearColor, backColor: backColor, gradientColor: watchLayout.secondRing, outerRing: secondRingOuter, marks: [], shadowDirection: shadowDirection, entityNotes: nil, shadowSize: watchLayout.shadowSize, highlightType: .flicker, offset: .zero)
Core(viewSize: size, dateString: "", timeString: "", font: WatchFont(watchLayout.centerFont), maxLength: 5, textColor: watchLayout.centerFontColor, outerBound: innerBound, innerColor: coreColor, backColor: backColor, centerOffset: 0, shadowDirection: shadowDirection, shadowSize: watchLayout.shadowSize)
}
}
}
}

#Preview("Icon") {
let watchLayout = WatchLayout.shared
watchLayout.loadStatic()
return Icon(watchLayout: watchLayout)
.frame(width: 120, height: 120)
}
23 changes: 0 additions & 23 deletions Vision/Assets.xcassets/Image.imageset/Contents.json

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions Vision/Views/Welcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwiftUI
struct Welcome: View {
let size: CGSize
@Environment(\.dismiss) var dismiss
@Environment(\.watchLayout) var watchLayout

var body: some View {
let baseLength = min(size.width, size.height)
Expand All @@ -18,8 +19,7 @@ struct Welcome: View {
VStack(spacing: baseLength / 25) {
Spacer(minLength: baseLength / 50)
.frame(maxHeight: baseLength / 25)
Image(.image)
.resizable()
Icon(watchLayout: watchLayout)
.frame(width: baseLength / 4, height: baseLength / 4)
Text("華曆", comment: "Chinendar")
.font(.largeTitle.bold())
Expand Down
23 changes: 0 additions & 23 deletions iOS/Assets.xcassets/Image.imageset/Contents.json

This file was deleted.

Binary file removed iOS/Assets.xcassets/Image.imageset/icon 240.png
Binary file not shown.
Binary file removed iOS/Assets.xcassets/Image.imageset/icon 360.png
Binary file not shown.
4 changes: 2 additions & 2 deletions iOS/Views/Welcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import SwiftUI

struct Welcome: View {
@Environment(\.dismiss) var dismiss
@Environment(\.watchLayout) var watchLayout

var body: some View {
VStack {
ScrollView {
VStack(spacing: 20) {
Spacer(minLength: 10)
.frame(maxHeight: 20)
Image(.image)
.resizable()
Icon(watchLayout: watchLayout)
.frame(width: 120, height: 120)
Text("華曆", comment: "Chinendar")
.font(.largeTitle.bold())
Expand Down
15 changes: 2 additions & 13 deletions macOS/Assets.xcassets/Image.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
{
"images" : [
{
"filename" : "icon 120.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "icon 240.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "icon 360.png",
"idiom" : "universal",
"scale" : "3x"
"filename" : "icon.png",
"idiom" : "universal"
}
],
"info" : {
Expand Down
Binary file removed macOS/Assets.xcassets/Image.imageset/icon 120.png
Binary file not shown.
Binary file removed macOS/Assets.xcassets/Image.imageset/icon 240.png
Binary file not shown.
Binary file removed macOS/Assets.xcassets/Image.imageset/icon 360.png
Binary file not shown.
4 changes: 2 additions & 2 deletions macOS/Views/Welcome.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import SwiftUI

struct Welcome: View {
@Environment(\.dismiss) var dismiss
@Environment(\.watchLayout) var watchLayout

var body: some View {
VStack(spacing: 20) {
Image(.image)
.resizable()
Icon(watchLayout: watchLayout)
.frame(width: 120, height: 120)
Text("華曆", comment: "Chinendar")
.font(.largeTitle.bold())
Expand Down

0 comments on commit 9d36300

Please sign in to comment.