From 8eeda083e9be6de24496f254de90787b87fdad1f Mon Sep 17 00:00:00 2001 From: david-swift Date: Wed, 16 Oct 2024 14:22:34 +0200 Subject: [PATCH] Separate AnyView extensions from widgets --- .swiftlint.yml | 3 +- Package.swift | 10 +- Sources/Adwaita/ActionRow+.swift | 17 ++ .../AnyView+.swift => AnyView++.swift} | 4 +- Sources/Adwaita/AnyView+.swift | 270 ++++++++++++++++++ Sources/Adwaita/Box+.swift | 15 + Sources/Adwaita/{View => }/CheckButton+.swift | 0 Sources/Adwaita/List+.swift | 24 ++ Sources/Adwaita/StatusPage+.swift | 17 ++ Sources/Adwaita/View/Modifiers/Clamp+.swift | 45 --- .../{Adwaita => Core}/Menu/MenuButton.swift | 0 .../Menu/MenuCollection.swift | 0 .../{Adwaita => Core}/Menu/MenuContext.swift | 0 .../Menu/MenuEitherView.swift | 0 .../{Adwaita => Core}/Menu/MenuSection.swift | 0 Sources/{Adwaita => Core}/Menu/Submenu.swift | 0 .../{Adwaita => Core}/Model/AdwaitaApp.swift | 0 .../Model/AdwaitaMainView.swift | 0 .../Model/AdwaitaSceneElement.swift | 0 .../Model/AdwaitaWidget.swift | 0 .../Model/Enumerations/Alignment.swift | 0 .../Model/Enumerations/ContentFit.swift | 0 .../Model/Enumerations/Edge.swift | 0 .../Model/Enumerations/Icon.swift | 0 .../Model/Enumerations/Transition.swift | 0 .../Model/Extensions/Array.swift | 0 .../Model/Extensions/Bool.swift | 0 .../Model/Extensions/Int.swift | 0 .../Model/Extensions/OpaquePointer.swift | 0 .../Model/Extensions/Set.swift | 0 .../Model/Extensions/String.swift | 4 +- .../Model/Extensions/UInt.swift | 0 .../Extensions/UnsafeMutablePointer.swift | 0 .../Extensions/UnsafeMutableRawPointer.swift | 0 .../Model/Extensions/ViewStorage.swift | 0 Sources/{Adwaita => Core}/Model/Idle.swift | 0 .../Model/Signals/SignalData.swift | 0 Sources/{Adwaita => Core}/Model/Storage.swift | 0 .../{Adwaita => Core}/Model/WindowView.swift | 0 Sources/{Adwaita => Core}/View/Banner+.swift | 0 Sources/{Adwaita => Core}/View/Button+.swift | 0 .../{Adwaita => Core}/View/Carousel+.swift | 0 .../View/Dialogs/AboutDialog.swift | 70 +++-- .../View/Dialogs/AlertDialog.swift | 45 ++- .../View/Dialogs/Dialog.swift | 63 ++-- .../View/Dialogs/FileDialog.swift | 96 +++---- .../{Adwaita => Core}/View/EitherView.swift | 0 Sources/{Adwaita => Core}/View/Fixed+.swift | 0 Sources/{Adwaita => Core}/View/FlowBox+.swift | 0 Sources/{Adwaita => Core}/View/ForEach.swift | 0 .../View/Forms/ActionRow+.swift | 7 - .../View/Forms/ComboRow+.swift | 0 .../View/Forms/EntryRow+.swift | 0 .../{Adwaita => Core}/View/Forms/Form.swift | 7 +- .../View/Forms/FormSection+.swift | 0 .../View/Forms/PasswordEntryRow+.swift | 0 .../View/Forms/SpinRow+.swift | 0 .../View/Forms/SwitchRow+.swift | 0 .../View/Generated/ActionRow.swift | 0 .../View/Generated/AspectFrame.swift | 0 .../View/Generated/Avatar.swift | 0 .../View/Generated/Banner.swift | 0 .../View/Generated/Bin.swift | 0 .../View/Generated/Box.swift | 0 .../View/Generated/Button.swift | 0 .../View/Generated/ButtonContent.swift | 0 .../View/Generated/Carousel.swift | 0 .../View/Generated/CenterBox.swift | 0 .../View/Generated/CheckButton.swift | 0 .../View/Generated/Clamp.swift | 0 .../View/Generated/ComboRow.swift | 0 .../View/Generated/EntryRow.swift | 0 .../View/Generated/ExpanderRow.swift | 0 .../View/Generated/Fixed.swift | 0 .../View/Generated/FlowBox.swift | 0 .../View/Generated/HeaderBar.swift | 0 .../View/Generated/Label.swift | 0 .../View/Generated/LevelBar.swift | 0 .../View/Generated/LinkButton.swift | 0 .../View/Generated/ListBox.swift | 0 .../View/Generated/Menu.swift | 0 .../View/Generated/NavigationView.swift | 0 .../View/Generated/Overlay.swift | 0 .../View/Generated/OverlaySplitView.swift | 0 .../View/Generated/PasswordEntryRow.swift | 0 .../View/Generated/Picture.swift | 0 .../View/Generated/Popover.swift | 0 .../View/Generated/PreferencesGroup.swift | 0 .../View/Generated/PreferencesPage.swift | 0 .../View/Generated/PreferencesRow.swift | 0 .../View/Generated/ProgressBar.swift | 0 .../View/Generated/ScrolledWindow.swift | 0 .../View/Generated/SearchBar.swift | 0 .../View/Generated/SearchEntry.swift | 0 .../View/Generated/Separator.swift | 0 .../View/Generated/SpinRow.swift | 0 .../View/Generated/Spinner.swift | 0 .../View/Generated/SplitButton.swift | 0 .../View/Generated/StatusPage.swift | 0 .../View/Generated/SwitchRow.swift | 0 .../View/Generated/ToastOverlay.swift | 0 .../View/Generated/ToggleButton.swift | 0 .../View/Generated/ToolbarView.swift | 0 .../View/Generated/WindowTitle.swift | 0 Sources/{Adwaita => Core}/View/HStack.swift | 3 +- .../{Adwaita => Core}/View/HeaderBar+.swift | 0 Sources/{Adwaita => Core}/View/List.swift | 14 - Sources/{Adwaita => Core}/View/Menu+.swift | 0 Sources/Core/View/Modifiers/Clamp+.swift | 23 ++ .../View/Modifiers/ModifierWrapper.swift | 134 ++++----- .../View/Modifiers/Popover+.swift | 18 +- .../View/Modifiers/ToastOverlay+.swift | 27 -- .../View/NavigationSplitView.swift | 0 .../View/NavigationView+.swift | 0 .../View/OverlaySplitView+.swift | 0 Sources/{Adwaita => Core}/View/Picture+.swift | 0 .../{Adwaita => Core}/View/ProgressBar+.swift | 0 .../{Adwaita => Core}/View/ScrollView.swift | 0 .../{Adwaita => Core}/View/StatusPage+.swift | 7 - Sources/{Adwaita => Core}/View/Text.swift | 0 Sources/{Adwaita => Core}/View/Toggle.swift | 0 Sources/{Adwaita => Core}/View/VStack.swift | 5 - .../{Adwaita => Core}/View/ViewStack.swift | 0 .../{Adwaita => Core}/View/ViewSwitcher.swift | 0 Sources/{Adwaita => Core}/Window/Window.swift | 0 .../Generation/GenerationConfiguration.swift | 2 +- 126 files changed, 559 insertions(+), 371 deletions(-) create mode 100644 Sources/Adwaita/ActionRow+.swift rename Sources/Adwaita/{View/Modifiers/AnyView+.swift => AnyView++.swift} (99%) create mode 100644 Sources/Adwaita/AnyView+.swift create mode 100644 Sources/Adwaita/Box+.swift rename Sources/Adwaita/{View => }/CheckButton+.swift (100%) create mode 100644 Sources/Adwaita/List+.swift create mode 100644 Sources/Adwaita/StatusPage+.swift delete mode 100644 Sources/Adwaita/View/Modifiers/Clamp+.swift rename Sources/{Adwaita => Core}/Menu/MenuButton.swift (100%) rename Sources/{Adwaita => Core}/Menu/MenuCollection.swift (100%) rename Sources/{Adwaita => Core}/Menu/MenuContext.swift (100%) rename Sources/{Adwaita => Core}/Menu/MenuEitherView.swift (100%) rename Sources/{Adwaita => Core}/Menu/MenuSection.swift (100%) rename Sources/{Adwaita => Core}/Menu/Submenu.swift (100%) rename Sources/{Adwaita => Core}/Model/AdwaitaApp.swift (100%) rename Sources/{Adwaita => Core}/Model/AdwaitaMainView.swift (100%) rename Sources/{Adwaita => Core}/Model/AdwaitaSceneElement.swift (100%) rename Sources/{Adwaita => Core}/Model/AdwaitaWidget.swift (100%) rename Sources/{Adwaita => Core}/Model/Enumerations/Alignment.swift (100%) rename Sources/{Adwaita => Core}/Model/Enumerations/ContentFit.swift (100%) rename Sources/{Adwaita => Core}/Model/Enumerations/Edge.swift (100%) rename Sources/{Adwaita => Core}/Model/Enumerations/Icon.swift (100%) rename Sources/{Adwaita => Core}/Model/Enumerations/Transition.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/Array.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/Bool.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/Int.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/OpaquePointer.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/Set.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/String.swift (89%) rename Sources/{Adwaita => Core}/Model/Extensions/UInt.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/UnsafeMutablePointer.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/UnsafeMutableRawPointer.swift (100%) rename Sources/{Adwaita => Core}/Model/Extensions/ViewStorage.swift (100%) rename Sources/{Adwaita => Core}/Model/Idle.swift (100%) rename Sources/{Adwaita => Core}/Model/Signals/SignalData.swift (100%) rename Sources/{Adwaita => Core}/Model/Storage.swift (100%) rename Sources/{Adwaita => Core}/Model/WindowView.swift (100%) rename Sources/{Adwaita => Core}/View/Banner+.swift (100%) rename Sources/{Adwaita => Core}/View/Button+.swift (100%) rename Sources/{Adwaita => Core}/View/Carousel+.swift (100%) rename Sources/{Adwaita => Core}/View/Dialogs/AboutDialog.swift (81%) rename Sources/{Adwaita => Core}/View/Dialogs/AlertDialog.swift (95%) rename Sources/{Adwaita => Core}/View/Dialogs/Dialog.swift (82%) rename Sources/{Adwaita => Core}/View/Dialogs/FileDialog.swift (74%) rename Sources/{Adwaita => Core}/View/EitherView.swift (100%) rename Sources/{Adwaita => Core}/View/Fixed+.swift (100%) rename Sources/{Adwaita => Core}/View/FlowBox+.swift (100%) rename Sources/{Adwaita => Core}/View/ForEach.swift (100%) rename Sources/{Adwaita => Core}/View/Forms/ActionRow+.swift (55%) rename Sources/{Adwaita => Core}/View/Forms/ComboRow+.swift (100%) rename Sources/{Adwaita => Core}/View/Forms/EntryRow+.swift (100%) rename Sources/{Adwaita => Core}/View/Forms/Form.swift (72%) rename Sources/{Adwaita => Core}/View/Forms/FormSection+.swift (100%) rename Sources/{Adwaita => Core}/View/Forms/PasswordEntryRow+.swift (100%) rename Sources/{Adwaita => Core}/View/Forms/SpinRow+.swift (100%) rename Sources/{Adwaita => Core}/View/Forms/SwitchRow+.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ActionRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/AspectFrame.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Avatar.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Banner.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Bin.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Box.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Button.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ButtonContent.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Carousel.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/CenterBox.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/CheckButton.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Clamp.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ComboRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/EntryRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ExpanderRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Fixed.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/FlowBox.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/HeaderBar.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Label.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/LevelBar.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/LinkButton.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ListBox.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Menu.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/NavigationView.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Overlay.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/OverlaySplitView.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/PasswordEntryRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Picture.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Popover.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/PreferencesGroup.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/PreferencesPage.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/PreferencesRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ProgressBar.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ScrolledWindow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/SearchBar.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/SearchEntry.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Separator.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/SpinRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/Spinner.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/SplitButton.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/StatusPage.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/SwitchRow.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ToastOverlay.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ToggleButton.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/ToolbarView.swift (100%) rename Sources/{Adwaita => Core}/View/Generated/WindowTitle.swift (100%) rename Sources/{Adwaita => Core}/View/HStack.swift (85%) rename Sources/{Adwaita => Core}/View/HeaderBar+.swift (100%) rename Sources/{Adwaita => Core}/View/List.swift (81%) rename Sources/{Adwaita => Core}/View/Menu+.swift (100%) create mode 100644 Sources/Core/View/Modifiers/Clamp+.swift rename Sources/{Adwaita => Core}/View/Modifiers/ModifierWrapper.swift (65%) rename Sources/{Adwaita => Core}/View/Modifiers/Popover+.swift (60%) rename Sources/{Adwaita => Core}/View/Modifiers/ToastOverlay+.swift (61%) rename Sources/{Adwaita => Core}/View/NavigationSplitView.swift (100%) rename Sources/{Adwaita => Core}/View/NavigationView+.swift (100%) rename Sources/{Adwaita => Core}/View/OverlaySplitView+.swift (100%) rename Sources/{Adwaita => Core}/View/Picture+.swift (100%) rename Sources/{Adwaita => Core}/View/ProgressBar+.swift (100%) rename Sources/{Adwaita => Core}/View/ScrollView.swift (100%) rename Sources/{Adwaita => Core}/View/StatusPage+.swift (74%) rename Sources/{Adwaita => Core}/View/Text.swift (100%) rename Sources/{Adwaita => Core}/View/Toggle.swift (100%) rename Sources/{Adwaita => Core}/View/VStack.swift (95%) rename Sources/{Adwaita => Core}/View/ViewStack.swift (100%) rename Sources/{Adwaita => Core}/View/ViewSwitcher.swift (100%) rename Sources/{Adwaita => Core}/Window/Window.swift (100%) diff --git a/.swiftlint.yml b/.swiftlint.yml index cbb68f0..c6d38bd 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -154,6 +154,5 @@ type_contents_order: - other_method excluded: - - Sources/Adwaita/View/Generated/ - - Sources/Adwaita/Adwaita.docc/ + - Sources/Core/View/Generated/ - .build/ \ No newline at end of file diff --git a/Package.swift b/Package.swift index 15f61de..9062813 100644 --- a/Package.swift +++ b/Package.swift @@ -17,6 +17,10 @@ let package = Package( name: "Adwaita", targets: ["Adwaita"] ), + .library( + name: "Core", + targets: ["Core"] + ), .library( name: "CAdw", targets: ["CAdw"] @@ -37,7 +41,7 @@ let package = Package( pkgConfig: "libadwaita-1" ), .target( - name: "Adwaita", + name: "Core", dependencies: [ "CAdw", .product(name: "LevenshteinTransformations", package: "levenshtein-transformations"), @@ -45,6 +49,10 @@ let package = Package( .product(name: "MetaSQLite", package: "meta-sqlite") ] ), + .target( + name: "Adwaita", + dependencies: ["Core"] + ), .executableTarget( name: "Generation", dependencies: [ diff --git a/Sources/Adwaita/ActionRow+.swift b/Sources/Adwaita/ActionRow+.swift new file mode 100644 index 0000000..c0a3016 --- /dev/null +++ b/Sources/Adwaita/ActionRow+.swift @@ -0,0 +1,17 @@ +// +// ActionRow+.swift +// Adwaita +// +// Created by david-swift on 16.10.24. +// + +extension ActionRow { + + /// Deemphasize the row title and emphasize the subtitle. + /// - Parameter active: Whether the style is currently applied. + /// - Returns: A view. + public func property(_ active: Bool = true) -> AnyView { + style("property", active: active) + } + +} diff --git a/Sources/Adwaita/View/Modifiers/AnyView+.swift b/Sources/Adwaita/AnyView++.swift similarity index 99% rename from Sources/Adwaita/View/Modifiers/AnyView+.swift rename to Sources/Adwaita/AnyView++.swift index 961cd38..3225ed8 100644 --- a/Sources/Adwaita/View/Modifiers/AnyView+.swift +++ b/Sources/Adwaita/AnyView++.swift @@ -1,8 +1,8 @@ // -// AnyView+.swift +// AnyView++.swift // Adwaita // -// Created by david-swift on 01.08.24. +// Created by david-swift on 16.10.24. // import CAdw diff --git a/Sources/Adwaita/AnyView+.swift b/Sources/Adwaita/AnyView+.swift new file mode 100644 index 0000000..9702baf --- /dev/null +++ b/Sources/Adwaita/AnyView+.swift @@ -0,0 +1,270 @@ +// +// AnyView+.swift +// Adwaita +// +// Created by david-swift on 16.10.24. +// + +@_exported import Core +import Foundation + +extension AnyView { + + /// Add an about dialog to the parent window. + /// - Parameters: + /// - visible: Whether the dialog is presented. + /// - app: The app's name. + /// - developer: The developer's name. + /// - version: The version string. + /// - icon: The app icon. + /// - website: The app's website. + /// - issues: Website for reporting issues. + public func aboutDialog( + visible: Binding, + app: String? = nil, + developer: String? = nil, + version: String? = nil, + icon: Icon? = nil, + website: URL? = nil, + issues: URL? = nil + ) -> AnyView { + AboutDialog( + visible: visible, + child: self, + appName: app, + developer: developer, + version: version, + icon: icon, + website: website, + issues: issues + ) + } + + /// Add an alert dialog to the parent window. + /// - Parameters: + /// - visible: Whether the dialog is presented. + /// - heading: The heading. + /// - body: The body text. + public func alertDialog( + visible: Binding, + heading: String, + body: String = "", + id: String? = nil + ) -> AlertDialog { + .init( + visible: visible, + child: self, + id: id ?? "no-id", + heading: heading, + body: body + ) + } + + /// Add a dialog to the parent window. + /// - 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, + title: String? = nil, + id: String? = nil, + width: Int? = nil, + height: Int? = nil, + @ViewBuilder content: () -> Body + ) -> AnyView { + Dialog( + visible: visible, + child: self, + id: id ?? "", + content: content(), + title: title, + width: width, + height: height + ) + } + + /// Create an importer file dialog. + /// - Parameters: + /// - open: The signal to open the dialog. + /// - initialFolder: The URL to the folder open when being opened. + /// - extensions: The accepted file extensions. + /// - folders: Whether folders are accepted. + /// - onOpen: Run this when a file for importing has been chosen. + /// - onClose: Run this when the user cancelled the action. + public func fileImporter( + open: Signal, + initialFolder: URL? = nil, + extensions: [String]? = nil, + onOpen: @escaping (URL) -> Void, + onClose: @escaping () -> Void + ) -> AnyView { + FileDialog( + importer: true, + open: open, + child: self, + result: onOpen, + cancel: onClose, + initialFolder: initialFolder, + initialName: nil, + extensions: extensions + ) + } + + /// Create an exporter file dialog. + /// - Parameters: + /// - exporter: The signal to open the dialog. + /// - initialFolder: The URL to the folder open when being opened. + /// - initialName: The default file name. + /// - onSave: Run this when a path for exporting has been chosen. + /// - onClose: Run this when the user cancelled the action. + public func fileExporter( + open: Signal, + initialFolder: URL? = nil, + initialName: String? = nil, + onSave: @escaping (URL) -> Void, + onClose: @escaping () -> Void + ) -> AnyView { + FileDialog( + importer: false, + open: open, + child: self, + result: onSave, + cancel: onClose, + initialFolder: initialFolder, + initialName: initialName + ) + } + + /// Add a popover on top of the view. + /// - Parameters: + /// - visible: Whether the popover is displayed. + /// - content: The popover's content. + /// - Returns: The view. + public func popover(visible: Binding, @ViewBuilder content: @escaping () -> Body) -> Overlay { + overlay { + Popover(visible: visible) + .child(content) + } + } + + /// Set the view's maximum width. + /// - Parameter maxWidth: The maximum width. + /// - Returns: A view. + public func frame(maxWidth: Int? = nil) -> Clamp { + .init() + .child { self } + .maximumSize(maxWidth ?? -1) + } + + /// Set the view's maximum height. + /// - Parameter maxHeight: The maximum height. + /// - Returns: A view. + public func frame(maxHeight: Int? = nil) -> Clamp { + .init(vertical: true) + .child { self } + .maximumSize(maxHeight ?? -1) + } + + /// Add padding around a view. + /// - Parameters: + /// - padding: The size of the padding. + /// - edges: The edges which are affected by the padding. + /// - Returns: A view. + public func padding(_ padding: Int = 10, _ edges: Set = .all) -> AnyView { + ModifierWrapper(content: self, padding: padding, edges: edges) + } + + /// Enable or disable the horizontal expansion. + /// - Parameter enabled: Whether it is enabled or disabled. + /// - Returns: A view. + public func hexpand(_ enabled: Bool = true) -> AnyView { + ModifierWrapper(content: self, hexpand: enabled) + } + + /// Enable or disable the vertical expansion. + /// - Parameter enabled: Whether it is enabled or disabled. + /// - Returns: A view. + public func vexpand(_ enabled: Bool = true) -> AnyView { + ModifierWrapper(content: self, vexpand: enabled) + } + + /// Set the horizontal alignment. + /// - Parameter align: The alignment. + /// - Returns: A view. + public func halign(_ align: Alignment) -> AnyView { + ModifierWrapper(content: self, halign: align) + } + + /// Set the vertical alignment. + /// - Parameter align: The alignment. + /// - Returns: A view. + public func valign(_ align: Alignment) -> AnyView { + ModifierWrapper(content: self, valign: align) + } + + /// Set the view's minimal width or height. + /// - Parameters: + /// - minWidth: The minimal width. + /// - minHeight: The minimal height. + /// - Returns: A view. + public func frame(minWidth: Int? = nil, minHeight: Int? = nil) -> AnyView { + ModifierWrapper(content: self, minWidth: minWidth, minHeight: minHeight) + } + + /// Add a style class to the view. + /// - Parameters: + /// - style: The style class. + /// - active: Whether the style is currently applied. + /// - Returns: A view. + public func style(_ style: String, active: Bool = true) -> AnyView { + ModifierWrapper(content: self, style: style, styleActive: active) + } + + /// Make the view insensitive (useful e.g. in overlays). + /// - Parameter insensitive: Whether the view is insensitive. + /// - Returns: A view. + public func insensitive(_ insensitive: Bool = true) -> AnyView { + ModifierWrapper(content: self, insensitive: insensitive) + } + + /// Set the view's visibility. + /// - Parameter visible: Whether the view is visible. + /// - Returns: A view. + public func visible(_ visible: Bool = true) -> AnyView { + ModifierWrapper(content: self, visible: visible) + } + + /// Add a tooltip to the widget. + /// - Parameter tooltip: The tooltip text. + /// - Returns: A view. + public func tooltip(_ tooltip: String) -> AnyView { + ModifierWrapper(content: self, tooltip: tooltip) + } + + /// Present a toast when the signal gets activated. + /// - Parameters: + /// - title: The title of the toast. + /// - signal: The signal which activates the presentation of a toast. + /// - Returns: A view. + public func toast(_ title: String, signal: Signal) -> ToastOverlay { + .init(title, signal: signal) + .child { self } + } + + /// Present a toast with a button when the signal gets activated. + /// - Parameters: + /// - title: The title of the toast. + /// - signal: The signal which activates the presentation of a toast. + /// - button: The button's label. + /// - handler: The handler for the button. + /// - Returns: A view. + public func toast(_ title: String, signal: Signal, button: String, handler: @escaping () -> Void) -> ToastOverlay { + .init(title, signal: signal) + .child { self } + .action(button: button, handler: handler) + } + +} diff --git a/Sources/Adwaita/Box+.swift b/Sources/Adwaita/Box+.swift new file mode 100644 index 0000000..96a5e0e --- /dev/null +++ b/Sources/Adwaita/Box+.swift @@ -0,0 +1,15 @@ +// +// Box+.swift +// Adwaita +// +// Created by david-swift on 16.10.24. +// + +extension Box { + + /// Link the children. + public func linked(_ active: Bool = true) -> AnyView { + style("linked", active: active) + } + +} diff --git a/Sources/Adwaita/View/CheckButton+.swift b/Sources/Adwaita/CheckButton+.swift similarity index 100% rename from Sources/Adwaita/View/CheckButton+.swift rename to Sources/Adwaita/CheckButton+.swift diff --git a/Sources/Adwaita/List+.swift b/Sources/Adwaita/List+.swift new file mode 100644 index 0000000..e3a6faf --- /dev/null +++ b/Sources/Adwaita/List+.swift @@ -0,0 +1,24 @@ +// +// List+.swift +// Adwaita +// +// Created by david-swift on 16.10.24. +// + +extension List { + + /// Add the "navigation-sidebar" style class. + /// - Parameter active: Whether the style is applied. + /// - Returns: A view. + public func sidebarStyle(_ active: Bool = true) -> AnyView { + style("navigation-sidebar", active: active) + } + + /// Apply the boxed list style class. + /// - Parameter active: Whether the style is applied. + /// - Returns: A view. + public func boxedList(_ active: Bool = true) -> AnyView { + style("boxed-list", active: active) + } + +} diff --git a/Sources/Adwaita/StatusPage+.swift b/Sources/Adwaita/StatusPage+.swift new file mode 100644 index 0000000..d5df4c0 --- /dev/null +++ b/Sources/Adwaita/StatusPage+.swift @@ -0,0 +1,17 @@ +// +// StatusPage+.swift +// Adwaita +// +// Created by david-swift on 16.10.24. +// + +extension StatusPage { + + /// Make the status page more compact. + /// - Parameter active: Whether the style is applied. + /// - Returns: A view. + public func compact(_ active: Bool = true) -> AnyView { + style("compact", active: active) + } + +} diff --git a/Sources/Adwaita/View/Modifiers/Clamp+.swift b/Sources/Adwaita/View/Modifiers/Clamp+.swift deleted file mode 100644 index 1840d3d..0000000 --- a/Sources/Adwaita/View/Modifiers/Clamp+.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// Clamp+.swift -// Adwaita -// -// Created by david-swift on 20.01.24. -// - -import CAdw - -extension Clamp { - - /// Initialize either a horizontal or vertical clamp. - /// - Parameter vertical: Whether it is a vertical clamp. - init(vertical: Bool) { - self.init() - if vertical { - appearFunctions.append { storage, _ in - gtk_orientable_set_orientation(storage.opaquePointer, GTK_ORIENTATION_VERTICAL) - } - } - } - -} - -extension AnyView { - - /// Set the view's maximum width. - /// - Parameter maxWidth: The maximum width. - /// - Returns: A view. - public func frame(maxWidth: Int? = nil) -> Clamp { - .init() - .child { self } - .maximumSize(maxWidth ?? -1) - } - - /// Set the view's maximum height. - /// - Parameter maxHeight: The maximum height. - /// - Returns: A view. - public func frame(maxHeight: Int? = nil) -> Clamp { - .init(vertical: true) - .child { self } - .maximumSize(maxHeight ?? -1) - } - -} diff --git a/Sources/Adwaita/Menu/MenuButton.swift b/Sources/Core/Menu/MenuButton.swift similarity index 100% rename from Sources/Adwaita/Menu/MenuButton.swift rename to Sources/Core/Menu/MenuButton.swift diff --git a/Sources/Adwaita/Menu/MenuCollection.swift b/Sources/Core/Menu/MenuCollection.swift similarity index 100% rename from Sources/Adwaita/Menu/MenuCollection.swift rename to Sources/Core/Menu/MenuCollection.swift diff --git a/Sources/Adwaita/Menu/MenuContext.swift b/Sources/Core/Menu/MenuContext.swift similarity index 100% rename from Sources/Adwaita/Menu/MenuContext.swift rename to Sources/Core/Menu/MenuContext.swift diff --git a/Sources/Adwaita/Menu/MenuEitherView.swift b/Sources/Core/Menu/MenuEitherView.swift similarity index 100% rename from Sources/Adwaita/Menu/MenuEitherView.swift rename to Sources/Core/Menu/MenuEitherView.swift diff --git a/Sources/Adwaita/Menu/MenuSection.swift b/Sources/Core/Menu/MenuSection.swift similarity index 100% rename from Sources/Adwaita/Menu/MenuSection.swift rename to Sources/Core/Menu/MenuSection.swift diff --git a/Sources/Adwaita/Menu/Submenu.swift b/Sources/Core/Menu/Submenu.swift similarity index 100% rename from Sources/Adwaita/Menu/Submenu.swift rename to Sources/Core/Menu/Submenu.swift diff --git a/Sources/Adwaita/Model/AdwaitaApp.swift b/Sources/Core/Model/AdwaitaApp.swift similarity index 100% rename from Sources/Adwaita/Model/AdwaitaApp.swift rename to Sources/Core/Model/AdwaitaApp.swift diff --git a/Sources/Adwaita/Model/AdwaitaMainView.swift b/Sources/Core/Model/AdwaitaMainView.swift similarity index 100% rename from Sources/Adwaita/Model/AdwaitaMainView.swift rename to Sources/Core/Model/AdwaitaMainView.swift diff --git a/Sources/Adwaita/Model/AdwaitaSceneElement.swift b/Sources/Core/Model/AdwaitaSceneElement.swift similarity index 100% rename from Sources/Adwaita/Model/AdwaitaSceneElement.swift rename to Sources/Core/Model/AdwaitaSceneElement.swift diff --git a/Sources/Adwaita/Model/AdwaitaWidget.swift b/Sources/Core/Model/AdwaitaWidget.swift similarity index 100% rename from Sources/Adwaita/Model/AdwaitaWidget.swift rename to Sources/Core/Model/AdwaitaWidget.swift diff --git a/Sources/Adwaita/Model/Enumerations/Alignment.swift b/Sources/Core/Model/Enumerations/Alignment.swift similarity index 100% rename from Sources/Adwaita/Model/Enumerations/Alignment.swift rename to Sources/Core/Model/Enumerations/Alignment.swift diff --git a/Sources/Adwaita/Model/Enumerations/ContentFit.swift b/Sources/Core/Model/Enumerations/ContentFit.swift similarity index 100% rename from Sources/Adwaita/Model/Enumerations/ContentFit.swift rename to Sources/Core/Model/Enumerations/ContentFit.swift diff --git a/Sources/Adwaita/Model/Enumerations/Edge.swift b/Sources/Core/Model/Enumerations/Edge.swift similarity index 100% rename from Sources/Adwaita/Model/Enumerations/Edge.swift rename to Sources/Core/Model/Enumerations/Edge.swift diff --git a/Sources/Adwaita/Model/Enumerations/Icon.swift b/Sources/Core/Model/Enumerations/Icon.swift similarity index 100% rename from Sources/Adwaita/Model/Enumerations/Icon.swift rename to Sources/Core/Model/Enumerations/Icon.swift diff --git a/Sources/Adwaita/Model/Enumerations/Transition.swift b/Sources/Core/Model/Enumerations/Transition.swift similarity index 100% rename from Sources/Adwaita/Model/Enumerations/Transition.swift rename to Sources/Core/Model/Enumerations/Transition.swift diff --git a/Sources/Adwaita/Model/Extensions/Array.swift b/Sources/Core/Model/Extensions/Array.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/Array.swift rename to Sources/Core/Model/Extensions/Array.swift diff --git a/Sources/Adwaita/Model/Extensions/Bool.swift b/Sources/Core/Model/Extensions/Bool.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/Bool.swift rename to Sources/Core/Model/Extensions/Bool.swift diff --git a/Sources/Adwaita/Model/Extensions/Int.swift b/Sources/Core/Model/Extensions/Int.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/Int.swift rename to Sources/Core/Model/Extensions/Int.swift diff --git a/Sources/Adwaita/Model/Extensions/OpaquePointer.swift b/Sources/Core/Model/Extensions/OpaquePointer.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/OpaquePointer.swift rename to Sources/Core/Model/Extensions/OpaquePointer.swift diff --git a/Sources/Adwaita/Model/Extensions/Set.swift b/Sources/Core/Model/Extensions/Set.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/Set.swift rename to Sources/Core/Model/Extensions/Set.swift diff --git a/Sources/Adwaita/Model/Extensions/String.swift b/Sources/Core/Model/Extensions/String.swift similarity index 89% rename from Sources/Adwaita/Model/Extensions/String.swift rename to Sources/Core/Model/Extensions/String.swift index 2d135d8..7835e43 100644 --- a/Sources/Adwaita/Model/Extensions/String.swift +++ b/Sources/Core/Model/Extensions/String.swift @@ -8,9 +8,9 @@ extension String { /// A label for the transition data in a widget's fields. - static var transition: Self { "transition" } + public static var transition: Self { "transition" } /// A label for the navigation label in a widget's fields. - static var navigationLabel: Self { "navigation-label" } + public static var navigationLabel: Self { "navigation-label" } /// Add the Ctrl key to a shortcut. /// - Returns: The shortcut. diff --git a/Sources/Adwaita/Model/Extensions/UInt.swift b/Sources/Core/Model/Extensions/UInt.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/UInt.swift rename to Sources/Core/Model/Extensions/UInt.swift diff --git a/Sources/Adwaita/Model/Extensions/UnsafeMutablePointer.swift b/Sources/Core/Model/Extensions/UnsafeMutablePointer.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/UnsafeMutablePointer.swift rename to Sources/Core/Model/Extensions/UnsafeMutablePointer.swift diff --git a/Sources/Adwaita/Model/Extensions/UnsafeMutableRawPointer.swift b/Sources/Core/Model/Extensions/UnsafeMutableRawPointer.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/UnsafeMutableRawPointer.swift rename to Sources/Core/Model/Extensions/UnsafeMutableRawPointer.swift diff --git a/Sources/Adwaita/Model/Extensions/ViewStorage.swift b/Sources/Core/Model/Extensions/ViewStorage.swift similarity index 100% rename from Sources/Adwaita/Model/Extensions/ViewStorage.swift rename to Sources/Core/Model/Extensions/ViewStorage.swift diff --git a/Sources/Adwaita/Model/Idle.swift b/Sources/Core/Model/Idle.swift similarity index 100% rename from Sources/Adwaita/Model/Idle.swift rename to Sources/Core/Model/Idle.swift diff --git a/Sources/Adwaita/Model/Signals/SignalData.swift b/Sources/Core/Model/Signals/SignalData.swift similarity index 100% rename from Sources/Adwaita/Model/Signals/SignalData.swift rename to Sources/Core/Model/Signals/SignalData.swift diff --git a/Sources/Adwaita/Model/Storage.swift b/Sources/Core/Model/Storage.swift similarity index 100% rename from Sources/Adwaita/Model/Storage.swift rename to Sources/Core/Model/Storage.swift diff --git a/Sources/Adwaita/Model/WindowView.swift b/Sources/Core/Model/WindowView.swift similarity index 100% rename from Sources/Adwaita/Model/WindowView.swift rename to Sources/Core/Model/WindowView.swift diff --git a/Sources/Adwaita/View/Banner+.swift b/Sources/Core/View/Banner+.swift similarity index 100% rename from Sources/Adwaita/View/Banner+.swift rename to Sources/Core/View/Banner+.swift diff --git a/Sources/Adwaita/View/Button+.swift b/Sources/Core/View/Button+.swift similarity index 100% rename from Sources/Adwaita/View/Button+.swift rename to Sources/Core/View/Button+.swift diff --git a/Sources/Adwaita/View/Carousel+.swift b/Sources/Core/View/Carousel+.swift similarity index 100% rename from Sources/Adwaita/View/Carousel+.swift rename to Sources/Core/View/Carousel+.swift diff --git a/Sources/Adwaita/View/Dialogs/AboutDialog.swift b/Sources/Core/View/Dialogs/AboutDialog.swift similarity index 81% rename from Sources/Adwaita/View/Dialogs/AboutDialog.swift rename to Sources/Core/View/Dialogs/AboutDialog.swift index aab8d1a..92be150 100644 --- a/Sources/Adwaita/View/Dialogs/AboutDialog.swift +++ b/Sources/Core/View/Dialogs/AboutDialog.swift @@ -9,7 +9,7 @@ import CAdw import Foundation /// The about dialog widget. -struct AboutDialog: AdwaitaWidget { +public struct AboutDialog: AdwaitaWidget { /// Whether the dialog is visible. @Binding var visible: Bool @@ -32,12 +32,42 @@ struct AboutDialog: AdwaitaWidget { /// The ID for the dialog's storage. let dialogID = "dialog" + /// Initialize the about dialog wrapper. + /// - Parameters: + /// - visible: The visibility. + /// - child: The child view. + /// - appName: The app's name. + /// - developer: The developer's name. + /// - version: The version. + /// - icon: The icon. + /// - website: The website's URL. + /// - issues: The link for opening issues. + public init( + visible: Binding, + child: AnyView, + appName: String? = nil, + developer: String? = nil, + version: String? = nil, + icon: Icon? = nil, + website: URL? = nil, + issues: URL? = nil + ) { + self._visible = visible + self.child = child + self.appName = appName + self.developer = developer + self.version = version + self.icon = icon + self.website = website + self.issues = issues + } + /// The view storage. /// - Parameters: /// - modifiers: Modify views before being updated. /// - type: The view render data type. /// - Returns: The view storage. - func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { + public func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { let storage = child.storage(data: data, type: type) update(storage, data: data, updateProperties: true, type: type) return storage @@ -49,7 +79,7 @@ struct AboutDialog: AdwaitaWidget { /// - modifiers: Modify views before being updated /// - updateProperties: Whether to update the view's properties. /// - type: The view render data type. - func update( + public func update( _ storage: ViewStorage, data: WidgetData, updateProperties: Bool, @@ -110,37 +140,3 @@ struct AboutDialog: AdwaitaWidget { } } - -extension AnyView { - - /// Add an about dialog to the parent window. - /// - Parameters: - /// - visible: Whether the dialog is presented. - /// - app: The app's name. - /// - developer: The developer's name. - /// - version: The version string. - /// - icon: The app icon. - /// - website: The app's website. - /// - issues: Website for reporting issues. - public func aboutDialog( - visible: Binding, - app: String? = nil, - developer: String? = nil, - version: String? = nil, - icon: Icon? = nil, - website: URL? = nil, - issues: URL? = nil - ) -> AnyView { - AboutDialog( - visible: visible, - child: self, - appName: app, - developer: developer, - version: version, - icon: icon, - website: website, - issues: issues - ) - } - -} diff --git a/Sources/Adwaita/View/Dialogs/AlertDialog.swift b/Sources/Core/View/Dialogs/AlertDialog.swift similarity index 95% rename from Sources/Adwaita/View/Dialogs/AlertDialog.swift rename to Sources/Core/View/Dialogs/AlertDialog.swift index a79a380..438fb67 100644 --- a/Sources/Adwaita/View/Dialogs/AlertDialog.swift +++ b/Sources/Core/View/Dialogs/AlertDialog.swift @@ -33,6 +33,27 @@ public struct AlertDialog: AdwaitaWidget { /// The child view. var child: AnyView + /// Initialize an alert dialog wrapper. + /// - Parameters: + /// - visible: Whether the dialog is visible. + /// - child: The child view. + /// - id: A unique identifier for dialogs on the view. + /// - heading: The heading. + /// - body: The body text. + public init( + visible: Binding, + child: AnyView, + id: String, + heading: String, + body: String + ) { + self._visible = visible + self.child = child + self.id = id + self.heading = heading + self.body = body + } + /// Information about a response. struct Response: Identifiable { @@ -214,30 +235,6 @@ public struct AlertDialog: AdwaitaWidget { } -extension AnyView { - - /// Add an alert dialog to the parent window. - /// - Parameters: - /// - visible: Whether the dialog is presented. - /// - heading: The heading. - /// - body: The body text. - public func alertDialog( - visible: Binding, - heading: String, - body: String = "", - id: String? = nil - ) -> AlertDialog { - .init( - visible: visible, - id: id ?? "no-id", - heading: heading, - body: body, - child: self - ) - } - -} - /// Run when an alert dialog closes. /// - Parameters: /// - ptr: The pointer. diff --git a/Sources/Adwaita/View/Dialogs/Dialog.swift b/Sources/Core/View/Dialogs/Dialog.swift similarity index 82% rename from Sources/Adwaita/View/Dialogs/Dialog.swift rename to Sources/Core/View/Dialogs/Dialog.swift index fdfe234..50f0d9f 100644 --- a/Sources/Adwaita/View/Dialogs/Dialog.swift +++ b/Sources/Core/View/Dialogs/Dialog.swift @@ -8,7 +8,7 @@ import CAdw /// The dialog widget. -struct Dialog: AdwaitaWidget { +public struct Dialog: AdwaitaWidget { /// Whether the dialog is visible. @Binding var visible: Bool @@ -30,12 +30,39 @@ struct Dialog: AdwaitaWidget { /// The ID for the content's storage. let contentID = "content" + /// Initialize a dialog wrapper. + /// - Parameters: + /// - visible: Whether the dialog is visible. + /// - child: The wrapped view. + /// - id: An unique identifier for dialogs on the view. + /// - content: The content. + /// - title: The title. + /// - width: The width. + /// - height: The height. + public init( + visible: Binding, + child: AnyView, + id: String, + content: Body, + title: String? = nil, + width: Int? = nil, + height: Int? = nil + ) { + self._visible = visible + self.child = child + self.id = id + self.content = content + self.title = title + self.width = width + self.height = height + } + /// The view storage. /// - Parameters: /// - modifiers: Modify views before being updated. /// - type: The view render data type. /// - Returns: The view storage. - func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { + public func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { let child = child.storage(data: data, type: type) let storage = ViewStorage(child.opaquePointer, content: [.mainContent: [child]]) update(storage, data: data, updateProperties: true, type: type) @@ -48,7 +75,7 @@ struct Dialog: AdwaitaWidget { /// - modifiers: Modify views before being updated /// - updateProperties: Whether to update the view's properties. /// - type: The view render data type. - func update( + public func update( _ storage: ViewStorage, data: WidgetData, updateProperties: Bool, @@ -115,33 +142,3 @@ struct Dialog: AdwaitaWidget { } } - -extension AnyView { - - /// Add a dialog to the parent window. - /// - 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, - title: String? = nil, - id: String? = nil, - width: Int? = nil, - height: Int? = nil, - @ViewBuilder content: () -> Body - ) -> AnyView { - Dialog( - visible: visible, - id: id ?? "", - title: title, - child: self, - content: content(), - width: width, - height: height - ) - } - -} diff --git a/Sources/Adwaita/View/Dialogs/FileDialog.swift b/Sources/Core/View/Dialogs/FileDialog.swift similarity index 74% rename from Sources/Adwaita/View/Dialogs/FileDialog.swift rename to Sources/Core/View/Dialogs/FileDialog.swift index 805ae90..b037b96 100644 --- a/Sources/Adwaita/View/Dialogs/FileDialog.swift +++ b/Sources/Core/View/Dialogs/FileDialog.swift @@ -9,10 +9,10 @@ import CAdw import Foundation /// A structure representing a file dialog window. -struct FileDialog: AdwaitaWidget { +public struct FileDialog: AdwaitaWidget { /// Whether the dialog is an importer. - var importer = true + var importer: Bool /// Whether the dialog should open. var open: Signal /// The dialog's child. @@ -28,12 +28,44 @@ struct FileDialog: AdwaitaWidget { /// The closure to run when the import or export is not successful. var cancel: () -> Void + // swiftlint:disable function_default_parameter_at_end + /// Initialize the file dialog wrapper. + /// - Parameters: + /// - importer: Whether it is an importer. + /// - open: The signal. + /// - child: The wrapped view. + /// - initialFolder: The initial URL. + /// - initialName: The initial name. + /// - extensions: The file extensions. + /// - result: Run when the import or export succeeds. + /// - cancel: Run when the import or export is not successful. + public init( + importer: Bool = true, + `open`: Signal, + child: AnyView, + result: @escaping (URL) -> Void, + cancel: @escaping () -> Void, + initialFolder: URL? = nil, + initialName: String? = nil, + extensions: [String]? = nil + ) { + self.importer = importer + self.open = open + self.child = child + self.result = result + self.cancel = cancel + self.initialFolder = initialFolder + self.initialName = initialName + self.extensions = extensions + } + // swiftlint:enable function_default_parameter_at_end + /// The view storage. /// - Parameters: /// - modifiers: Modify views before being updated. /// - type: The view render data type. /// - Returns: The view storage. - func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { + public func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { let child = child.storage(data: data, type: type) let storage = ViewStorage(child.opaquePointer, content: [.mainContent: [child]]) update(storage, data: data, updateProperties: true, type: type) @@ -46,7 +78,7 @@ struct FileDialog: AdwaitaWidget { /// - modifiers: Modify views before being updated /// - updateProperties: Whether to update the view's properties. /// - type: The view render data type. - func update( + public func update( _ storage: ViewStorage, data: WidgetData, updateProperties: Bool, @@ -92,62 +124,6 @@ struct FileDialog: AdwaitaWidget { } -extension AnyView { - - /// Create an importer file dialog. - /// - Parameters: - /// - open: The signal to open the dialog. - /// - initialFolder: The URL to the folder open when being opened. - /// - extensions: The accepted file extensions. - /// - folders: Whether folders are accepted. - /// - onOpen: Run this when a file for importing has been chosen. - /// - onClose: Run this when the user cancelled the action. - public func fileImporter( - open: Signal, - initialFolder: URL? = nil, - extensions: [String]? = nil, - onOpen: @escaping (URL) -> Void, - onClose: @escaping () -> Void - ) -> AnyView { - FileDialog( - importer: true, - open: open, - child: self, - initialFolder: initialFolder, - initialName: nil, - extensions: extensions, - result: onOpen, - cancel: onClose - ) - } - - /// Create an exporter file dialog. - /// - Parameters: - /// - exporter: The signal to open the dialog. - /// - initialFolder: The URL to the folder open when being opened. - /// - initialName: The default file name. - /// - onSave: Run this when a path for exporting has been chosen. - /// - onClose: Run this when the user cancelled the action. - public func fileExporter( - open: Signal, - initialFolder: URL? = nil, - initialName: String? = nil, - onSave: @escaping (URL) -> Void, - onClose: @escaping () -> Void - ) -> AnyView { - FileDialog( - importer: false, - open: open, - child: self, - initialFolder: initialFolder, - initialName: initialName, - result: onSave, - cancel: onClose - ) - } - -} - /// An Adwaita file dialog window callback. class AdwaitaFileDialog { diff --git a/Sources/Adwaita/View/EitherView.swift b/Sources/Core/View/EitherView.swift similarity index 100% rename from Sources/Adwaita/View/EitherView.swift rename to Sources/Core/View/EitherView.swift diff --git a/Sources/Adwaita/View/Fixed+.swift b/Sources/Core/View/Fixed+.swift similarity index 100% rename from Sources/Adwaita/View/Fixed+.swift rename to Sources/Core/View/Fixed+.swift diff --git a/Sources/Adwaita/View/FlowBox+.swift b/Sources/Core/View/FlowBox+.swift similarity index 100% rename from Sources/Adwaita/View/FlowBox+.swift rename to Sources/Core/View/FlowBox+.swift diff --git a/Sources/Adwaita/View/ForEach.swift b/Sources/Core/View/ForEach.swift similarity index 100% rename from Sources/Adwaita/View/ForEach.swift rename to Sources/Core/View/ForEach.swift diff --git a/Sources/Adwaita/View/Forms/ActionRow+.swift b/Sources/Core/View/Forms/ActionRow+.swift similarity index 55% rename from Sources/Adwaita/View/Forms/ActionRow+.swift rename to Sources/Core/View/Forms/ActionRow+.swift index 8e2c044..0a4257d 100644 --- a/Sources/Adwaita/View/Forms/ActionRow+.swift +++ b/Sources/Core/View/Forms/ActionRow+.swift @@ -14,11 +14,4 @@ extension ActionRow { self = self.title(title) } - /// Deemphasize the row title and emphasize the subtitle. - /// - Parameter active: Whether the style is currently applied. - /// - Returns: A view. - public func property(_ active: Bool = true) -> AnyView { - style("property", active: active) - } - } diff --git a/Sources/Adwaita/View/Forms/ComboRow+.swift b/Sources/Core/View/Forms/ComboRow+.swift similarity index 100% rename from Sources/Adwaita/View/Forms/ComboRow+.swift rename to Sources/Core/View/Forms/ComboRow+.swift diff --git a/Sources/Adwaita/View/Forms/EntryRow+.swift b/Sources/Core/View/Forms/EntryRow+.swift similarity index 100% rename from Sources/Adwaita/View/Forms/EntryRow+.swift rename to Sources/Core/View/Forms/EntryRow+.swift diff --git a/Sources/Adwaita/View/Forms/Form.swift b/Sources/Core/View/Forms/Form.swift similarity index 72% rename from Sources/Adwaita/View/Forms/Form.swift rename to Sources/Core/View/Forms/Form.swift index eccc5e3..4eb8f12 100644 --- a/Sources/Adwaita/View/Forms/Form.swift +++ b/Sources/Core/View/Forms/Form.swift @@ -15,8 +15,11 @@ public struct Form: SimpleView { /// The view's body. public var view: Body { - List([Int](content.indices), selection: nil) { index in content[index] } - .style("boxed-list") + ModifierWrapper( + content: List([Int](content.indices), selection: nil) { index in content[index] }, + style: "boxed-list", + styleActive: true + ) } /// Initialize a `Form`. diff --git a/Sources/Adwaita/View/Forms/FormSection+.swift b/Sources/Core/View/Forms/FormSection+.swift similarity index 100% rename from Sources/Adwaita/View/Forms/FormSection+.swift rename to Sources/Core/View/Forms/FormSection+.swift diff --git a/Sources/Adwaita/View/Forms/PasswordEntryRow+.swift b/Sources/Core/View/Forms/PasswordEntryRow+.swift similarity index 100% rename from Sources/Adwaita/View/Forms/PasswordEntryRow+.swift rename to Sources/Core/View/Forms/PasswordEntryRow+.swift diff --git a/Sources/Adwaita/View/Forms/SpinRow+.swift b/Sources/Core/View/Forms/SpinRow+.swift similarity index 100% rename from Sources/Adwaita/View/Forms/SpinRow+.swift rename to Sources/Core/View/Forms/SpinRow+.swift diff --git a/Sources/Adwaita/View/Forms/SwitchRow+.swift b/Sources/Core/View/Forms/SwitchRow+.swift similarity index 100% rename from Sources/Adwaita/View/Forms/SwitchRow+.swift rename to Sources/Core/View/Forms/SwitchRow+.swift diff --git a/Sources/Adwaita/View/Generated/ActionRow.swift b/Sources/Core/View/Generated/ActionRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ActionRow.swift rename to Sources/Core/View/Generated/ActionRow.swift diff --git a/Sources/Adwaita/View/Generated/AspectFrame.swift b/Sources/Core/View/Generated/AspectFrame.swift similarity index 100% rename from Sources/Adwaita/View/Generated/AspectFrame.swift rename to Sources/Core/View/Generated/AspectFrame.swift diff --git a/Sources/Adwaita/View/Generated/Avatar.swift b/Sources/Core/View/Generated/Avatar.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Avatar.swift rename to Sources/Core/View/Generated/Avatar.swift diff --git a/Sources/Adwaita/View/Generated/Banner.swift b/Sources/Core/View/Generated/Banner.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Banner.swift rename to Sources/Core/View/Generated/Banner.swift diff --git a/Sources/Adwaita/View/Generated/Bin.swift b/Sources/Core/View/Generated/Bin.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Bin.swift rename to Sources/Core/View/Generated/Bin.swift diff --git a/Sources/Adwaita/View/Generated/Box.swift b/Sources/Core/View/Generated/Box.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Box.swift rename to Sources/Core/View/Generated/Box.swift diff --git a/Sources/Adwaita/View/Generated/Button.swift b/Sources/Core/View/Generated/Button.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Button.swift rename to Sources/Core/View/Generated/Button.swift diff --git a/Sources/Adwaita/View/Generated/ButtonContent.swift b/Sources/Core/View/Generated/ButtonContent.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ButtonContent.swift rename to Sources/Core/View/Generated/ButtonContent.swift diff --git a/Sources/Adwaita/View/Generated/Carousel.swift b/Sources/Core/View/Generated/Carousel.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Carousel.swift rename to Sources/Core/View/Generated/Carousel.swift diff --git a/Sources/Adwaita/View/Generated/CenterBox.swift b/Sources/Core/View/Generated/CenterBox.swift similarity index 100% rename from Sources/Adwaita/View/Generated/CenterBox.swift rename to Sources/Core/View/Generated/CenterBox.swift diff --git a/Sources/Adwaita/View/Generated/CheckButton.swift b/Sources/Core/View/Generated/CheckButton.swift similarity index 100% rename from Sources/Adwaita/View/Generated/CheckButton.swift rename to Sources/Core/View/Generated/CheckButton.swift diff --git a/Sources/Adwaita/View/Generated/Clamp.swift b/Sources/Core/View/Generated/Clamp.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Clamp.swift rename to Sources/Core/View/Generated/Clamp.swift diff --git a/Sources/Adwaita/View/Generated/ComboRow.swift b/Sources/Core/View/Generated/ComboRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ComboRow.swift rename to Sources/Core/View/Generated/ComboRow.swift diff --git a/Sources/Adwaita/View/Generated/EntryRow.swift b/Sources/Core/View/Generated/EntryRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/EntryRow.swift rename to Sources/Core/View/Generated/EntryRow.swift diff --git a/Sources/Adwaita/View/Generated/ExpanderRow.swift b/Sources/Core/View/Generated/ExpanderRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ExpanderRow.swift rename to Sources/Core/View/Generated/ExpanderRow.swift diff --git a/Sources/Adwaita/View/Generated/Fixed.swift b/Sources/Core/View/Generated/Fixed.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Fixed.swift rename to Sources/Core/View/Generated/Fixed.swift diff --git a/Sources/Adwaita/View/Generated/FlowBox.swift b/Sources/Core/View/Generated/FlowBox.swift similarity index 100% rename from Sources/Adwaita/View/Generated/FlowBox.swift rename to Sources/Core/View/Generated/FlowBox.swift diff --git a/Sources/Adwaita/View/Generated/HeaderBar.swift b/Sources/Core/View/Generated/HeaderBar.swift similarity index 100% rename from Sources/Adwaita/View/Generated/HeaderBar.swift rename to Sources/Core/View/Generated/HeaderBar.swift diff --git a/Sources/Adwaita/View/Generated/Label.swift b/Sources/Core/View/Generated/Label.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Label.swift rename to Sources/Core/View/Generated/Label.swift diff --git a/Sources/Adwaita/View/Generated/LevelBar.swift b/Sources/Core/View/Generated/LevelBar.swift similarity index 100% rename from Sources/Adwaita/View/Generated/LevelBar.swift rename to Sources/Core/View/Generated/LevelBar.swift diff --git a/Sources/Adwaita/View/Generated/LinkButton.swift b/Sources/Core/View/Generated/LinkButton.swift similarity index 100% rename from Sources/Adwaita/View/Generated/LinkButton.swift rename to Sources/Core/View/Generated/LinkButton.swift diff --git a/Sources/Adwaita/View/Generated/ListBox.swift b/Sources/Core/View/Generated/ListBox.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ListBox.swift rename to Sources/Core/View/Generated/ListBox.swift diff --git a/Sources/Adwaita/View/Generated/Menu.swift b/Sources/Core/View/Generated/Menu.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Menu.swift rename to Sources/Core/View/Generated/Menu.swift diff --git a/Sources/Adwaita/View/Generated/NavigationView.swift b/Sources/Core/View/Generated/NavigationView.swift similarity index 100% rename from Sources/Adwaita/View/Generated/NavigationView.swift rename to Sources/Core/View/Generated/NavigationView.swift diff --git a/Sources/Adwaita/View/Generated/Overlay.swift b/Sources/Core/View/Generated/Overlay.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Overlay.swift rename to Sources/Core/View/Generated/Overlay.swift diff --git a/Sources/Adwaita/View/Generated/OverlaySplitView.swift b/Sources/Core/View/Generated/OverlaySplitView.swift similarity index 100% rename from Sources/Adwaita/View/Generated/OverlaySplitView.swift rename to Sources/Core/View/Generated/OverlaySplitView.swift diff --git a/Sources/Adwaita/View/Generated/PasswordEntryRow.swift b/Sources/Core/View/Generated/PasswordEntryRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/PasswordEntryRow.swift rename to Sources/Core/View/Generated/PasswordEntryRow.swift diff --git a/Sources/Adwaita/View/Generated/Picture.swift b/Sources/Core/View/Generated/Picture.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Picture.swift rename to Sources/Core/View/Generated/Picture.swift diff --git a/Sources/Adwaita/View/Generated/Popover.swift b/Sources/Core/View/Generated/Popover.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Popover.swift rename to Sources/Core/View/Generated/Popover.swift diff --git a/Sources/Adwaita/View/Generated/PreferencesGroup.swift b/Sources/Core/View/Generated/PreferencesGroup.swift similarity index 100% rename from Sources/Adwaita/View/Generated/PreferencesGroup.swift rename to Sources/Core/View/Generated/PreferencesGroup.swift diff --git a/Sources/Adwaita/View/Generated/PreferencesPage.swift b/Sources/Core/View/Generated/PreferencesPage.swift similarity index 100% rename from Sources/Adwaita/View/Generated/PreferencesPage.swift rename to Sources/Core/View/Generated/PreferencesPage.swift diff --git a/Sources/Adwaita/View/Generated/PreferencesRow.swift b/Sources/Core/View/Generated/PreferencesRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/PreferencesRow.swift rename to Sources/Core/View/Generated/PreferencesRow.swift diff --git a/Sources/Adwaita/View/Generated/ProgressBar.swift b/Sources/Core/View/Generated/ProgressBar.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ProgressBar.swift rename to Sources/Core/View/Generated/ProgressBar.swift diff --git a/Sources/Adwaita/View/Generated/ScrolledWindow.swift b/Sources/Core/View/Generated/ScrolledWindow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ScrolledWindow.swift rename to Sources/Core/View/Generated/ScrolledWindow.swift diff --git a/Sources/Adwaita/View/Generated/SearchBar.swift b/Sources/Core/View/Generated/SearchBar.swift similarity index 100% rename from Sources/Adwaita/View/Generated/SearchBar.swift rename to Sources/Core/View/Generated/SearchBar.swift diff --git a/Sources/Adwaita/View/Generated/SearchEntry.swift b/Sources/Core/View/Generated/SearchEntry.swift similarity index 100% rename from Sources/Adwaita/View/Generated/SearchEntry.swift rename to Sources/Core/View/Generated/SearchEntry.swift diff --git a/Sources/Adwaita/View/Generated/Separator.swift b/Sources/Core/View/Generated/Separator.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Separator.swift rename to Sources/Core/View/Generated/Separator.swift diff --git a/Sources/Adwaita/View/Generated/SpinRow.swift b/Sources/Core/View/Generated/SpinRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/SpinRow.swift rename to Sources/Core/View/Generated/SpinRow.swift diff --git a/Sources/Adwaita/View/Generated/Spinner.swift b/Sources/Core/View/Generated/Spinner.swift similarity index 100% rename from Sources/Adwaita/View/Generated/Spinner.swift rename to Sources/Core/View/Generated/Spinner.swift diff --git a/Sources/Adwaita/View/Generated/SplitButton.swift b/Sources/Core/View/Generated/SplitButton.swift similarity index 100% rename from Sources/Adwaita/View/Generated/SplitButton.swift rename to Sources/Core/View/Generated/SplitButton.swift diff --git a/Sources/Adwaita/View/Generated/StatusPage.swift b/Sources/Core/View/Generated/StatusPage.swift similarity index 100% rename from Sources/Adwaita/View/Generated/StatusPage.swift rename to Sources/Core/View/Generated/StatusPage.swift diff --git a/Sources/Adwaita/View/Generated/SwitchRow.swift b/Sources/Core/View/Generated/SwitchRow.swift similarity index 100% rename from Sources/Adwaita/View/Generated/SwitchRow.swift rename to Sources/Core/View/Generated/SwitchRow.swift diff --git a/Sources/Adwaita/View/Generated/ToastOverlay.swift b/Sources/Core/View/Generated/ToastOverlay.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ToastOverlay.swift rename to Sources/Core/View/Generated/ToastOverlay.swift diff --git a/Sources/Adwaita/View/Generated/ToggleButton.swift b/Sources/Core/View/Generated/ToggleButton.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ToggleButton.swift rename to Sources/Core/View/Generated/ToggleButton.swift diff --git a/Sources/Adwaita/View/Generated/ToolbarView.swift b/Sources/Core/View/Generated/ToolbarView.swift similarity index 100% rename from Sources/Adwaita/View/Generated/ToolbarView.swift rename to Sources/Core/View/Generated/ToolbarView.swift diff --git a/Sources/Adwaita/View/Generated/WindowTitle.swift b/Sources/Core/View/Generated/WindowTitle.swift similarity index 100% rename from Sources/Adwaita/View/Generated/WindowTitle.swift rename to Sources/Core/View/Generated/WindowTitle.swift diff --git a/Sources/Adwaita/View/HStack.swift b/Sources/Core/View/HStack.swift similarity index 85% rename from Sources/Adwaita/View/HStack.swift rename to Sources/Core/View/HStack.swift index 9bb0527..aadf90c 100644 --- a/Sources/Adwaita/View/HStack.swift +++ b/Sources/Core/View/HStack.swift @@ -15,8 +15,7 @@ public struct HStack: SimpleView { /// The view's body. public var view: Body { - VStack(horizontal: true, content: content) - .linked(linked) + ModifierWrapper(content: VStack(horizontal: true, content: content), style: "linked", styleActive: linked) } /// Initialize a `HStack`. diff --git a/Sources/Adwaita/View/HeaderBar+.swift b/Sources/Core/View/HeaderBar+.swift similarity index 100% rename from Sources/Adwaita/View/HeaderBar+.swift rename to Sources/Core/View/HeaderBar+.swift diff --git a/Sources/Adwaita/View/List.swift b/Sources/Core/View/List.swift similarity index 81% rename from Sources/Adwaita/View/List.swift rename to Sources/Core/View/List.swift index 22744ef..5276f72 100644 --- a/Sources/Adwaita/View/List.swift +++ b/Sources/Core/View/List.swift @@ -59,18 +59,4 @@ extension List { } } - /// Add the "navigation-sidebar" style class. - /// - Parameter active: Whether the style is applied. - /// - Returns: A view. - public func sidebarStyle(_ active: Bool = true) -> AnyView { - style("navigation-sidebar", active: active) - } - - /// Apply the boxed list style class. - /// - Parameter active: Whether the style is applied. - /// - Returns: A view. - public func boxedList(_ active: Bool = true) -> AnyView { - style("boxed-list", active: active) - } - } diff --git a/Sources/Adwaita/View/Menu+.swift b/Sources/Core/View/Menu+.swift similarity index 100% rename from Sources/Adwaita/View/Menu+.swift rename to Sources/Core/View/Menu+.swift diff --git a/Sources/Core/View/Modifiers/Clamp+.swift b/Sources/Core/View/Modifiers/Clamp+.swift new file mode 100644 index 0000000..1effc42 --- /dev/null +++ b/Sources/Core/View/Modifiers/Clamp+.swift @@ -0,0 +1,23 @@ +// +// Clamp+.swift +// Adwaita +// +// Created by david-swift on 20.01.24. +// + +import CAdw + +extension Clamp { + + /// Initialize either a horizontal or vertical clamp. + /// - Parameter vertical: Whether it is a vertical clamp. + public init(vertical: Bool) { + self.init() + if vertical { + appearFunctions.append { storage, _ in + gtk_orientable_set_orientation(storage.opaquePointer, GTK_ORIENTATION_VERTICAL) + } + } + } + +} diff --git a/Sources/Adwaita/View/Modifiers/ModifierWrapper.swift b/Sources/Core/View/Modifiers/ModifierWrapper.swift similarity index 65% rename from Sources/Adwaita/View/Modifiers/ModifierWrapper.swift rename to Sources/Core/View/Modifiers/ModifierWrapper.swift index 15d94f6..5a1ee31 100644 --- a/Sources/Adwaita/View/Modifiers/ModifierWrapper.swift +++ b/Sources/Core/View/Modifiers/ModifierWrapper.swift @@ -8,7 +8,7 @@ import CAdw /// A wrapper for view modifiers for any view. -struct ModifierWrapper: AdwaitaWidget { +public struct ModifierWrapper: AdwaitaWidget { /// The view. var content: AnyView @@ -39,12 +39,60 @@ struct ModifierWrapper: AdwaitaWidget { /// The tooltip. var tooltip: String? + /// Initialize a modifier wrapper. + /// - Parameters: + /// - content: The view. + /// - padding: The padding. + /// - edges: The padding edges. + /// - hexpand: Whether to expand horizontally. + /// - vexpand: Whether to expand vertically. + /// - halign: The horizontal alignment. + /// - valign: The vertical alignment. + /// - minWidth: The minimum width. + /// - minHeight: The minimum height. + /// - style: The style class. + /// - styleActive: Whether the style is active. + /// - insensitive: Whether the view is insensitive. + /// - visible: Whether the view is visible. + /// - tooltip: The tooltip. + public init( + content: AnyView, + padding: Int? = nil, + edges: Set? = nil, + hexpand: Bool? = nil, + vexpand: Bool? = nil, + halign: Alignment? = nil, + valign: Alignment? = nil, + minWidth: Int? = nil, + minHeight: Int? = nil, + style: String? = nil, + styleActive: Bool? = nil, + insensitive: Bool? = nil, + visible: Bool? = nil, + tooltip: String? = nil + ) { + self.content = content + self.padding = padding + self.edges = edges + self.hexpand = hexpand + self.vexpand = vexpand + self.halign = halign + self.valign = valign + self.minWidth = minWidth + self.minHeight = minHeight + self.style = style + self.styleActive = styleActive + self.insensitive = insensitive + self.visible = visible + self.tooltip = tooltip + } + /// The view storage. /// - Parameters: /// - modifiers: Modify views before being updated. /// - type: The view render data type. /// - Returns: The view storage. - func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { + public func container(data: WidgetData, type: Data.Type) -> ViewStorage where Data: ViewRenderData { let content = content.storage(data: data, type: type) let storage = ViewStorage(content.pointer, content: [.mainContent: [content]]) update(storage, data: data, updateProperties: true, type: type) @@ -57,7 +105,7 @@ struct ModifierWrapper: AdwaitaWidget { /// - modifiers: Modify views before being updated /// - updateProperties: Whether to update the view's properties. /// - type: The view render data type. - func update( + public func update( _ storage: ViewStorage, data: WidgetData, updateProperties: Bool, @@ -142,83 +190,3 @@ struct ModifierWrapper: AdwaitaWidget { } } - -extension AnyView { - - /// Add padding around a view. - /// - Parameters: - /// - padding: The size of the padding. - /// - edges: The edges which are affected by the padding. - /// - Returns: A view. - public func padding(_ padding: Int = 10, _ edges: Set = .all) -> AnyView { - ModifierWrapper(content: self, padding: padding, edges: edges) - } - - /// Enable or disable the horizontal expansion. - /// - Parameter enabled: Whether it is enabled or disabled. - /// - Returns: A view. - public func hexpand(_ enabled: Bool = true) -> AnyView { - ModifierWrapper(content: self, hexpand: enabled) - } - - /// Enable or disable the vertical expansion. - /// - Parameter enabled: Whether it is enabled or disabled. - /// - Returns: A view. - public func vexpand(_ enabled: Bool = true) -> AnyView { - ModifierWrapper(content: self, vexpand: enabled) - } - - /// Set the horizontal alignment. - /// - Parameter align: The alignment. - /// - Returns: A view. - public func halign(_ align: Alignment) -> AnyView { - ModifierWrapper(content: self, halign: align) - } - - /// Set the vertical alignment. - /// - Parameter align: The alignment. - /// - Returns: A view. - public func valign(_ align: Alignment) -> AnyView { - ModifierWrapper(content: self, valign: align) - } - - /// Set the view's minimal width or height. - /// - Parameters: - /// - minWidth: The minimal width. - /// - minHeight: The minimal height. - /// - Returns: A view. - public func frame(minWidth: Int? = nil, minHeight: Int? = nil) -> AnyView { - ModifierWrapper(content: self, minWidth: minWidth, minHeight: minHeight) - } - - /// Add a style class to the view. - /// - Parameters: - /// - style: The style class. - /// - active: Whether the style is currently applied. - /// - Returns: A view. - public func style(_ style: String, active: Bool = true) -> AnyView { - ModifierWrapper(content: self, style: style, styleActive: active) - } - - /// Make the view insensitive (useful e.g. in overlays). - /// - Parameter insensitive: Whether the view is insensitive. - /// - Returns: A view. - public func insensitive(_ insensitive: Bool = true) -> AnyView { - ModifierWrapper(content: self, insensitive: insensitive) - } - - /// Set the view's visibility. - /// - Parameter visible: Whether the view is visible. - /// - Returns: A view. - public func visible(_ visible: Bool = true) -> AnyView { - ModifierWrapper(content: self, visible: visible) - } - - /// Add a tooltip to the widget. - /// - Parameter tooltip: The tooltip text. - /// - Returns: A view. - public func tooltip(_ tooltip: String) -> AnyView { - ModifierWrapper(content: self, tooltip: tooltip) - } - -} diff --git a/Sources/Adwaita/View/Modifiers/Popover+.swift b/Sources/Core/View/Modifiers/Popover+.swift similarity index 60% rename from Sources/Adwaita/View/Modifiers/Popover+.swift rename to Sources/Core/View/Modifiers/Popover+.swift index 69ee19a..3a8d16e 100644 --- a/Sources/Adwaita/View/Modifiers/Popover+.swift +++ b/Sources/Core/View/Modifiers/Popover+.swift @@ -11,7 +11,7 @@ extension Popover { /// Initialize either a horizontal or vertical clamp. /// - Parameter vertical: Whether it is a vertical clamp. - init(visible: Binding) { + public init(visible: Binding) { self.init() updateFunctions.append { storage, _, _ in storage.connectSignal(name: "closed", id: "visible") { @@ -28,19 +28,3 @@ extension Popover { } } - -extension AnyView { - - /// Add a popover on top of the view. - /// - Parameters: - /// - visible: Whether the popover is displayed. - /// - content: The popover's content. - /// - Returns: The view. - public func popover(visible: Binding, @ViewBuilder content: @escaping () -> Body) -> Overlay { - overlay { - Popover(visible: visible) - .child(content) - } - } - -} diff --git a/Sources/Adwaita/View/Modifiers/ToastOverlay+.swift b/Sources/Core/View/Modifiers/ToastOverlay+.swift similarity index 61% rename from Sources/Adwaita/View/Modifiers/ToastOverlay+.swift rename to Sources/Core/View/Modifiers/ToastOverlay+.swift index 5be24c1..8887643 100644 --- a/Sources/Adwaita/View/Modifiers/ToastOverlay+.swift +++ b/Sources/Core/View/Modifiers/ToastOverlay+.swift @@ -46,30 +46,3 @@ extension ToastOverlay { } } - -extension AnyView { - - /// Present a toast when the signal gets activated. - /// - Parameters: - /// - title: The title of the toast. - /// - signal: The signal which activates the presentation of a toast. - /// - Returns: A view. - public func toast(_ title: String, signal: Signal) -> ToastOverlay { - .init(title, signal: signal) - .child { self } - } - - /// Present a toast with a button when the signal gets activated. - /// - Parameters: - /// - title: The title of the toast. - /// - signal: The signal which activates the presentation of a toast. - /// - button: The button's label. - /// - handler: The handler for the button. - /// - Returns: A view. - public func toast(_ title: String, signal: Signal, button: String, handler: @escaping () -> Void) -> ToastOverlay { - .init(title, signal: signal) - .child { self } - .action(button: button, handler: handler) - } - -} diff --git a/Sources/Adwaita/View/NavigationSplitView.swift b/Sources/Core/View/NavigationSplitView.swift similarity index 100% rename from Sources/Adwaita/View/NavigationSplitView.swift rename to Sources/Core/View/NavigationSplitView.swift diff --git a/Sources/Adwaita/View/NavigationView+.swift b/Sources/Core/View/NavigationView+.swift similarity index 100% rename from Sources/Adwaita/View/NavigationView+.swift rename to Sources/Core/View/NavigationView+.swift diff --git a/Sources/Adwaita/View/OverlaySplitView+.swift b/Sources/Core/View/OverlaySplitView+.swift similarity index 100% rename from Sources/Adwaita/View/OverlaySplitView+.swift rename to Sources/Core/View/OverlaySplitView+.swift diff --git a/Sources/Adwaita/View/Picture+.swift b/Sources/Core/View/Picture+.swift similarity index 100% rename from Sources/Adwaita/View/Picture+.swift rename to Sources/Core/View/Picture+.swift diff --git a/Sources/Adwaita/View/ProgressBar+.swift b/Sources/Core/View/ProgressBar+.swift similarity index 100% rename from Sources/Adwaita/View/ProgressBar+.swift rename to Sources/Core/View/ProgressBar+.swift diff --git a/Sources/Adwaita/View/ScrollView.swift b/Sources/Core/View/ScrollView.swift similarity index 100% rename from Sources/Adwaita/View/ScrollView.swift rename to Sources/Core/View/ScrollView.swift diff --git a/Sources/Adwaita/View/StatusPage+.swift b/Sources/Core/View/StatusPage+.swift similarity index 74% rename from Sources/Adwaita/View/StatusPage+.swift rename to Sources/Core/View/StatusPage+.swift index 8e1c830..472e9ae 100644 --- a/Sources/Adwaita/View/StatusPage+.swift +++ b/Sources/Core/View/StatusPage+.swift @@ -26,11 +26,4 @@ extension StatusPage { self = self.child(content) } - /// Make the status page more compact. - /// - Parameter active: Whether the style is applied. - /// - Returns: A view. - public func compact(_ active: Bool = true) -> AnyView { - style("compact", active: active) - } - } diff --git a/Sources/Adwaita/View/Text.swift b/Sources/Core/View/Text.swift similarity index 100% rename from Sources/Adwaita/View/Text.swift rename to Sources/Core/View/Text.swift diff --git a/Sources/Adwaita/View/Toggle.swift b/Sources/Core/View/Toggle.swift similarity index 100% rename from Sources/Adwaita/View/Toggle.swift rename to Sources/Core/View/Toggle.swift diff --git a/Sources/Adwaita/View/VStack.swift b/Sources/Core/View/VStack.swift similarity index 95% rename from Sources/Adwaita/View/VStack.swift rename to Sources/Core/View/VStack.swift index 602fe3a..e28cc64 100644 --- a/Sources/Adwaita/View/VStack.swift +++ b/Sources/Core/View/VStack.swift @@ -32,11 +32,6 @@ extension VStack { } } - /// Link the children. - public func linked(_ active: Bool = true) -> AnyView { - style("linked", active: active) - } - } /// A wrapper around ``VStack`` which applies the ``VStack`` only if there is more than one view. diff --git a/Sources/Adwaita/View/ViewStack.swift b/Sources/Core/View/ViewStack.swift similarity index 100% rename from Sources/Adwaita/View/ViewStack.swift rename to Sources/Core/View/ViewStack.swift diff --git a/Sources/Adwaita/View/ViewSwitcher.swift b/Sources/Core/View/ViewSwitcher.swift similarity index 100% rename from Sources/Adwaita/View/ViewSwitcher.swift rename to Sources/Core/View/ViewSwitcher.swift diff --git a/Sources/Adwaita/Window/Window.swift b/Sources/Core/Window/Window.swift similarity index 100% rename from Sources/Adwaita/Window/Window.swift rename to Sources/Core/Window/Window.swift diff --git a/Sources/Generation/GenerationConfiguration.swift b/Sources/Generation/GenerationConfiguration.swift index 567470b..aa4724f 100644 --- a/Sources/Generation/GenerationConfiguration.swift +++ b/Sources/Generation/GenerationConfiguration.swift @@ -35,7 +35,7 @@ struct GenerationConfiguration { var adwGirFilePath = adwGirFilePath + "Adw-1.gir" /// The folder containing the generated Swift files. - var folder = "Sources/Adwaita/View/Generated/" + var folder = "Sources/Core/View/Generated/" /// The Libadwaita widgets. var adwWidgets: [WidgetConfiguration] = [