Skip to content

Commit 548125f

Browse files
committed
Style TextField text to match foregroundColor when using GtkBackend
1 parent 498b8b3 commit 548125f

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ public final class AppKitBackend: AppBackend {
444444
}
445445

446446
public func updateTextField(
447-
_ textField: Widget, placeholder: String, onChange: @escaping (String) -> Void
447+
_ textField: Widget,
448+
placeholder: String,
449+
environment: Environment,
450+
onChange: @escaping (String) -> Void
448451
) {
449452
let textField = textField as! NSObservableTextField
450453
textField.placeholderString = placeholder

Sources/GtkBackend/GtkBackend.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,19 @@ public final class GtkBackend: AppBackend {
477477
}
478478

479479
public func updateTextField(
480-
_ textField: Widget, placeholder: String, onChange: @escaping (String) -> Void
480+
_ textField: Widget,
481+
placeholder: String,
482+
environment: Environment,
483+
onChange: @escaping (String) -> Void
481484
) {
482485
let textField = textField as! Entry
483486
textField.placeholderText = placeholder
484487
textField.changed = { widget in
485488
onChange(widget.text)
486489
}
490+
491+
textField.css.clear()
492+
textField.css.set(properties: Self.cssProperties(for: environment))
487493
}
488494

489495
public func setContent(ofTextField textField: Widget, to content: String) {

Sources/SwiftCrossUI/Backend/AppBackend.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ public protocol AppBackend {
313313
/// The backend shouldn't wait until the user finishes typing to call the change handler;
314314
/// it should allow live access to the value.
315315
func updateTextField(
316-
_ textField: Widget, placeholder: String, onChange: @escaping (String) -> Void
316+
_ textField: Widget,
317+
placeholder: String,
318+
environment: Environment,
319+
onChange: @escaping (String) -> Void
317320
)
318321
/// Sets the value of an editable text field.
319322
func setContent(ofTextField textField: Widget, to content: String)
@@ -501,7 +504,10 @@ extension AppBackend {
501504
todo()
502505
}
503506
public func updateTextField(
504-
_ textField: Widget, placeholder: String, onChange: @escaping (String) -> Void
507+
_ textField: Widget,
508+
placeholder: String,
509+
environment: Environment,
510+
onChange: @escaping (String) -> Void
505511
) {
506512
todo()
507513
}

Sources/SwiftCrossUI/Views/TextField.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public struct TextField: ElementaryView, View {
2323
dryRun: Bool
2424
) -> ViewSize {
2525
if !dryRun {
26-
backend.updateTextField(widget, placeholder: placeholder) { newValue in
26+
backend.updateTextField(
27+
widget,
28+
placeholder: placeholder,
29+
environment: environment
30+
) { newValue in
2731
self.value?.wrappedValue = newValue
2832
}
2933
if let value = value?.wrappedValue, value != backend.getContent(ofTextField: widget) {

0 commit comments

Comments
 (0)