Skip to content

Commit

Permalink
Add option to change settings window's width and height for a setting…
Browse files Browse the repository at this point in the history
…s tab
  • Loading branch information
david-swift committed Jul 9, 2023
1 parent 1c83904 commit 429ed84
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
6 changes: 1 addition & 5 deletions Sources/SettingsKit/Components/SettingsKitScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ struct SettingsKitScene<Content>: 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)
}
}
Expand Down
39 changes: 39 additions & 0 deletions Sources/SettingsKit/Model/Data/SettingsTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
{
Expand Down
9 changes: 9 additions & 0 deletions Tests/TestApp/TestApp/TestAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 429ed84

Please sign in to comment.