Skip to content

Commit

Permalink
Merge pull request #184 from ikorich/feature/tooltips
Browse files Browse the repository at this point in the history
Updated hints to default behaviour
  • Loading branch information
twostraws authored Apr 29, 2024
2 parents 79ec837 + abe401b commit b2b2811
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 61 deletions.
1 change: 1 addition & 0 deletions ControlRoom/Main Window/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct SidebarView: View {
}
.buttonStyle(.borderless)
.padding(.leading, 3)
.help("Show \(preferences.shouldShowOnlyActiveDevices ? "all" : "only active") devices")

SearchField("Filter", text: $filterText.onChange(controller.filterSimulators), onClear: {})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,36 @@ struct NotificationEditorView: View {
HStack(spacing: 30) {
APSFormView(notificationAps: $notificationAps)

VStack(alignment: .leading) {
Text("Aps")
.font(.headline)
.addingInfoButton(title: "APS", description: "NotificationView.Hints.APS")

TextEditor(text: .constant(notificationAps.json))
.font(.system(.body, design: .monospaced))
.disableAutocorrection(true)
.frame(height: 200)
.scrollContentBackground(.hidden)
.padding(5)
.background(.quaternary)
.border(.tertiary, width: 1)

Text("User info")
.font(.headline)
.addingInfoButton(title: "User info", description: "NotificationView.Hints.UserInfo")

TextEditor(text: $userInfo)
.font(.system(.body, design: .monospaced))
.disableAutocorrection(true)
.frame(height: 200)
.scrollContentBackground(.hidden)
.padding(5)
.background(.quaternary)
.border(.tertiary, width: 1)
VStack(spacing: 16) {
VStack(alignment: .leading) {
Text("Aps")
.font(.headline)

TextEditor(text: .constant(notificationAps.json))
.font(.system(.body, design: .monospaced))
.disableAutocorrection(true)
.frame(height: 200)
.scrollContentBackground(.hidden)
.padding(5)
.background(.quaternary)
.border(.tertiary, width: 1)
}
.help("NotificationView.Hints.APS".localizedHint)

VStack(alignment: .leading) {
Text("User info")
.font(.headline)

TextEditor(text: $userInfo)
.font(.system(.body, design: .monospaced))
.disableAutocorrection(true)
.frame(height: 200)
.scrollContentBackground(.hidden)
.padding(5)
.background(.quaternary)
.border(.tertiary, width: 1)
}
.help("NotificationView.Hints.UserInfo".localizedHint)

Spacer()
}
Expand Down Expand Up @@ -255,10 +259,10 @@ private struct LocalizedFieldView: View {

HStack(spacing: 10) {
TextField("Localized key", text: $value)
.addingInfoButton(title: "Localized key", description: valueDescription)
.help(valueDescription.localizedHint)

TextField("Localized arguments", text: $arguments)
.addingInfoButton(title: "Localized key", description: argumentsDescription)
.help(argumentsDescription.localizedHint)
}
}
}
Expand All @@ -274,8 +278,8 @@ private struct FieldView: View {
Text(title)

TextField(title, text: $value)
.addingInfoButton(title: title, description: description)
}
.help(description.localizedHint)
}
}

Expand All @@ -285,10 +289,8 @@ private struct ToggleFieldView: View {
@Binding var value: Bool

var body: some View {
HStack {
Toggle(isOn: $value, label: { Text(title) })
}
.addingInfoButton(title: title, description: description)
Toggle(isOn: $value, label: { Text(title) })
.help(description.localizedHint)
}
}

Expand All @@ -313,42 +315,15 @@ private struct SliderFieldView: View {
Slider(value: $value, label: { Text(title) })
Text(sliderDisplayValue)
}
.help(description.localizedHint)
.disabled(!isEnabled)
.addingInfoButton(title: title, description: description)
}

var sliderDisplayValue: String {
Self.numberFormatter.string(for: value) ?? ""
}
}

private extension View {
func addingInfoButton(title: String, description: String) -> some View {
modifier(InfoButtonModifier(title: title,
description: description.localizedHint))
}
}

private struct InfoButtonModifier: ViewModifier {
let title: String
let description: String

@State private var shouldShowDescription = false

func body(content: Content) -> some View {
HStack {
content

Button("?") {
shouldShowDescription = true
}
}
.alert(isPresented: $shouldShowDescription) {
Alert(title: Text(title), message: Text(description))
}
}
}

private extension String {
var localizedHint: String {
NSLocalizedString(self, tableName: "NotificationEditorView", bundle: .main, comment: "")
Expand Down

0 comments on commit b2b2811

Please sign in to comment.