extension View { /// Adds help text to a view using a string that you provide. /// /// This configures a hover tooltip where applicable, i.e. desktop and /// visionOS. When using touch screens, most users will not be able to /// access the help text in a simple way, though it can configure the /// accessibility hint text. public func help(_ text: String) -> some View { HelpView(helpText: text, content: self) } } struct HelpView: View, TypeSafeView { var helpText: String var content: Content var body: TupleView1 { content } typealias Children = TupleView1.Children func children( backend: Backend, snapshots: [ViewGraphSnapshotter.NodeSnapshot]?, environment: EnvironmentValues ) -> Children { body.children( backend: backend, snapshots: snapshots, environment: environment ) } func asWidget( _ children: Children, backend: Backend ) -> Backend.Widget { func castBackend_inner(_ backend: NewBackend) -> NewBackend.Widget { return backend.createTooltipContainer(wrapping: children.child0.widget.into()) } guard let castedBackend = backend as? any (BaseAppBackend & BackendFeatures.Tooltips) else { fatalError("Backend does not implement BackendFeatures.Tooltips") } return castBackend_inner(castedBackend) as! Backend.Widget } func computeLayout( _ widget: Backend.Widget, children: Children, proposedSize: ProposedViewSize, environment: EnvironmentValues, backend: Backend ) -> ViewLayoutResult { children.child0.computeLayout( with: body.view0, proposedSize: proposedSize, environment: environment ) } func commit( _ widget: Backend.Widget, children: Children, layout: ViewLayoutResult, environment: EnvironmentValues, backend: Backend ) { func castBackend_inner(_ backend: NewBackend) { let widget = widget as! NewBackend.Widget let size = children.child0.commit().size backend.setSize(of: widget, to: size.vector) backend.updateTooltipContainer(widget, tooltip: helpText) } guard let castedBackend = backend as? any (BaseAppBackend & BackendFeatures.Tooltips) else { fatalError("Backend does not implement BackendFeatures.Tooltips") } castBackend_inner(castedBackend) } }