adwaita-swift/Sources/Adwaita/View/StatusPage.swift
david-swift 921f025e39 Update demo and fix bugs
- Fix build optional in ViewBuilder
- Fix maximum size frame modifier
- Improve inspector wrapper
- Improve header bar
- Improve status page
- Improve the naming of some elements
2023-10-12 22:15:15 +02:00

62 lines
1.6 KiB
Swift

//
// StatusPage.swift
// Adwaita
//
// Created by david-swift on 25.09.23.
//
import GTUI
/// A status page widget.
public struct StatusPage: Widget {
/// The title.
var title: String
/// The description.
var description: String
/// The icon.
var icon: Icon
/// Additional content.
var content: Body
/// Initialize a status page widget.
/// - Parameters:
/// - title: The title.
/// - icon: The icon.
/// - description: Additional details.
/// - content: Additional content.
public init(
_ title: String,
icon: Icon? = nil,
description: String = "",
@ViewBuilder content: () -> Body = { [] }
) {
self.title = title
self.description = description
self.icon = icon ?? .custom(name: "")
self.content = content()
}
/// Update the view storage of the text widget.
/// - Parameter storage: The view storage.
public func update(_ storage: ViewStorage) {
if let statusPage = storage.view as? GTUI.StatusPage {
_ = statusPage.title(title).description(description).icon(icon)
}
if let storage = storage.content[.mainContent]?.first {
content.widget().update(storage)
}
}
/// Get the container of the text widget.
/// - Returns: The view storage.
public func container() -> ViewStorage {
let child = content.widget().container()
return .init(
GTUI.StatusPage().title(title).description(description).icon(icon).child(child.view),
content: [.mainContent: [child]]
)
}
}