admin管理员组文章数量:1399788
I am creating settings window for my macOS app, using SwiftUI. I should use Settings {...}
scene, however I have found some strange behaviour there. For example I can't make window resizable with any .windowResizability()
modifier, or my toolbar is always separated from window titlebar, regardless of ToolbarItem(placement:)
I use. If I change Settings to WindowGroup, everything works as expected, but not with Settings.
My App, just for illustration:
var body: some Scene {
WindowGroup {
Text("Main window")
.frame(minWidth: 400, maxWidth: 400, minHeight: 200, maxHeight: .infinity)
}
Settings {
SettingsContentView()
.frame(minWidth: 600, maxWidth: 600, minHeight: 200, maxHeight: .infinity)
.stdEnvironment(model: self.Model)
}
.windowToolbarStyle(.unified)
.defaultSize(width: 600, height: 500)
.windowResizability(.contentMinSize)
}
So my question is - if I create settings window using WindowGroup, how do I then connect it to standard Settings command from menu? Is it possible to always open specified WindowGroup whenever settings would normally be opened?
I am creating settings window for my macOS app, using SwiftUI. I should use Settings {...}
scene, however I have found some strange behaviour there. For example I can't make window resizable with any .windowResizability()
modifier, or my toolbar is always separated from window titlebar, regardless of ToolbarItem(placement:)
I use. If I change Settings to WindowGroup, everything works as expected, but not with Settings.
My App, just for illustration:
var body: some Scene {
WindowGroup {
Text("Main window")
.frame(minWidth: 400, maxWidth: 400, minHeight: 200, maxHeight: .infinity)
}
Settings {
SettingsContentView()
.frame(minWidth: 600, maxWidth: 600, minHeight: 200, maxHeight: .infinity)
.stdEnvironment(model: self.Model)
}
.windowToolbarStyle(.unified)
.defaultSize(width: 600, height: 500)
.windowResizability(.contentMinSize)
}
So my question is - if I create settings window using WindowGroup, how do I then connect it to standard Settings command from menu? Is it possible to always open specified WindowGroup whenever settings would normally be opened?
Share Improve this question asked Mar 26 at 6:22 KavenKaven 3392 silver badges15 bronze badges1 Answer
Reset to default 2You can use CommandGroup(replacing: .appSettings) { ... }
to add a menu item to where the settings menu item would have been. Put your own "Settings" button there to open a regular Window
.
I wouldn't use a WindowGroup
for settings, because usually you can only open one settings window.
Example:
@Environment(\.openWindow) var openWindow
var body: some Scene {
WindowGroup {
ContentView()
}
mands {
CommandGroup(replacing: .appSettings) {
Button("Settings...") {
openWindow(id: "settings")
}
.keyboardShortcut(",")
}
}
Window("Settings", id: "settings") {
Text("Some Settings Here...")
}
}
本文标签: SwiftUI on MacOScreate Settings with WindowGoupStack Overflow
版权声明:本文标题:SwiftUI on MacOS - create Settings with WindowGoup - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744162076a2593384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论