adwaita-swift/Sources/Adwaita/View/Forms/PasswordEntryRow+.swift
david-swift 04c77831b5
Some checks are pending
Deploy Docs / publish (push) Waiting to run
SwiftLint / SwiftLint (push) Waiting to run
Remove Core library
2025-10-30 21:36:13 +01:00

40 lines
1.1 KiB
Swift

//
// PasswordEntryRow+.swift
// Adwaita
//
// Created by david-swift on 20.01.24.
//
import CAdw
extension PasswordEntryRow {
/// Initialize an entry row.
/// - Parameters:
/// - title: The row's title.
/// - text: The text.
public init(_ title: String, text: Binding<String>) {
self.init()
self = self.title(title)
updateFunctions.append { storage, _, _ in
storage.notify(name: "text") {
let newValue = String(cString: gtk_editable_get_text(storage.opaquePointer))
if text.wrappedValue != newValue {
text.wrappedValue = newValue
}
}
if text.wrappedValue != .init(cString: gtk_editable_get_text(storage.opaquePointer)) {
gtk_editable_set_text(storage.opaquePointer, text.wrappedValue)
}
}
}
/// Set the entry row's subtitle.
/// - Parameter subtitle: The subtitle.
/// - Returns: The entry row.
public func onSubmit(_ onSubmit: @escaping () -> Void) -> Self {
apply(onSubmit)
}
}