Skip to content

Commit 907c46c

Browse files
committed
Improve sidebar design support
- Better selection management - Modifiers for using room above or below list of settings subtabs - Improve search
1 parent d2f57b2 commit 907c46c

File tree

11 files changed

+388
-422
lines changed

11 files changed

+388
-422
lines changed

Documentation/Reference/SettingsKit/structs/SettingsTab.md

+22-177
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A tab in the settings window.
1212
### `model`
1313

1414
```swift
15-
@StateObject private var model = SettingsModel.shared
15+
@StateObject var model = SettingsModel.shared
1616
```
1717

1818
The instance of the settings model.
@@ -49,6 +49,22 @@ public var content: [SettingsSubtab]
4949

5050
The tab's content.
5151

52+
### `top`
53+
54+
```swift
55+
public var top: AnyView?
56+
```
57+
58+
The view above the list of the subtabs in the sidebar style settings window.
59+
60+
### `bottom`
61+
62+
```swift
63+
public var bottom: AnyView?
64+
```
65+
66+
The view below the list of the subtabs in the sidebar style settings window.
67+
5268
### `sidebarActions`
5369

5470
```swift
@@ -76,7 +92,7 @@ The settings window's height.
7692
### `contentWithoutNoSelectionSubtabs`
7793

7894
```swift
79-
private var contentWithoutNoSelectionSubtabs: [SettingsSubtab]
95+
var contentWithoutNoSelectionSubtabs: [SettingsSubtab]
8096
```
8197

8298
The tab's content, but without the subtabs with the ``TabType.noSelection`` type.
@@ -92,15 +108,15 @@ The view containing all the subtabs.
92108
### `sidebar`
93109

94110
```swift
95-
private var sidebar: some View
111+
var sidebar: some View
96112
```
97113

98114
The tab's sidebar containing all the subtabs.
99115

100116
### `sidebarList`
101117

102118
```swift
103-
private var sidebarList: some View
119+
var sidebarList: some View
104120
```
105121

106122
The list in the tab's sidebar.
@@ -116,7 +132,7 @@ The body if the sidebar layout is active.
116132
### `contentView`
117133

118134
```swift
119-
private var contentView: some View
135+
var contentView: some View
120136
```
121137

122138
The selected subtab's content.
@@ -163,175 +179,4 @@ The initializer.
163179
| type | The tab type of the settings tab. |
164180
| id | The identifier. |
165181
| color | The tab’s color in the settings window with the sidebar design. |
166-
| content | The content of the settings tab. |
167-
168-
### `listContent(subtab:)`
169-
170-
```swift
171-
private func listContent(subtab: SettingsSubtab) -> some View
172-
```
173-
174-
A row in the sidebar list.
175-
- Parameter subtab: The subtab of the row.
176-
- Returns: The row.
177-
178-
#### Parameters
179-
180-
| Name | Description |
181-
| ---- | ----------- |
182-
| subtab | The subtab of the row. |
183-
184-
### `updateSubtabSelection(ids:)`
185-
186-
```swift
187-
private func updateSubtabSelection(ids: [String])
188-
```
189-
190-
Update the selection of the subtab.
191-
- Parameter ids: The identifiers of the subtabs.
192-
193-
#### Parameters
194-
195-
| Name | Description |
196-
| ---- | ----------- |
197-
| ids | The identifiers of the subtabs. |
198-
199-
### `actions(content:)`
200-
201-
```swift
202-
public func actions(@ArrayBuilder<ToolbarGroup> content: () -> [ToolbarGroup]) -> Self
203-
```
204-
205-
Adds actions to the settings sidebar.
206-
- Parameter content: The actions.
207-
- Returns: The new tab with the actions.
208-
209-
#### Parameters
210-
211-
| Name | Description |
212-
| ---- | ----------- |
213-
| content | The actions. |
214-
215-
### `actions(content:)`
216-
217-
```swift
218-
public func actions(content: [ToolbarGroup]) -> Self
219-
```
220-
221-
Add actions to the settings sidebar by providing an array.
222-
- Parameter content: The actions as an array..
223-
- Returns: The new tab with the actions.
224-
225-
#### Parameters
226-
227-
| Name | Description |
228-
| ---- | ----------- |
229-
| content | The actions as an array.. |
230-
231-
### `standardActions(add:remove:options:)`
232-
233-
```swift
234-
public func standardActions(
235-
add: @escaping () -> Void,
236-
remove: @escaping (String?, Int?) -> Void,
237-
options: (() -> Void)? = nil
238-
) -> Self
239-
```
240-
241-
The standard set of actions with an add button, a remove button and optionally an options button.
242-
- Parameters:
243-
- add: The action that is called when the add button is pressed.
244-
- remove: The action that is called when the remove button is pressed,
245-
giving the the selected subtab's id and index.
246-
- options: The action that is called when the options button is pressed.
247-
If it is nil, there is no options button.
248-
- Returns: The new tab with the actions.
249-
250-
#### Parameters
251-
252-
| Name | Description |
253-
| ---- | ----------- |
254-
| add | The action that is called when the add button is pressed. |
255-
| remove | The action that is called when the remove button is pressed, giving the the selected subtab’s id and index. |
256-
| options | The action that is called when the options button is pressed. If it is nil, there is no options button. |
257-
258-
### `standardActions(add:remove:options:)`
259-
260-
```swift
261-
public func standardActions<ContentView>(
262-
@ViewBuilder add: @escaping () -> ContentView,
263-
remove: @escaping (String?, Int?) -> Void,
264-
options: (() -> Void)? = nil
265-
) -> Self where ContentView: View
266-
```
267-
268-
The standard set of actions with an add menu, a remove button and optionally an options button.
269-
- Parameters:
270-
- add: The menu that is opened when the add button is pressed.
271-
- remove: The action that is called when the remove button is pressed,
272-
giving the the selected subtab's id and index.
273-
- options: The action that is called when the options button is pressed.
274-
If it is nil, there is no options button.
275-
- Returns: The new tab with the actions.
276-
277-
#### Parameters
278-
279-
| Name | Description |
280-
| ---- | ----------- |
281-
| add | The menu that is opened when the add button is pressed. |
282-
| remove | The action that is called when the remove button is pressed, giving the the selected subtab’s id and index. |
283-
| options | The action that is called when the options button is pressed. If it is nil, there is no options button. |
284-
285-
### `frame(width:height:)`
286-
287-
```swift
288-
public func frame(width: CGFloat? = nil, height: CGFloat? = nil) -> Self
289-
```
290-
291-
Set the window's width and height when this tab is open.
292-
This is being ignored if there is more than one subtab or if there are settings actions.
293-
- Parameters:
294-
- width: The width. If nil, the window uses the content's width.
295-
- height: The height. If nil, the window uses the content's height.
296-
- Returns: The settings tab with the new window size.
297-
298-
#### Parameters
299-
300-
| Name | Description |
301-
| ---- | ----------- |
302-
| width | The width. If nil, the window uses the content’s width. |
303-
| height | The height. If nil, the window uses the content’s height. |
304-
305-
### `width(_:)`
306-
307-
```swift
308-
public func width(_ width: CGFloat? = nil) -> Self
309-
```
310-
311-
Set the window's width when this tab is open without affecting the height.
312-
This is being ignored if there is more than one subtab or if there are settings actions.
313-
- Parameter width: The width. If nil, the window uses the content's width.
314-
- Returns: The settings tab with the new window size.
315-
316-
#### Parameters
317-
318-
| Name | Description |
319-
| ---- | ----------- |
320-
| width | The width. If nil, the window uses the content’s width. |
321-
322-
### `height(_:)`
323-
324-
```swift
325-
public func height(_ height: CGFloat? = nil) -> Self
326-
```
327-
328-
Set the window's height when this tab is open without affecting the width.
329-
This is being ignored if there is more than one subtab or if there are settings actions.
330-
- Parameter height: The height. If nil, the window uses the content's height.
331-
- Returns: The settings tab with the new window size.
332-
333-
#### Parameters
334-
335-
| Name | Description |
336-
| ---- | ----------- |
337-
| height | The height. If nil, the window uses the content’s height. |
182+
| content | The content of the settings tab. |

Icons/SidebarDesign.png

9.1 KB
Loading

README.md

+20-18
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@ An example app project is available [here.][4]
5454
* [Add a Settings Window][6]
5555
* [Tabs & Subtabs][7]
5656
* [Actions][8]
57+
* [The Sidebar Design][9]
5758

5859
## Thanks
5960

6061
### Dependencies
61-
- [SFSafeSymbols][9] licensed under the [MIT license][10]
62-
- [SwiftLintPlugin][11] licensed under the [MIT license][12]
63-
- [ColibriComponents][13] licensed under the [MIT license][14]
62+
- [SFSafeSymbols][10] licensed under the [MIT license][11]
63+
- [SwiftLintPlugin][12] licensed under the [MIT license][13]
64+
- [ColibriComponents][14] licensed under the [MIT license][15]
6465

6566
### Other Thanks
66-
- The [contributors][15]
67-
- [SourceDocs][16] used for generating the [docs][17]
68-
- [SwiftLint][18] for checking whether code style conventions are violated
69-
- The programming language [Swift][19]
67+
- The [contributors][16]
68+
- [SourceDocs][17] used for generating the [docs][18]
69+
- [SwiftLint][19] for checking whether code style conventions are violated
70+
- The programming language [Swift][20]
7071

7172
[1]: #installation
7273
[2]: #usage
@@ -76,16 +77,17 @@ An example app project is available [here.][4]
7677
[6]: user-manual/Usage/AddSettingsWindow.md
7778
[7]: user-manual/Usage/TabsAndSubtabs.md
7879
[8]: user-manual/Usage/Actions.md
79-
[9]: https://github.com/SFSafeSymbols/SFSafeSymbols
80-
[10]: https://github.com/SFSafeSymbols/SFSafeSymbols/blob/stable/LICENSE
81-
[11]: https://github.com/lukepistrol/SwiftLintPlugin
82-
[12]: https://github.com/lukepistrol/SwiftLintPlugin/blob/main/LICENSE
83-
[13]: https://github.com/david-swift/ColibriComponents-macOS
84-
[14]: https://github.com/david-swift/ColibriComponents-macOS/blob/main/LICENSE.md
85-
[15]: Contributors.md
86-
[16]: https://github.com/SourceDocs/SourceDocs
87-
[17]: Documentation/Reference/SettingsKit-macOS/README.md
88-
[18]: https://github.com/realm/SwiftLint
89-
[19]: https://github.com/apple/swift
80+
[9]: user-manual/Usage/SidebarDesign.md
81+
[10]: https://github.com/SFSafeSymbols/SFSafeSymbols
82+
[11]: https://github.com/SFSafeSymbols/SFSafeSymbols/blob/stable/LICENSE
83+
[12]: https://github.com/lukepistrol/SwiftLintPlugin
84+
[13]: https://github.com/lukepistrol/SwiftLintPlugin/blob/main/LICENSE
85+
[14]: https://github.com/david-swift/ColibriComponents-macOS
86+
[15]: https://github.com/david-swift/ColibriComponents-macOS/blob/main/LICENSE.md
87+
[16]: Contributors.md
88+
[17]: https://github.com/SourceDocs/SourceDocs
89+
[18]: Documentation/Reference/SettingsKit-macOS/README.md
90+
[19]: https://github.com/realm/SwiftLint
91+
[20]: https://github.com/apple/swift
9092

9193
[image-1]: Icons/GitHubBanner.png

SUMMARY.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
* [Add a Settings Window][3]
99
* [Tabs & Subtabs][4]
1010
* [Actions][5]
11+
* [The Sidebar Design][6]
1112

1213
[1]: README.md
1314
[2]: user-manual/GettingStarted.md
1415
[3]: user-manual/Usage/AddSettingsWindow.md
1516
[4]: user-manual/Usage/TabsAndSubtabs.md
16-
[5]: user-manual/Usage/Actions.md
17+
[5]: user-manual/Usage/Actions.md
18+
[6]: user-manual/Usage/SidebarDesign.md

Sources/SettingsKit/Components/SettingsKitScene.swift

+15-6
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,17 @@ struct SettingsKitScene<Content>: Scene where Content: Scene {
5252
Section {
5353
ForEach(settings.filter { tab in
5454
if case let .new(title: title, icon: _) = tab.type {
55-
return title.lowercased().contains(search.lowercased()) || search.isEmpty
56-
} else {
57-
return false
55+
let search = search.lowercased()
56+
let contentContains = tab.content.contains { subtab in
57+
if case let .new(title: title, icon: _) = subtab.type {
58+
return title.lowercased().contains(search)
59+
}
60+
return false
61+
}
62+
return title.lowercased().contains(search) || search.isEmpty || contentContains
5863
}
59-
}) { tab in
60-
tab.sidebarLabel
61-
}
64+
return false
65+
}) { $0.sidebarLabel }
6266
}
6367
}
6468
let tab = settings.first { $0.id == SettingsModel.shared.selectedTab }
@@ -81,6 +85,11 @@ struct SettingsKitScene<Content>: Scene where Content: Scene {
8185
window?.toolbarStyle = .unified
8286
window?.toolbar?.displayMode = .iconOnly
8387
}
88+
.onAppear {
89+
if !settings.contains(where: { $0.id == model.selectedTab }), let id = settings.first?.id {
90+
model.selectedTab = id
91+
}
92+
}
8493
}
8594

8695
/// The view with the tab design.

0 commit comments

Comments
 (0)