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
@available(macOS 10.15, *)
@available(macOS, obsoleted: 11)
struct Tooltip: NSViewRepresentable {
let tooltip: String
@ -166,8 +167,9 @@ struct Tooltip: NSViewRepresentable {
}
@available(macOS 10.15, *)
@available(macOS, obsoleted: 11)
extension View {
public func toolTip(_ tooltip: String) -> some View {
public func help(_ tooltip: String) -> some View {
overlay(Tooltip(tooltip: tooltip))
}
}

View File

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

View File

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