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

Artboards structure #254

Merged
merged 54 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a9b4150
Extract content view subclass
akaDuality Apr 7, 2023
ae5586a
Set frame outside of image function
akaDuality Apr 7, 2023
e17c2ee
Do not flip coordinates
akaDuality Apr 7, 2023
4e963ed
Fix text recognition from image
akaDuality Apr 7, 2023
5938b03
Remove code
akaDuality Apr 7, 2023
06e507e
Move frames to document
akaDuality Apr 7, 2023
2a98866
Refactor image fitting
akaDuality Apr 9, 2023
bf47dcb
Read stubbed file
akaDuality Apr 9, 2023
254a576
Add controls to Frame
akaDuality Apr 9, 2023
c84b3b0
Rework file saving to support frames
akaDuality Apr 9, 2023
4d4b91f
Fix selection
akaDuality Apr 9, 2023
3a0c6a0
Rename document to AppleDocument
akaDuality Apr 9, 2023
8bc6138
Wrap frames in `Artboard` domain object
akaDuality Apr 9, 2023
c272d17
Present frames at navigator
akaDuality Apr 9, 2023
3f65197
Fix test’s build
akaDuality Apr 15, 2023
ebaa4ff
Refactor cursors
akaDuality Apr 15, 2023
24a67c5
Draw background images of frames on CALayer
akaDuality Apr 15, 2023
c3c69bb
Restore image recognition
akaDuality Apr 15, 2023
7fe5248
Fix tests
akaDuality Apr 15, 2023
dafc827
Use artboard to publish events
akaDuality Apr 15, 2023
6633178
Test: when add image it creates a frame
akaDuality Apr 16, 2023
2e099bc
Disable tests and mark code as deprecated
akaDuality Apr 16, 2023
f025c12
Remove image property from document
akaDuality Apr 16, 2023
ccae145
When draw an element inside frame should add to frames
akaDuality Apr 16, 2023
1437384
Rename frame’s `controls` to `elements`
akaDuality Apr 16, 2023
fd23186
Rearrange files
akaDuality Apr 16, 2023
d04c623
Extract Artboard package
akaDuality Apr 16, 2023
b4cb683
Refactor grouping
akaDuality Apr 16, 2023
b219df6
Add parent property that simplifies deleting of any element
akaDuality Apr 16, 2023
8c08df7
Show element’s outside of frames at Navigator
akaDuality Apr 16, 2023
7a270c4
Remove image property
akaDuality Apr 17, 2023
eda1c5b
Add undo to removing
akaDuality Apr 17, 2023
c55fb72
Fix tests in document
akaDuality May 6, 2023
d4e0039
Simplify couple of tests
akaDuality May 6, 2023
8c73cd2
Restore document persistance tests
akaDuality May 6, 2023
c12e7df
Fix translating tests
akaDuality May 7, 2023
9ade85e
Fix CanvasUpdatingTests
akaDuality May 7, 2023
607b6cf
Add empty file to allow target creation
akaDuality May 7, 2023
46971a9
Fix build for Preview
akaDuality May 7, 2023
6283ed9
Fix build of Preview’s test
akaDuality May 7, 2023
ce8ac7c
Fix build for preview
akaDuality May 7, 2023
042574b
Can fit scale according to width and height
akaDuality May 7, 2023
374fc7b
Move elements inside container during MoveAction
akaDuality May 7, 2023
45da205
Allow to select frame
akaDuality May 8, 2023
931ff46
Add encoding for containers
akaDuality May 8, 2023
c8af3fc
Read file in artboard format
akaDuality May 8, 2023
5dacadd
Add support for 3 version of files
akaDuality May 8, 2023
5df9f07
Fix image loading for all formats
akaDuality May 8, 2023
2117ff0
Add shared constructor for Image from data
akaDuality May 8, 2023
4cd47e7
Fix build for Preview
akaDuality May 8, 2023
0a76201
Update gitignore
akaDuality May 8, 2023
272ac27
fix compile error within closure
drucelweisse May 9, 2023
4888d10
Support relative path for images
akaDuality May 9, 2023
be23471
Add thumbnail test for artboard
akaDuality May 9, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/
.DS_Store
15 changes: 14 additions & 1 deletion Shared/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,33 @@ let package = Package(
.package(url: "[email protected]:apple/swift-argument-parser.git", from: "1.2.1"),
],
targets: [
.target(
name: "Artboard"
),
.testTarget(
name: "ArtboardTests",
dependencies: [
"Artboard"
]
),
.target(
name: "Document",
dependencies: [
"Artboard",
.productItem(name: "CustomDump", package: "swift-custom-dump"),
]),
.target(
name: "DocumentTestHelpers",
dependencies: ["Document"],
dependencies: [
"Artboard",
"Document"],
path: "TestHelpers/DocumentTestHelpers",
resources: [
.process("Samples/screenWith3xScale.png"),
.copy("Samples/BetaVersionFormat.vodesign"),
.copy("Samples/FrameVersionFormat.vodesign"),
.copy("Samples/FrameVersionFormatWithHeicPreview.vodesign"),
.copy("Samples/ArtboardFormat.vodesign"),
]
),
.testTarget(
Expand Down
30 changes: 30 additions & 0 deletions Shared/Sources/Artboard/AccessibilityViews.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Foundation

public enum ArtboardType: String, Codable {
case element
case container
case frame
}

public protocol ArtboardElement: AnyObject, Equatable {
var label: String { get set }
var frame: CGRect { get set }

var type: ArtboardType { get }

/// Had to be `weak`
var parent: (any ArtboardContainer)? { get set }
}

public protocol ArtboardContainer: ArtboardElement {
var elements: [any ArtboardElement] { get set }
}

/// Allows
public protocol InstantiatableContainer {
init(
elements: [any ArtboardElement],
frame: CGRect,
label: String
)
}
101 changes: 101 additions & 0 deletions Shared/Sources/Artboard/Artboard.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import CoreGraphics

import Foundation

#if os(iOS)
import UIKit
public typealias Image = UIImage
public extension Image {
convenience init?(path: URL) {
self.init(contentsOfFile: path.path)
}
}

#elseif os(macOS)
import AppKit
public typealias Image = NSImage
public extension Image {
convenience init?(path: URL) {
self.init(contentsOf: path)
}
}
#endif

/// Data layer with hierarchical structure if element
public class Artboard {
// let figmaURL: String
public var frames: [Frame]
public var controlsWithoutFrames: [any ArtboardElement]

public init(
frames: [Frame] = [],
controlsWithoutFrames: [any ArtboardElement] = []) {
self.frames = frames
self.controlsWithoutFrames = controlsWithoutFrames
}

public var imageLoader: ImageLoading!
}

/// Domain object that is used for drawing
public class Frame: ArtboardContainer {
public var type: ArtboardType = .frame

public var label: String
public var imageLocation: ImageLocation
public var frame: CGRect

/// In absolute coordinates
public var elements: [any ArtboardElement]
public var parent: (any ArtboardContainer)? = nil

public convenience init(
label: String,
imageName: String,
frame: CGRect,
elements: [any ArtboardElement]
) {
self.init(label: label,
imageLocation: .file(name: imageName),
frame: frame,
elements: elements)
}

public init(
label: String,
imageLocation: ImageLocation,
frame: CGRect,
elements: [any ArtboardElement]
) {
self.label = label
self.imageLocation = imageLocation
self.frame = frame
self.elements = elements

for element in elements {
element.parent = self
}
}

// MARK: ArtboardElement
public static func == (lhs: Frame, rhs: Frame) -> Bool {
lhs.label == rhs.label // TODO: Better comparison
}
}

public enum ImageLocation: Codable {
case file(name: String)
case url(url: URL)
}

public protocol ImageLoading {
func image(for frame: Frame) -> Image?
}

public class DummyImageLoader: ImageLoading {
public init() {}

public func image(for frame: Frame) -> Image? {
return nil
}
}
4 changes: 2 additions & 2 deletions Shared/Sources/Canvas/A11yControlLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class A11yControlLayer: CALayer {

private let config = Config()

public var model: (any AccessibilityView)?
public var model: (any ArtboardElement)?

public lazy var label: CATextLayer? = {
let label = CATextLayer()
Expand Down Expand Up @@ -70,7 +70,7 @@ public class A11yControlLayer: CALayer {
}

public extension A11yControlLayer {
static func copy(from model: any AccessibilityView) -> A11yControlLayer {
static func copy(from model: any ArtboardElement) -> A11yControlLayer {
let control = A11yControlLayer()
control.model = model
control.frame = model.frame
Expand Down
Loading