forked from aparoksha/adwaita-swift
Add support for setting a dialog's width & height
This commit is contained in:
parent
8b4ce2bede
commit
d32aaa9de7
@ -18,6 +18,10 @@ struct Dialog: Widget {
|
||||
var child: View
|
||||
/// The content of the dialog.
|
||||
var content: Body
|
||||
/// The dialog's width.
|
||||
var width: Int?
|
||||
/// The dialog's height.
|
||||
var height: Int?
|
||||
|
||||
/// The ID for the dialog's storage.
|
||||
let dialogID = "dialog"
|
||||
@ -53,7 +57,10 @@ struct Dialog: Widget {
|
||||
createDialog(storage: storage, modifiers: modifiers)
|
||||
adw_dialog_present(storage.content[dialogID]?.first?.pointer?.cast(), storage.pointer?.cast())
|
||||
}
|
||||
adw_dialog_set_title(storage.content[dialogID]?.first?.pointer?.cast(), title ?? "")
|
||||
let pointer = storage.content[dialogID]?.first?.pointer
|
||||
adw_dialog_set_title(pointer?.cast(), title ?? "")
|
||||
adw_dialog_set_content_width(pointer?.cast(), width?.cInt ?? -1)
|
||||
adw_dialog_set_content_height(pointer?.cast(), height?.cInt ?? -1)
|
||||
} else {
|
||||
if storage.content[dialogID]?.first != nil {
|
||||
adw_dialog_close(storage.content[dialogID]?.first?.pointer?.cast())
|
||||
@ -89,9 +96,17 @@ extension View {
|
||||
/// - Parameters:
|
||||
/// - visible: Whether the dialog is presented.
|
||||
/// - title: The dialog's title.
|
||||
/// - width: The dialog's width.
|
||||
/// - height: The dialog's height.
|
||||
/// - content: The dialog's content.
|
||||
public func dialog(visible: Binding<Bool>, title: String? = nil, @ViewBuilder content: () -> Body) -> View {
|
||||
Dialog(visible: visible, title: title, child: self, content: content())
|
||||
public func dialog(
|
||||
visible: Binding<Bool>,
|
||||
title: String? = nil,
|
||||
width: Int? = nil,
|
||||
height: Int? = nil,
|
||||
@ViewBuilder content: () -> Body
|
||||
) -> View {
|
||||
Dialog(visible: visible, title: title, child: self, content: content(), width: width, height: height)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,6 +13,8 @@ struct DialogDemo: View {
|
||||
|
||||
@State private var dialog = false
|
||||
let padding = 20
|
||||
let width = 300
|
||||
let height = 200
|
||||
|
||||
var view: Body {
|
||||
VStack {
|
||||
@ -23,7 +25,7 @@ struct DialogDemo: View {
|
||||
.frame(maxSize: 100)
|
||||
.padding()
|
||||
}
|
||||
.dialog(visible: $dialog, title: "Counter") {
|
||||
.dialog(visible: $dialog, title: "Counter", width: width, height: height) {
|
||||
CounterDemo()
|
||||
.padding(padding)
|
||||
.topToolbar {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user