Add @State, StateBox, Binding, DependencyTracker, and SubscriptionToken for targeted reactive updates. Label gains two reactive overloads: Label(Binding<String>) for the explicit-binding path and Label(() -> String) for tracked closures. Both update the Gtk.Label text in-place without re-mounting. Regression tests verify label updates survive when the Swift wrapper is deallocated after the GObject is attached to the widget tree (GTK does not retain wrappers). Includes 28 new tests across ReactiveLabelTests and StateTests suites.
26 lines
571 B
Swift
26 lines
571 B
Swift
import Portico
|
|
|
|
struct Counter: View {
|
|
@State private var count = 0
|
|
|
|
var body: some View {
|
|
VStack(spacing: 12) {
|
|
Label { "Count: \(count)" }
|
|
HStack(spacing: 12) {
|
|
Button("-") { count -= 1 }
|
|
Button("+") { count += 1 }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@main
|
|
struct ExampleApp: App {
|
|
var applicationId: String? { "dev.bscubed.PorticoExample" }
|
|
|
|
var body: some Scene {
|
|
Window { _ in Counter() }
|
|
.title("Portico P1")
|
|
.defaultSize(width: 1280, height: 800)
|
|
}
|
|
}
|