// // Text.swift // MacBackend // // Created by david-swift on 29.11.2024. // import SwiftUI /// The text widget. public struct Text: SwiftUIWidget { /// The label. var label: String /// The font. var font: Font? /// Whether the text is selectable. var selectionDisabled = true /// Initialize the text widget. /// - Parameter label: The text. public init(_ label: String) { self.label = label } /// Get the SwiftUI view. /// - Parameter properties: The widget data. /// - Returns: The SwiftUI view. @SwiftUI.ViewBuilder public static func view(properties: Self) -> some SwiftUI.View { let text = SwiftUI.Text(properties.label) .font(properties.font?.swiftUI) if properties.selectionDisabled { text .textSelection(.disabled) } else { text .textSelection(.enabled) } } /// Set the font. /// - Parameter font: The font. /// - Returns: The text view. public func font(_ font: Font?) -> Self { modify { $0.font = font } } /// Whether the selection is disabled. /// - Parameter isDisabled: The selection is disabled. /// - Returns: The text view. public func selectionDisabled(_ isDisabled: Bool = true) -> Self { modify { $0.selectionDisabled = isDisabled } } }