| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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<Content: View>: View, TypeSafeView {
- var helpText: String
- var content: Content
- var body: TupleView1<Content> { content }
- typealias Children = TupleView1<Content>.Children
- func children<Backend: BaseAppBackend>(
- backend: Backend,
- snapshots: [ViewGraphSnapshotter.NodeSnapshot]?,
- environment: EnvironmentValues
- ) -> Children {
- body.children(
- backend: backend,
- snapshots: snapshots,
- environment: environment
- )
- }
- func asWidget<Backend: BaseAppBackend>(
- _ children: Children,
- backend: Backend
- ) -> Backend.Widget {
- func castBackend_inner<NewBackend: BaseAppBackend & BackendFeatures.Tooltips>(_ 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<Backend: BaseAppBackend>(
- _ widget: Backend.Widget,
- children: Children,
- proposedSize: ProposedViewSize,
- environment: EnvironmentValues,
- backend: Backend
- ) -> ViewLayoutResult {
- children.child0.computeLayout(
- with: body.view0,
- proposedSize: proposedSize,
- environment: environment
- )
- }
- func commit<Backend: BaseAppBackend>(
- _ widget: Backend.Widget,
- children: Children,
- layout: ViewLayoutResult,
- environment: EnvironmentValues,
- backend: Backend
- ) {
- func castBackend_inner<NewBackend: BaseAppBackend & BackendFeatures.Tooltips>(_ 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)
- }
- }
|