Skip to content

Commit

Permalink
fix: Show all scales for macOS and iOS icons (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley authored Jan 8, 2023
1 parent d5a579c commit 71e65ca
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 44 deletions.
8 changes: 8 additions & 0 deletions Symbolic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
D83970E528B11F5200282EE8 /* SymbolicError.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83970E428B11F5200282EE8 /* SymbolicError.swift */; };
D83970E728B132C700282EE8 /* UnityScaleWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83970E628B132C700282EE8 /* UnityScaleWindow.swift */; };
D83970E928B1340900282EE8 /* DeviceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = D83970E828B1340900282EE8 /* DeviceType.swift */; };
D84868E8296ACC58009FDF32 /* Header.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84868E7296ACC58009FDF32 /* Header.swift */; };
D84868EA296ACC8B009FDF32 /* IconPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84868E9296ACC8B009FDF32 /* IconPreview.swift */; };
D864A23A2965A2D1008A4261 /* Interact in Frameworks */ = {isa = PBXBuildFile; productRef = D864A2392965A2D1008A4261 /* Interact */; };
D864A23C2965E239008A4261 /* MacIconView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D864A23B2965E239008A4261 /* MacIconView.swift */; };
D86B0ECF291BEF7400352367 /* IconDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = D86B0ECE291BEF7400352367 /* IconDocument.swift */; };
Expand Down Expand Up @@ -69,6 +71,8 @@
D83970E428B11F5200282EE8 /* SymbolicError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolicError.swift; sourceTree = "<group>"; };
D83970E628B132C700282EE8 /* UnityScaleWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnityScaleWindow.swift; sourceTree = "<group>"; };
D83970E828B1340900282EE8 /* DeviceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceType.swift; sourceTree = "<group>"; };
D84868E7296ACC58009FDF32 /* Header.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Header.swift; sourceTree = "<group>"; };
D84868E9296ACC8B009FDF32 /* IconPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconPreview.swift; sourceTree = "<group>"; };
D864A2382965999C008A4261 /* interact */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = interact; sourceTree = "<group>"; };
D864A23B2965E239008A4261 /* MacIconView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacIconView.swift; sourceTree = "<group>"; };
D86B0ECE291BEF7400352367 /* IconDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconDocument.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -154,6 +158,8 @@
D864A23B2965E239008A4261 /* MacIconView.swift */,
D821B9ED28ACDC6F00504AA4 /* SymbolPicker.swift */,
D83970E628B132C700282EE8 /* UnityScaleWindow.swift */,
D84868E7296ACC58009FDF32 /* Header.swift */,
D84868E9296ACC8B009FDF32 /* IconPreview.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -441,7 +447,9 @@
D8D9731128ACF8D2006CBF15 /* ExportToolbar.swift in Sources */,
D83970E728B132C700282EE8 /* UnityScaleWindow.swift in Sources */,
D83970E228B0B45300282EE8 /* Color.swift in Sources */,
D84868EA296ACC8B009FDF32 /* IconPreview.swift in Sources */,
D821B9E028ACDB6000504AA4 /* View.swift in Sources */,
D84868E8296ACC58009FDF32 /* Header.swift in Sources */,
D8CD4A7E28AC35C300D57F34 /* SymbolicApp.swift in Sources */,
D8B6130A293BB98100F29E0C /* ApplicationModel.swift in Sources */,
D864A23C2965E239008A4261 /* MacIconView.swift in Sources */,
Expand Down
55 changes: 40 additions & 15 deletions Symbolic/Toolbars/ExportToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@

import SwiftUI

struct IconDefinition {
struct IconDefinition: Identifiable {

enum Style {
case macOS
case iOS
case watchOS
}

var id = UUID()

let style: Style
let size: CGSize
let scales: [CGFloat]
let description: String?

init(_ size: CGFloat, scales: [CGFloat]) {
init(_ style: Style, size: CGFloat, scales: [CGFloat], description: String? = nil) {
self.style = style
self.size = CGSize(width: size, height: size)
self.scales = scales
}

}

extension IconDefinition: Identifiable {

var id: CGFloat {
return size.width
self.description = description
}

}
Expand All @@ -47,11 +51,32 @@ struct ExportToolbar: CustomizableToolbarContent {
static let icons: [String:[IconDefinition]] = [

"macOS": [
IconDefinition(16, scales: [1, 2]),
IconDefinition(32, scales: [1, 2]),
IconDefinition(128, scales: [1, 2]),
IconDefinition(256, scales: [1, 2]),
IconDefinition(512, scales: [1, 2]),
IconDefinition(.macOS, size: 16, scales: [1, 2]),
IconDefinition(.macOS, size: 32, scales: [1, 2]),
IconDefinition(.macOS, size: 128, scales: [1, 2]),
IconDefinition(.macOS, size: 256, scales: [1, 2]),
IconDefinition(.macOS, size: 512, scales: [1, 2]),
],

"iOS": [

// iPhone
IconDefinition(.iOS, size: 20, scales: [2, 3], description: "iPhone Notifications"),
IconDefinition(.iOS, size: 29, scales: [2, 3], description: "iPhone Settings"),
IconDefinition(.iOS, size: 40, scales: [2, 3], description: "iPhone Spotlight"),
IconDefinition(.iOS, size: 60, scales: [2, 3], description: "iPhone App"),

// iPad
IconDefinition(.iOS, size: 20, scales: [1, 2], description: "iPad Notifications"),
IconDefinition(.iOS, size: 29, scales: [1, 2], description: "iPad Settings"),
IconDefinition(.iOS, size: 40, scales: [1, 2], description: "iPad Spotlight"),
IconDefinition(.iOS, size: 76, scales: [1, 2], description: "iPad App"),
IconDefinition(.iOS, size: 83.5, scales: [2, 3], description: "iPad Pro (12.9-inch) App"),

IconDefinition(.iOS, size: 1024, scales: [1], description: "App Store"),
],

"watchOS": [
]

]
Expand Down
36 changes: 7 additions & 29 deletions Symbolic/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,37 +35,15 @@ struct ContentView: View {
HStack(spacing: 0) {
ScrollView {
VStack {
Text("macOS")
.foregroundColor(.secondary)
.horizontalSpace(.leading)
Divider()
ForEach(ExportToolbar.icons["macOS"]!) { icon in
ZStack {
MacIconView(icon: document.icon, size: icon.size.width, isShadowFlipped: false)
if showGrid {
Image("Grid_macOS")
.resizable()
.frame(width: icon.size.width, height: icon.size.height)
}
}
Text("\(Int(icon.size.width))pt")
.foregroundColor(.secondary)
Header("macOS")
ForEach(ExportToolbar.icons["macOS"]!) { definition in
IconPreview(icon: document.icon, definition: definition, showGrid: showGrid)
}
Text("iOS")
.foregroundColor(.secondary)
.horizontalSpace(.leading)
Divider()
ZStack {
IconView(icon: document.icon, size: 512, renderShadow: false)
.modifier(IconCorners(size: 512))
if showGrid {
Image("Grid_iOS")
}
Header("iOS")
ForEach(ExportToolbar.icons["iOS"]!) { definition in
IconPreview(icon: document.icon, definition: definition, showGrid: showGrid)
}
Text("watchOS")
.foregroundColor(.secondary)
.horizontalSpace(.leading)
Divider()
Header("watchOS")
IconView(icon: document.icon, size: 512, renderShadow: false)
.clipShape(Circle())
}
Expand Down
41 changes: 41 additions & 0 deletions Symbolic/Views/Header.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2022-2023 InSeven Limited
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import SwiftUI

struct Header: View {

let text: String

init(_ text: String) {
self.text = text
}

var body: some View {
VStack {
Text(text)
.fontWeight(.bold)
.foregroundColor(.secondary)
.horizontalSpace(.leading)
Divider()
}
}

}
70 changes: 70 additions & 0 deletions Symbolic/Views/IconPreview.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) 2022-2023 InSeven Limited
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import SwiftUI

struct IconPreview: View {

let icon: Icon
let definition: IconDefinition
let showGrid: Bool

var body: some View {
VStack {
HStack(alignment: .bottom, spacing: 16) {
ForEach(definition.scales, id: \.self) { scale in
let width = definition.size.width * (scale / 2)
let height = definition.size.height * (scale / 2)
VStack {
ZStack {
switch definition.style {
case .macOS:
MacIconView(icon: icon, size: width, isShadowFlipped: false)
if showGrid {
Image("Grid_macOS")
.resizable()
.frame(width: width, height: height)
}
case .iOS:
IconView(icon: icon, size: width, renderShadow: false)
.modifier(IconCorners(size: width))
if showGrid {
Image("Grid_iOS")
.resizable()
.frame(width: width, height: height)
}
case .watchOS:
Text("WATCH")
}
}
Text("\(Int(scale))x")
}
}
}
Divider()
if let description = definition.description {
Text(description)
}
Text("\(Int(definition.size.width))pt")
}
.foregroundColor(.secondary)
}

}

0 comments on commit 71e65ca

Please sign in to comment.