-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from li3zhen1/GraphProxy
Add `GraphProxy` and `.graphOverlay(alignment:content:)`
- Loading branch information
Showing
10 changed files
with
119 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
@usableFromInline | ||
struct AnyGraphContent<NodeID: Hashable>: GraphContent { | ||
|
||
public struct AnyGraphContent<NodeID: Hashable>: GraphContent { | ||
|
||
@usableFromInline | ||
let storage: any GraphContent<NodeID> | ||
|
||
@inlinable | ||
init(_ storage: any GraphContent<NodeID>) { | ||
public init(_ storage: any GraphContent<NodeID>) { | ||
self.storage = storage | ||
} | ||
|
||
@inlinable | ||
func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>) { | ||
public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>) { | ||
storage._attachToGraphRenderingContext(&context) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import SwiftUI | ||
|
||
public struct GraphProxy { | ||
|
||
@usableFromInline | ||
let storage: (any _AnyGraphProxyProtocol)? | ||
|
||
@inlinable | ||
init(_ storage: some _AnyGraphProxyProtocol) { | ||
self.storage = storage | ||
} | ||
|
||
@inlinable | ||
public init() { | ||
self.storage = nil | ||
} | ||
} | ||
|
||
extension GraphProxy: _AnyGraphProxyProtocol { | ||
public func locateNode(at locationInViewportCoordinate: CGPoint) -> AnyHashable? { | ||
storage?.locateNode(at: locationInViewportCoordinate) | ||
} | ||
} | ||
|
||
@usableFromInline | ||
struct GraphProxyKey: PreferenceKey { | ||
@inlinable | ||
static func reduce(value: inout GraphProxy, nextValue: () -> GraphProxy) { | ||
value = nextValue() | ||
} | ||
|
||
@inlinable | ||
static var defaultValue: GraphProxy { | ||
get { | ||
.init() | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
extension View { | ||
@inlinable | ||
public func graphOverlay<V>( | ||
alignment: Alignment = .center, | ||
@ViewBuilder content: @escaping (GraphProxy) -> V | ||
) -> some View where V: View { | ||
self.overlayPreferenceValue(GraphProxyKey.self, content) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters