PrefUI // Simplify the usage of .help() backports.

This commit is contained in:
ShikiSuen 2022-10-24 10:24:16 +08:00
parent d263719e64
commit 7a4aa38df5
3 changed files with 7 additions and 15 deletions

View File

@ -152,6 +152,7 @@ extension Binding {
// Ref: https://stackoverflow.com/a/63217861 // Ref: https://stackoverflow.com/a/63217861
@available(macOS 10.15, *) @available(macOS 10.15, *)
@available(macOS, obsoleted: 11)
struct Tooltip: NSViewRepresentable { struct Tooltip: NSViewRepresentable {
let tooltip: String let tooltip: String
@ -166,8 +167,9 @@ struct Tooltip: NSViewRepresentable {
} }
@available(macOS 10.15, *) @available(macOS 10.15, *)
@available(macOS, obsoleted: 11)
extension View { extension View {
public func toolTip(_ tooltip: String) -> some View { public func help(_ tooltip: String) -> some View {
overlay(Tooltip(tooltip: tooltip)) overlay(Tooltip(tooltip: tooltip))
} }
} }

View File

@ -48,13 +48,8 @@ struct VwrPrefPaneCassette: View {
SSPreferences.Section(title: "", bottomDivider: true) { SSPreferences.Section(title: "", bottomDivider: true) {
Text(LocalizedStringKey("Choose your desired cassette file path. Will be omitted if invalid.")) Text(LocalizedStringKey("Choose your desired cassette file path. Will be omitted if invalid."))
HStack { HStack {
if #available(macOS 11.0, *) { TextField(fdrCassetteDataDefault, text: $tbxCassettePath).disabled(true)
TextField(fdrCassetteDataDefault, text: $tbxCassettePath).disabled(true) .help(tbxCassettePath)
.help(tbxCassettePath)
} else {
TextField(fdrCassetteDataDefault, text: $tbxCassettePath).disabled(true)
.toolTip(tbxCassettePath)
}
Button { Button {
Self.dlgOpenFile.title = NSLocalizedString( Self.dlgOpenFile.title = NSLocalizedString(
"Choose your desired cassette file path.", comment: "" "Choose your desired cassette file path.", comment: ""

View File

@ -60,13 +60,8 @@ struct VwrPrefPaneDictionary: View {
SSPreferences.Section(title: "", bottomDivider: true) { SSPreferences.Section(title: "", bottomDivider: true) {
Text(LocalizedStringKey("Choose your desired user data folder path. Will be omitted if invalid.")) Text(LocalizedStringKey("Choose your desired user data folder path. Will be omitted if invalid."))
HStack { HStack {
if #available(macOS 11.0, *) { TextField(fdrUserDataDefault, text: $tbxUserDataPathSpecified).disabled(true)
TextField(fdrUserDataDefault, text: $tbxUserDataPathSpecified).disabled(true) .help(tbxUserDataPathSpecified)
.help(tbxUserDataPathSpecified)
} else {
TextField(fdrUserDataDefault, text: $tbxUserDataPathSpecified).disabled(true)
.toolTip(tbxUserDataPathSpecified)
}
Button { Button {
Self.dlgOpenPath.title = NSLocalizedString( Self.dlgOpenPath.title = NSLocalizedString(
"Choose your desired user data folder.", comment: "" "Choose your desired user data folder.", comment: ""