Skip to content

Commit fa884c7

Browse files
committed
Fixed sheet rendering with GtkBackend on Linux
1 parent 7ec8b6d commit fa884c7

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

Sources/AppKitBackend/AppKitBackend.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,19 +1711,21 @@ public final class AppKitBackend: AppBackend {
17111711

17121712
public func updateSheet(
17131713
_ sheet: NSCustomSheet,
1714+
size: SIMD2<Int>,
17141715
onDismiss: @escaping () -> Void
17151716
) {
1717+
sheet.contentView?.frame.size = .init(width: size.x, height: size.y)
17161718
sheet.onDismiss = onDismiss
17171719
}
17181720

1719-
public func sizeOf(_ sheet: NSCustomSheet) -> SIMD2<Int> {
1721+
public func size(ofSheet sheet: NSCustomSheet) -> SIMD2<Int> {
17201722
guard let size = sheet.contentView?.frame.size else {
17211723
return SIMD2(x: 0, y: 0)
17221724
}
17231725
return SIMD2(x: Int(size.width), y: Int(size.height))
17241726
}
17251727

1726-
public func showSheet(_ sheet: NSCustomSheet, window: NSCustomWindow?) {
1728+
public func showSheet(_ sheet: NSCustomSheet, window: NSCustomWindow) {
17271729
guard let window else {
17281730
print("warning: Cannot show sheet without a parent window")
17291731
return

Sources/GtkBackend/GtkBackend.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,9 +1592,15 @@ public final class GtkBackend: AppBackend {
15921592
return sheet
15931593
}
15941594

1595-
public func updateSheet(_ sheet: Gtk.Window, onDismiss: @escaping () -> Void) {
1595+
public func updateSheet(
1596+
_ sheet: Gtk.Window,
1597+
size: SIMD2<Int>,
1598+
onDismiss: @escaping () -> Void
1599+
) {
15961600
let key: OpaquePointer = OpaquePointer(sheet.widgetPointer)
15971601

1602+
sheet.size = Size(width: size.x, height: size.y)
1603+
15981604
// Add a slight border to not be just a flat corner
15991605
sheet.css.set(property: .border(color: SwiftCrossUI.Color.gray.gtkColor, width: 1))
16001606

@@ -1629,10 +1635,10 @@ public final class GtkBackend: AppBackend {
16291635
}
16301636
}
16311637

1632-
public func showSheet(_ sheet: Gtk.Window, window: ApplicationWindow?) {
1638+
public func showSheet(_ sheet: Gtk.Window, window: ApplicationWindow) {
16331639
sheet.isModal = true
16341640
sheet.isDecorated = false
1635-
sheet.setTransient(for: window ?? windows[0])
1641+
sheet.setTransient(for: window)
16361642
sheet.present()
16371643
}
16381644

@@ -1646,7 +1652,7 @@ public final class GtkBackend: AppBackend {
16461652
connectedCloseHandlers.remove(key)
16471653
}
16481654

1649-
public func sizeOf(_ sheet: Gtk.Window) -> SIMD2<Int> {
1655+
public func size(ofSheet sheet: Gtk.Window) -> SIMD2<Int> {
16501656
return SIMD2(x: sheet.size.width, y: sheet.size.height)
16511657
}
16521658

Sources/SwiftCrossUI/Backend/AppBackend.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ public protocol AppBackend: Sendable {
612612
/// Updates the content and appearance of a sheet.
613613
func updateSheet(
614614
_ sheet: Sheet,
615+
size: SIMD2<Int>,
615616
onDismiss: @escaping () -> Void
616617
)
617618

@@ -626,15 +627,15 @@ public protocol AppBackend: Sendable {
626627
/// app modal, a standalone window, or a modal for a window of its choosing.
627628
func showSheet(
628629
_ sheet: Sheet,
629-
window: Window?
630+
window: Window
630631
)
631632

632633
/// Dismisses a sheet programmatically.
633634
/// Gets used by the ``View/sheet`` modifier to close a sheet.
634635
func dismissSheet(_ sheet: Sheet, window: Window)
635636

636637
/// Get the dimensions of a sheet
637-
func sizeOf(_ sheet: Sheet) -> SIMD2<Int>
638+
func size(ofSheet sheet: Sheet) -> SIMD2<Int>
638639

639640
/// Sets the corner radius for a sheet presentation.
640641
///
@@ -1266,20 +1267,21 @@ extension AppBackend {
12661267

12671268
public func updateSheet(
12681269
_ sheet: Sheet,
1270+
size: SIMD2<Int>,
12691271
onDismiss: @escaping () -> Void
12701272
) {
12711273
todo()
12721274
}
12731275

1274-
public func sizeOf(
1275-
sheet: Sheet
1276+
public func size(
1277+
ofSheet sheet: Sheet
12761278
) -> SIMD2<Int> {
12771279
todo()
12781280
}
12791281

12801282
public func showSheet(
12811283
_ sheet: Sheet,
1282-
window: Window?
1284+
window: Window
12831285
) {
12841286
todo()
12851287
}

Sources/SwiftCrossUI/Views/Modifiers/SheetModifier.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ struct SheetModifier<Content: View, SheetContent: View>: TypeSafeView {
8181
isPresented.wrappedValue = false
8282
})
8383
let sheetEnvironment = environment.with(\.dismiss, dismissAction)
84-
84+
8585
let result = children.sheetContentNode!.update(
8686
with: sheetContent(),
87-
proposedSize: backend.sizeOf(sheet),
87+
proposedSize: SIMD2(x: 10_000, y: 0),
8888
environment: sheetEnvironment,
8989
dryRun: false
9090
)
9191

9292
backend.updateSheet(
9393
sheet,
94+
size: result.size.size,
9495
onDismiss: { handleDismiss(children: children) }
9596
)
9697

@@ -122,7 +123,7 @@ struct SheetModifier<Content: View, SheetContent: View>: TypeSafeView {
122123

123124
backend.showSheet(
124125
sheet,
125-
window: .some(environment.window! as! Backend.Window)
126+
window: environment.window! as! Backend.Window
126127
)
127128
children.sheet = sheet
128129
} else if !isPresented.wrappedValue && children.sheet != nil {

0 commit comments

Comments
 (0)