Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kyome22/panelscenekit
Library that provides NSPanel via SwiftUI Scene.
https://github.com/kyome22/panelscenekit
Last synced: about 2 months ago
JSON representation
Library that provides NSPanel via SwiftUI Scene.
- Host: GitHub
- URL: https://github.com/kyome22/panelscenekit
- Owner: Kyome22
- License: mit
- Created: 2024-11-02T13:53:48.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-02T14:20:52.000Z (about 2 months ago)
- Last Synced: 2024-11-02T15:18:58.939Z (about 2 months ago)
- Language: Swift
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PanelSceneKit
Library that provides NSPanel via SwiftUI Scene.
## Requirements
- Development with Xcode 16.0+
- Written in Swift 6.0
- Compatible with macOS 14.0+## Usage
Below is an example of displaying a custom `NSPanel` with a floating attribute.
```swift
@main
struct SampleApp: App {
@State var isPresented: Bool = truevar body: some Scene {
PanelScene(isPresented: $isPresented, type: FloatingPanel.self) { _ in
Text("Hello World!")
.fixedSize()
.padding()
}
}
}
```You need to define a custom `NSPanel` that conforms to `HostingPanel`.
```swift
final class FloatingPanel: NSPanel, HostingPanel {
init(content: () -> Content) {
super.init(
contentRect: .zero,
styleMask: [.titled, .closable, .fullSizeContentView, .nonactivatingPanel],
backing: .buffered,
defer: false
)
level = .floating
isOpaque = false
isMovableByWindowBackground = true
titlebarAppearsTransparent = true
titleVisibility = .hidden
animationBehavior = .utilityWindow
contentView = NSHostingView(rootView: content())
}
}
```You can toggle the visibility of the specified PanelScene from a remote scope.
```diff swift
@main
struct SampleApp: App {
+ @PanelState("SomePanelKey") var isPresented: Bool = falsevar body: some Scene {
PanelScene(isPresented: $isPresented, type: FloatingPanel.self) { _ in
Text("Hello World!")
.fixedSize()
.padding()
}
}
}// Request to open the specified PanelScene.
PanelSceneMessenger.request(panelAction: .open, with: "SomePanelKey")// Request to close the specified PanelScene.
PanelSceneMessenger.request(panelAction: .close, with: "SomePanelKey")
```## Privacy Manifest
This library does not collect or track user information, so it does not include a PrivacyInfo.xcprivacy file.