From 429ed84c383e2bbc0fa0fcfad98c1c3dc0507f13 Mon Sep 17 00:00:00 2001 From: david-swift Date: Sun, 9 Jul 2023 07:59:21 +0200 Subject: [PATCH] Add option to change settings window's width and height for a settings tab --- .../Components/SettingsKitScene.swift | 6 +-- .../SettingsKit/Model/Data/SettingsTab.swift | 39 +++++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 4 +- Tests/TestApp/TestApp/TestAppApp.swift | 9 +++++ 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/Sources/SettingsKit/Components/SettingsKitScene.swift b/Sources/SettingsKit/Components/SettingsKitScene.swift index b42433a..e98a5c3 100755 --- a/Sources/SettingsKit/Components/SettingsKitScene.swift +++ b/Sources/SettingsKit/Components/SettingsKitScene.swift @@ -31,17 +31,13 @@ struct SettingsKitScene: Scene where Content: Scene { }) { ForEach(settings) { tab in if case let .new(label: label) = tab.type { - Color.clear - .overlay { - tab - } + tab .tabItem { label } } } } - .frame(width: .settingsWidth, height: .settingsHeight) .symbolVariant(symbolVariant) } } diff --git a/Sources/SettingsKit/Model/Data/SettingsTab.swift b/Sources/SettingsKit/Model/Data/SettingsTab.swift index ac76086..87a75de 100755 --- a/Sources/SettingsKit/Model/Data/SettingsTab.swift +++ b/Sources/SettingsKit/Model/Data/SettingsTab.swift @@ -21,16 +21,22 @@ public struct SettingsTab: Identifiable, View { public var content: [SettingsSubtab] /// The sidebar actions view. public var sidebarActions: [ToolbarGroup] + /// The settings window's width. + public var windowWidth: CGFloat? = .settingsWidth + /// The settings window's height. + public var windowHeight: CGFloat? = .settingsHeight /// The view containing all the subtabs. public var body: some View { if content.count <= 1 && sidebarActions.isEmpty { content.first + .frame(width: windowWidth, height: windowHeight) } else { HSplitView { sidebar contentView } + .frame(width: .settingsWidth, height: .settingsHeight) } } @@ -173,4 +179,37 @@ public struct SettingsTab: Identifiable, View { } } + /// Set the window's width and height when this tab is open. + /// This is being ignored if there is more than one subtab or if there are settings actions. + /// - Parameters: + /// - width: The width. If nil, the window uses the content's width. + /// - height: The height. If nil, the window uses the content's height. + /// - Returns: The settings tab with the new window size. + public func frame(width: CGFloat? = nil, height: CGFloat? = nil) -> Self { + var newSelf = self + newSelf.windowWidth = width + newSelf.windowHeight = height + return newSelf + } + + /// Set the window's width when this tab is open without affecting the height. + /// This is being ignored if there is more than one subtab or if there are settings actions. + /// - Parameter width: The width. If nil, the window uses the content's width. + /// - Returns: The settings tab with the new window size. + public func width(_ width: CGFloat? = nil) -> Self { + var newSelf = self + newSelf.windowWidth = width + return newSelf + } + + /// Set the window's height when this tab is open without affecting the width. + /// This is being ignored if there is more than one subtab or if there are settings actions. + /// - Parameter height: The height. If nil, the window uses the content's height. + /// - Returns: The settings tab with the new window size. + public func height(_ height: CGFloat? = nil) -> Self { + var newSelf = self + newSelf.windowHeight = height + return newSelf + } + } diff --git a/Tests/TestApp/TestApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Tests/TestApp/TestApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 5b5718a..5e52137 100755 --- a/Tests/TestApp/TestApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Tests/TestApp/TestApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/david-swift/ColibriComponents-macOS", "state" : { - "revision" : "1d38bac19399970b275856e4e09b5343e13b49c5", - "version" : "0.1.1" + "revision" : "decdef77939275f710df3e3fc02f5dfdd219c5fb", + "version" : "0.1.8" } }, { diff --git a/Tests/TestApp/TestApp/TestAppApp.swift b/Tests/TestApp/TestApp/TestAppApp.swift index 0594139..94bd281 100755 --- a/Tests/TestApp/TestApp/TestAppApp.swift +++ b/Tests/TestApp/TestApp/TestAppApp.swift @@ -25,6 +25,15 @@ struct TestAppApp: App { for settingsTab in appModel.allSettings { settingsTab } + SettingsTab(.new(label: .init("Test", systemSymbol: .arrowLeftCircle)), id: "test") { + SettingsSubtab(.noSelection, id: "subtab") { + let width = 500.0 + let height = 100.0 + Text("Hello!") + .frame(width: width, height: height) + } + } + .frame() } }