Skip to content

Ensure proper method(s) are supportive of cross-platform swift 6 support #108

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

Closed
wants to merge 11 commits into from
Closed
22 changes: 11 additions & 11 deletions Examples/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@
"version" : "1.6.45"
}
},
{
"identity" : "libwebp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/the-swift-collective/libwebp",
"state" : {
"revision" : "5f745a17b9a5c2a4283f17c2cde4517610ab5f99",
"version" : "1.4.1"
}
},
{
"identity" : "pathkit",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -130,8 +139,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/swift-image-formats",
"state" : {
"revision" : "05a0169a2a5e9365a058e9aa13da5937be6e2586",
"version" : "0.3.1"
"revision" : "697bd8aa62bef7d74a1383454e3534a527769e41",
"version" : "0.3.2"
}
},
{
Expand All @@ -143,15 +152,6 @@
"version" : "0.4.0"
}
},
{
"identity" : "swift-libwebp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/swift-libwebp",
"state" : {
"revision" : "61dc3787c764022ad2f5ab4f9994a569afe86f9f",
"version" : "0.2.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
Expand Down
24 changes: 12 additions & 12 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "9bdf10c7a21892e3f103174fa966d5a212af3dfca1608849b243319bfbb3d005",
"originHash" : "d7660de3524ddfd94fb5ed75c380bbcda1ec9d99cc0b74dee8d2f70756063c78",
"pins" : [
{
"identity" : "jpeg",
Expand All @@ -19,6 +19,15 @@
"version" : "1.6.45"
}
},
{
"identity" : "libwebp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/the-swift-collective/libwebp",
"state" : {
"revision" : "5f745a17b9a5c2a4283f17c2cde4517610ab5f99",
"version" : "1.4.1"
}
},
{
"identity" : "swift-cwinrt",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -51,17 +60,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/swift-image-formats",
"state" : {
"revision" : "05a0169a2a5e9365a058e9aa13da5937be6e2586",
"version" : "0.3.1"
}
},
{
"identity" : "swift-libwebp",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stackotter/swift-libwebp",
"state" : {
"revision" : "61dc3787c764022ad2f5ab4f9994a569afe86f9f",
"version" : "0.2.0"
"revision" : "697bd8aa62bef7d74a1383454e3534a527769e41",
"version" : "0.3.2"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let package = Package(
),
.package(
url: "https://github.com/stackotter/swift-image-formats",
.upToNextMinor(from: "0.3.1")
.upToNextMinor(from: "0.3.2")
),
.package(
url: "https://github.com/wabiverse/swift-windowsappsdk",
Expand Down
123 changes: 123 additions & 0 deletions Sources/AppKitBackend/BaseWidget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import AppKit

public class BaseWidget: NSView {
private var leftConstraint: NSLayoutConstraint?
private var topConstraint: NSLayoutConstraint?
private var widthConstraint: NSLayoutConstraint?
private var heightConstraint: NSLayoutConstraint?

var x = 0 {
didSet {
if x != oldValue {
updateLeftConstraint()
}
}
}

var y = 0 {
didSet {
if y != oldValue {
updateTopConstraint()
}
}
}

var width = 0 {
didSet {
if width != oldValue {
updateWidthConstraint()
}
}
}

var height = 0 {
didSet {
if height != oldValue {
updateHeightConstraint()
}
}
}

init() {
super.init(frame: .zero)

self.translatesAutoresizingMaskIntoConstraints = false
}

@available(*, unavailable)
public required init?(coder: NSCoder) {
fatalError("init(coder:) is not used for this view")
}

private func updateLeftConstraint() {
leftConstraint?.isActive = false
guard let superview else { return }
if #available(macOS 11.0, *) {
leftConstraint = self.leftAnchor.constraint(
equalTo: superview.safeAreaLayoutGuide.leftAnchor, constant: CGFloat(x))
} else {
leftConstraint = self.leftAnchor.constraint(
equalTo: superview.leftAnchor, constant: CGFloat(x))
}
leftConstraint!.isActive = true
}

private func updateTopConstraint() {
topConstraint?.isActive = false
guard let superview else { return }
if #available(macOS 11.0, *) {
topConstraint = self.topAnchor.constraint(
equalTo: superview.safeAreaLayoutGuide.topAnchor, constant: CGFloat(x))
} else {
topConstraint = self.topAnchor.constraint(
equalTo: superview.topAnchor, constant: CGFloat(x))
}
topConstraint!.isActive = true
}

private func updateWidthConstraint() {
widthConstraint?.isActive = false
widthConstraint = self.widthAnchor.constraint(equalToConstant: CGFloat(width))
widthConstraint!.isActive = true
}

private func updateHeightConstraint() {
heightConstraint?.isActive = false
heightConstraint = self.heightAnchor.constraint(equalToConstant: CGFloat(height))
heightConstraint!.isActive = true
}

public override func viewDidMoveToSuperview() {
super.viewDidMoveToSuperview()

updateLeftConstraint()
updateTopConstraint()
}
}

class WrapperWidget<View: NSView>: BaseWidget {
init(child: View) {
super.init()

self.addSubview(child)
child.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
child.topAnchor.constraint(equalTo: self.topAnchor),
child.leadingAnchor.constraint(equalTo: self.leadingAnchor),
child.bottomAnchor.constraint(equalTo: self.bottomAnchor),
child.trailingAnchor.constraint(equalTo: self.trailingAnchor),
])
}

override convenience init() {
self.init(child: View(frame: .zero))
}

var child: View {
subviews[0] as! View
}

override var intrinsicContentSize: CGSize {
child.intrinsicContentSize
}
}
Loading
Loading