PreferencesExtension // Clang-Format.
This commit is contained in:
parent
e5d8e8fe98
commit
db555640eb
|
@ -23,8 +23,8 @@ import SwiftUI
|
|||
@available(macOS 10.15, *)
|
||||
extension Preferences {
|
||||
/**
|
||||
Function builder for `Preferences` components used in order to restrict types of child views to be of type `Section`.
|
||||
*/
|
||||
Function builder for `Preferences` components used in order to restrict types of child views to be of type `Section`.
|
||||
*/
|
||||
@resultBuilder
|
||||
public enum SectionBuilder {
|
||||
public static func buildBlock(_ sections: Section...) -> [Section] {
|
||||
|
@ -33,8 +33,8 @@ extension Preferences {
|
|||
}
|
||||
|
||||
/**
|
||||
A view which holds `Preferences.Section` views and does all the alignment magic similar to `NSGridView` from AppKit.
|
||||
*/
|
||||
A view which holds `Preferences.Section` views and does all the alignment magic similar to `NSGridView` from AppKit.
|
||||
*/
|
||||
public struct Container: View {
|
||||
private let sectionBuilder: () -> [Section]
|
||||
private let contentWidth: Double
|
||||
|
@ -42,15 +42,15 @@ extension Preferences {
|
|||
@State private var maximumLabelWidth = 0.0
|
||||
|
||||
/**
|
||||
Creates an instance of container component, which handles layout of stacked `Preferences.Section` views.
|
||||
Creates an instance of container component, which handles layout of stacked `Preferences.Section` views.
|
||||
|
||||
Custom alignment requires content width to be specified beforehand.
|
||||
Custom alignment requires content width to be specified beforehand.
|
||||
|
||||
- Parameters:
|
||||
- contentWidth: A fixed width of the container's content (excluding paddings).
|
||||
- minimumLabelWidth: A minimum width for labels within this container. By default, it will fit to the largest label.
|
||||
- builder: A view builder that creates `Preferences.Section`'s of this container.
|
||||
*/
|
||||
- Parameters:
|
||||
- contentWidth: A fixed width of the container's content (excluding paddings).
|
||||
- minimumLabelWidth: A minimum width for labels within this container. By default, it will fit to the largest label.
|
||||
- builder: A view builder that creates `Preferences.Section`'s of this container.
|
||||
*/
|
||||
public init(
|
||||
contentWidth: Double,
|
||||
minimumLabelWidth: Double = 0,
|
||||
|
|
|
@ -112,12 +112,12 @@ struct Localization {
|
|||
]
|
||||
|
||||
/**
|
||||
Returns the localized version of the given string.
|
||||
Returns the localized version of the given string.
|
||||
|
||||
- Parameter identifier: Identifier of the string to localize.
|
||||
- Parameter identifier: Identifier of the string to localize.
|
||||
|
||||
- Note: If the system's locale can't be determined, the English localization of the string will be returned.
|
||||
*/
|
||||
- Note: If the system's locale can't be determined, the English localization of the string will be returned.
|
||||
*/
|
||||
static subscript(identifier: Identifier) -> String {
|
||||
// Force-unwrapped since all of the involved code is under our control.
|
||||
let localizedDict = Localization.localizedStrings[identifier]!
|
||||
|
|
|
@ -25,18 +25,18 @@ import SwiftUI
|
|||
/// Acts as type-eraser for `Preferences.Pane<T>`.
|
||||
public protocol PreferencePaneConvertible {
|
||||
/**
|
||||
Convert `self` to equivalent `PreferencePane`.
|
||||
*/
|
||||
Convert `self` to equivalent `PreferencePane`.
|
||||
*/
|
||||
func asPreferencePane() -> PreferencePane
|
||||
}
|
||||
|
||||
@available(macOS 10.15, *)
|
||||
extension Preferences {
|
||||
/**
|
||||
Create a SwiftUI-based preference pane.
|
||||
Create a SwiftUI-based preference pane.
|
||||
|
||||
SwiftUI equivalent of the `PreferencePane` protocol.
|
||||
*/
|
||||
SwiftUI equivalent of the `PreferencePane` protocol.
|
||||
*/
|
||||
public struct Pane<Content: View>: View, PreferencePaneConvertible {
|
||||
let identifier: PaneIdentifier
|
||||
let title: String
|
||||
|
@ -63,8 +63,8 @@ extension Preferences {
|
|||
}
|
||||
|
||||
/**
|
||||
Hosting controller enabling `Preferences.Pane` to be used alongside AppKit `NSViewController`'s.
|
||||
*/
|
||||
Hosting controller enabling `Preferences.Pane` to be used alongside AppKit `NSViewController`'s.
|
||||
*/
|
||||
public final class PaneHostingController<Content: View>: NSHostingController<Content>, PreferencePane {
|
||||
public let preferencePaneIdentifier: PaneIdentifier
|
||||
public let preferencePaneTitle: String
|
||||
|
@ -102,8 +102,8 @@ extension Preferences {
|
|||
@available(macOS 10.15, *)
|
||||
extension View {
|
||||
/**
|
||||
Applies font and color for a label used for describing a preference.
|
||||
*/
|
||||
Applies font and color for a label used for describing a preference.
|
||||
*/
|
||||
public func preferenceDescription() -> some View {
|
||||
font(.system(size: 11.0))
|
||||
// TODO: Use `.foregroundStyle` when targeting macOS 12.
|
||||
|
|
|
@ -97,17 +97,17 @@ public final class PreferencesWindowController: NSWindowController {
|
|||
}
|
||||
|
||||
/**
|
||||
Show the preferences window and brings it to front.
|
||||
Show the preferences window and brings it to front.
|
||||
|
||||
If you pass a `Preferences.PaneIdentifier`, the window will activate the corresponding tab.
|
||||
If you pass a `Preferences.PaneIdentifier`, the window will activate the corresponding tab.
|
||||
|
||||
- Parameter preferencePane: Identifier of the preference pane to display, or `nil` to show the tab that was open when the user last closed the window.
|
||||
- Parameter preferencePane: Identifier of the preference pane to display, or `nil` to show the tab that was open when the user last closed the window.
|
||||
|
||||
- Note: Unless you need to open a specific pane, prefer not to pass a parameter at all or `nil`.
|
||||
- Note: Unless you need to open a specific pane, prefer not to pass a parameter at all or `nil`.
|
||||
|
||||
- See `close()` to close the window again.
|
||||
- See `showWindow(_:)` to show the window without the convenience of activating the app.
|
||||
*/
|
||||
- See `close()` to close the window again.
|
||||
- See `showWindow(_:)` to show the window without the convenience of activating the app.
|
||||
*/
|
||||
public func show(preferencePane preferenceIdentifier: Preferences.PaneIdentifier? = nil) {
|
||||
if let preferenceIdentifier = preferenceIdentifier {
|
||||
tabViewController.activateTab(preferenceIdentifier: preferenceIdentifier, animated: false)
|
||||
|
@ -168,8 +168,8 @@ extension PreferencesWindowController {
|
|||
@available(macOS 10.15, *)
|
||||
extension PreferencesWindowController {
|
||||
/**
|
||||
Create a preferences window from only SwiftUI-based preference panes.
|
||||
*/
|
||||
Create a preferences window from only SwiftUI-based preference panes.
|
||||
*/
|
||||
public convenience init(
|
||||
panes: [PreferencePaneConvertible],
|
||||
style: Preferences.Style = .toolbarItems,
|
||||
|
|
|
@ -23,13 +23,13 @@ import SwiftUI
|
|||
@available(macOS 10.15, *)
|
||||
extension Preferences {
|
||||
/**
|
||||
Represents a section with right-aligned title and optional bottom divider.
|
||||
*/
|
||||
Represents a section with right-aligned title and optional bottom divider.
|
||||
*/
|
||||
@available(macOS 10.15, *)
|
||||
public struct Section: View {
|
||||
/**
|
||||
Preference key holding max width of section labels.
|
||||
*/
|
||||
Preference key holding max width of section labels.
|
||||
*/
|
||||
private struct LabelWidthPreferenceKey: PreferenceKey {
|
||||
typealias Value = Double
|
||||
|
||||
|
@ -42,8 +42,8 @@ extension Preferences {
|
|||
}
|
||||
|
||||
/**
|
||||
Convenience overlay for finding a label's dimensions using `GeometryReader`.
|
||||
*/
|
||||
Convenience overlay for finding a label's dimensions using `GeometryReader`.
|
||||
*/
|
||||
private struct LabelOverlay: View {
|
||||
var body: some View {
|
||||
GeometryReader { geometry in
|
||||
|
@ -54,8 +54,8 @@ extension Preferences {
|
|||
}
|
||||
|
||||
/**
|
||||
Convenience modifier for applying `LabelWidthPreferenceKey`.
|
||||
*/
|
||||
Convenience modifier for applying `LabelWidthPreferenceKey`.
|
||||
*/
|
||||
struct LabelWidthModifier: ViewModifier {
|
||||
@Binding var maximumWidth: Double
|
||||
|
||||
|
@ -73,15 +73,15 @@ extension Preferences {
|
|||
public let verticalAlignment: VerticalAlignment
|
||||
|
||||
/**
|
||||
A section is responsible for controlling a single preference.
|
||||
A section is responsible for controlling a single preference.
|
||||
|
||||
- Parameters:
|
||||
- bottomDivider: Whether to place a `Divider` after the section content. Default is `false`.
|
||||
- verticalAlignement: The vertical alignment of the section content.
|
||||
- verticalAlignment:
|
||||
- label: A view describing preference handled by this section.
|
||||
- content: A content view.
|
||||
*/
|
||||
- Parameters:
|
||||
- bottomDivider: Whether to place a `Divider` after the section content. Default is `false`.
|
||||
- verticalAlignement: The vertical alignment of the section content.
|
||||
- verticalAlignment:
|
||||
- label: A view describing preference handled by this section.
|
||||
- content: A content view.
|
||||
*/
|
||||
public init<Label: View, Content: View>(
|
||||
bottomDivider: Bool = false,
|
||||
verticalAlignment: VerticalAlignment = .firstTextBaseline,
|
||||
|
@ -98,15 +98,15 @@ extension Preferences {
|
|||
}
|
||||
|
||||
/**
|
||||
Creates instance of section, responsible for controling single preference with `Text` as a `Label`.
|
||||
Creates instance of section, responsible for controling single preference with `Text` as a `Label`.
|
||||
|
||||
- Parameters:
|
||||
- title: A string describing preference handled by this section.
|
||||
- bottomDivider: Whether to place a `Divider` after the section content. Default is `false`.
|
||||
- verticalAlignement: The vertical alignment of the section content.
|
||||
- verticalAlignment:
|
||||
- content: A content view.
|
||||
*/
|
||||
- Parameters:
|
||||
- title: A string describing preference handled by this section.
|
||||
- bottomDivider: Whether to place a `Divider` after the section content. Default is `false`.
|
||||
- verticalAlignement: The vertical alignment of the section content.
|
||||
- verticalAlignment:
|
||||
- content: A content view.
|
||||
*/
|
||||
public init<Content: View>(
|
||||
title: String,
|
||||
bottomDivider: Bool = false,
|
||||
|
|
|
@ -130,8 +130,8 @@ class UserInteractionPausableWindow: NSWindow {
|
|||
@available(macOS 10.15, *)
|
||||
extension View {
|
||||
/**
|
||||
Equivalent to `.eraseToAnyPublisher()` from the Combine framework.
|
||||
*/
|
||||
Equivalent to `.eraseToAnyPublisher()` from the Combine framework.
|
||||
*/
|
||||
func eraseToAnyView() -> AnyView {
|
||||
AnyView(self)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue