forked from aparoksha/adwaita-swift
Extract about dialog conf options to separate file
This commit is contained in:
parent
9597c57b39
commit
b3f222e316
@ -15,19 +15,8 @@ struct AboutDialog: AdwaitaWidget {
|
|||||||
@Binding var visible: Bool
|
@Binding var visible: Bool
|
||||||
/// The wrapped view.
|
/// The wrapped view.
|
||||||
var child: AnyView
|
var child: AnyView
|
||||||
|
/// The dialog configuration options.
|
||||||
/// The app's name.
|
var config: AdwaitaAboutDialogConfig
|
||||||
var appName: String?
|
|
||||||
/// The developer's name.
|
|
||||||
var developer: String?
|
|
||||||
/// The app version.
|
|
||||||
var version: String?
|
|
||||||
/// The app icon.
|
|
||||||
var icon: Icon?
|
|
||||||
/// The app's website.
|
|
||||||
var website: URL?
|
|
||||||
/// The link for opening issues.
|
|
||||||
var issues: URL?
|
|
||||||
|
|
||||||
/// The ID for the dialog's storage.
|
/// The ID for the dialog's storage.
|
||||||
let dialogID = "dialog"
|
let dialogID = "dialog"
|
||||||
@ -36,30 +25,18 @@ struct AboutDialog: AdwaitaWidget {
|
|||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - visible: The visibility.
|
/// - visible: The visibility.
|
||||||
/// - child: The child view.
|
/// - child: The child view.
|
||||||
/// - appName: The app's name.
|
/// - configure: A closure that mutates the dialog configuration.
|
||||||
/// - developer: The developer's name.
|
|
||||||
/// - version: The version.
|
|
||||||
/// - icon: The icon.
|
|
||||||
/// - website: The website's URL.
|
|
||||||
/// - issues: The link for opening issues.
|
|
||||||
init(
|
init(
|
||||||
visible: Binding<Bool>,
|
visible: Binding<Bool>,
|
||||||
child: AnyView,
|
child: AnyView,
|
||||||
appName: String? = nil,
|
configure: (inout AdwaitaAboutDialogConfig) -> Void
|
||||||
developer: String? = nil,
|
|
||||||
version: String? = nil,
|
|
||||||
icon: Icon? = nil,
|
|
||||||
website: URL? = nil,
|
|
||||||
issues: URL? = nil
|
|
||||||
) {
|
) {
|
||||||
self._visible = visible
|
self._visible = visible
|
||||||
self.child = child
|
self.child = child
|
||||||
self.appName = appName
|
|
||||||
self.developer = developer
|
var cfg = AdwaitaAboutDialogConfig()
|
||||||
self.version = version
|
configure(&cfg)
|
||||||
self.icon = icon
|
self.config = cfg
|
||||||
self.website = website
|
|
||||||
self.issues = issues
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The view storage.
|
/// The view storage.
|
||||||
@ -97,26 +74,12 @@ struct AboutDialog: AdwaitaWidget {
|
|||||||
storage.opaquePointer?.cast()
|
storage.opaquePointer?.cast()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
let dialog = storage.content[dialogID]?.first?.opaquePointer
|
guard let dialog = storage.content[dialogID]?.first?.opaquePointer else {
|
||||||
if let appName {
|
return
|
||||||
adw_about_dialog_set_application_name(dialog, appName)
|
|
||||||
}
|
}
|
||||||
if let developer {
|
config.apply(to: dialog)
|
||||||
adw_about_dialog_set_developer_name(dialog, developer)
|
|
||||||
}
|
adw_dialog_set_content_height(dialog.cast(), -1)
|
||||||
if let version {
|
|
||||||
adw_about_dialog_set_version(dialog, version)
|
|
||||||
}
|
|
||||||
if let icon {
|
|
||||||
adw_about_dialog_set_application_icon(dialog, icon.string)
|
|
||||||
}
|
|
||||||
if let website {
|
|
||||||
adw_about_dialog_set_website(dialog, website.absoluteString)
|
|
||||||
}
|
|
||||||
if let issues {
|
|
||||||
adw_about_dialog_set_issue_url(dialog, issues.absoluteString)
|
|
||||||
}
|
|
||||||
adw_dialog_set_content_height(dialog?.cast(), -1)
|
|
||||||
} else {
|
} else {
|
||||||
if storage.content[dialogID]?.first != nil {
|
if storage.content[dialogID]?.first != nil {
|
||||||
let dialog = storage.content[dialogID]?.first?.opaquePointer
|
let dialog = storage.content[dialogID]?.first?.opaquePointer
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user