This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from AparokshaUI/1.0.0
Migrate to Meta backend
- Loading branch information
Showing
167 changed files
with
3,901 additions
and
5,186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// MenuCollection.swift | ||
// Adwaita | ||
// | ||
// Created by david-swift on 02.08.2024. | ||
// | ||
|
||
import CAdw | ||
import Foundation | ||
|
||
/// A collection of menus. | ||
public struct MenuCollection: MenuWidget, Wrapper { | ||
|
||
/// The content of the collection. | ||
var content: Body | ||
|
||
/// Initialize a menu. | ||
/// - Parameter content: The content of the collection. | ||
public init(@ViewBuilder content: @escaping () -> Body) { | ||
self.content = content() | ||
} | ||
|
||
/// The view storage. | ||
/// - Parameters: | ||
/// - modifiers: Modify the views before updating. | ||
/// - type: The type of the views. | ||
/// - Returns: The view storage. | ||
public func container<Data>( | ||
data: WidgetData, | ||
type: Data.Type | ||
) -> ViewStorage where Data: ViewRenderData { | ||
let storages = content.storages(data: data, type: type) | ||
return .init(nil, content: [.mainContent: storages]) | ||
} | ||
|
||
/// Update the stored content. | ||
/// - Parameters: | ||
/// - storage: The storage to update. | ||
/// - modifiers: Modify the views before updating. | ||
/// - updateProperties: Whether to update the properties. | ||
/// - type: The type of the views. | ||
public func update<Data>( | ||
_ storage: ViewStorage, | ||
data: WidgetData, | ||
updateProperties: Bool, | ||
type: Data.Type | ||
) where Data: ViewRenderData { | ||
guard let storages = storage.content[.mainContent] else { | ||
return | ||
} | ||
content.update(storages, data: data, updateProperties: updateProperties, type: type) | ||
} | ||
|
||
/// Render the collection as a menu. | ||
/// - Parameter data: The widget data. | ||
/// - Returns: The view storage with the GMenu as the pointer. | ||
public func getMenu(data: WidgetData) -> ViewStorage { | ||
let menu = g_menu_new() | ||
let storage = container(data: data.noModifiers, type: MenuContext.self) | ||
if let app = data.appStorage as? AdwaitaApp, let window = data.sceneStorage.pointer as? AdwaitaWindow { | ||
initializeMenu(menu: menu, storage: storage, app: app, window: window) | ||
} | ||
storage.pointer = menu | ||
return storage | ||
} | ||
|
||
/// Initialize a menu. | ||
/// - Parameters: | ||
/// - menu: The pointer to the GMenu. | ||
/// - storage: The storage for the menu's content. | ||
/// - app: The app object. | ||
/// - window: The window object. | ||
func initializeMenu(menu: OpaquePointer?, storage: ViewStorage, app: AdwaitaApp, window: AdwaitaWindow?) { | ||
if let item = storage.opaquePointer { | ||
g_menu_append_item(menu, item) | ||
storage.pointer = item | ||
} else { | ||
for element in storage.content[.mainContent] ?? [] { | ||
initializeMenu(menu: menu, storage: element, app: app, window: window) | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// MenuContext.swift | ||
// Adwaita | ||
// | ||
// Created by david-swift on 01.08.24. | ||
// | ||
|
||
/// The menu items view context. | ||
public enum MenuContext: ViewRenderData { | ||
|
||
/// The type of the widgets. | ||
public typealias WidgetType = MenuWidget | ||
/// The wrapper type. | ||
public typealias WrapperType = MenuCollection | ||
/// The either view type. | ||
public typealias EitherViewType = MenuEitherView | ||
|
||
} | ||
|
||
/// The type of the widgets. | ||
public protocol MenuWidget: Meta.Widget { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// MenuEitherView.swift | ||
// Adwaita | ||
// | ||
// Created by david-swift on 06.08.2024. | ||
// | ||
|
||
/// Show one of two views depending on a condition. | ||
public struct MenuEitherView: Meta.EitherView, SimpleView { | ||
|
||
/// The view. | ||
public var view: Body | ||
|
||
/// Initialize an either view. | ||
/// - Parameters: | ||
/// - condition: The condition. | ||
/// - view1: The first view. | ||
/// - view2: The second view. | ||
public init(_ condition: Bool, view1: () -> Body, else view2: () -> Body) { | ||
self.view = condition ? view1() : view2() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,58 @@ | ||
// | ||
// Submenu.swift | ||
// MenuButton.swift | ||
// Adwaita | ||
// | ||
// Created by david-swift on 22.10.23. | ||
// | ||
|
||
import CAdw | ||
|
||
/// A section for menus. | ||
public struct MenuSection: MenuItem { | ||
/// A button widget for menus. | ||
public struct MenuSection: MenuWidget { | ||
|
||
/// The content of the section. | ||
var sectionContent: MenuContent | ||
var sectionContent: Body | ||
|
||
/// Initialize a section for menus. | ||
/// - Parameter content: The content of the section. | ||
public init(@MenuBuilder content: () -> MenuContent) { | ||
public init(@ViewBuilder content: () -> Body) { | ||
self.sectionContent = content() | ||
} | ||
|
||
/// Add the section to a menu. | ||
/// The view storage. | ||
/// - Parameters: | ||
/// - menu: The menu. | ||
/// - app: The application containing the menu. | ||
/// - window: The application window containing the menu. | ||
public func addMenuItem(menu: OpaquePointer?, app: GTUIApp, window: GTUIApplicationWindow?) { | ||
let section = g_menu_new() | ||
g_menu_append_section(menu, nil, section?.cast()) | ||
for element in sectionContent { | ||
element.addMenuItems(menu: section, app: app, window: window) | ||
/// - modifiers: Modify the views before updating. | ||
/// - type: The type of the views. | ||
/// - Returns: The view storage. | ||
public func container<Data>( | ||
data: WidgetData, | ||
type: Data.Type | ||
) -> ViewStorage where Data: ViewRenderData { | ||
let storage = ViewStorage(nil) | ||
let childStorage = MenuCollection { sectionContent }.getMenu(data: data) | ||
storage.content[.mainContent] = [childStorage] | ||
let pointer = g_menu_item_new_section(nil, childStorage.opaquePointer?.cast()) | ||
storage.pointer = pointer | ||
return storage | ||
} | ||
|
||
/// Update the stored content. | ||
/// - Parameters: | ||
/// - storage: The storage to update. | ||
/// - modifiers: Modify the views before updating. | ||
/// - updateProperties: Whether to update the properties. | ||
/// - type: The type of the views. | ||
public func update<Data>( | ||
_ storage: ViewStorage, | ||
data: WidgetData, | ||
updateProperties: Bool, | ||
type: Data.Type | ||
) where Data: ViewRenderData { | ||
guard let content = storage.content[.mainContent]?.first else { | ||
return | ||
} | ||
MenuCollection { sectionContent } | ||
.updateStorage(content, data: data, updateProperties: updateProperties, type: MenuContext.self) | ||
} | ||
|
||
} |
Oops, something went wrong.