Fix style
This commit is contained in:
parent
edb6a81812
commit
557ec14232
@ -19,7 +19,7 @@ public class SignalData {
|
|||||||
var handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void {
|
var handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void {
|
||||||
{ _, data in
|
{ _, data in
|
||||||
let data = unsafeBitCast(data, to: SignalData.self)
|
let data = unsafeBitCast(data, to: SignalData.self)
|
||||||
data.closure([])
|
_ = data.closure([])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ public class SignalData {
|
|||||||
) -> Void {
|
) -> Void {
|
||||||
{ _, arg1, data in
|
{ _, arg1, data in
|
||||||
let data = unsafeBitCast(data, to: SignalData.self)
|
let data = unsafeBitCast(data, to: SignalData.self)
|
||||||
data.closure([arg1])
|
_ = data.closure([arg1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public class SignalData {
|
|||||||
) -> Void {
|
) -> Void {
|
||||||
{ _, arg1, arg2, data in
|
{ _, arg1, arg2, data in
|
||||||
let data = unsafeBitCast(data, to: SignalData.self)
|
let data = unsafeBitCast(data, to: SignalData.self)
|
||||||
data.closure([arg1, arg2])
|
_ = data.closure([arg1, arg2])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ public class SignalData {
|
|||||||
) -> Void {
|
) -> Void {
|
||||||
{ _, arg1, arg2, arg3, data in
|
{ _, arg1, arg2, arg3, data in
|
||||||
let data = unsafeBitCast(data, to: SignalData.self)
|
let data = unsafeBitCast(data, to: SignalData.self)
|
||||||
data.closure([arg1, arg2, arg3])
|
_ = data.closure([arg1, arg2, arg3])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
133
Sources/Adwaita/Window/Window+.swift
Normal file
133
Sources/Adwaita/Window/Window+.swift
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
//
|
||||||
|
// Window+.swift
|
||||||
|
// Adwaita
|
||||||
|
//
|
||||||
|
// Created by david-swift on 30.10.25.
|
||||||
|
//
|
||||||
|
|
||||||
|
extension Window {
|
||||||
|
|
||||||
|
/// Add a keyboard shortcut.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - shortcut: The keyboard shortcut.
|
||||||
|
/// - action: The closure to execute when the keyboard shortcut is pressed.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func keyboardShortcut(_ shortcut: String, action: @escaping (AdwaitaWindow) -> Void) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.shortcuts[shortcut] = action
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add the shortcut "<Ctrl>w" which closes the window.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func closeShortcut() -> Self {
|
||||||
|
keyboardShortcut("w".ctrl()) { $0.close() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a keyboard shortcut for the whole application.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - shortcut: The keyboard shortcut.
|
||||||
|
/// - action: The closure to execute when the keyboard shortcut is pressed.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func appKeyboardShortcut(_ shortcut: String, action: @escaping (AdwaitaApp) -> Void) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.appShortcuts[shortcut] = action
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add the shortcut "<Ctrl>q" which quits the application.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func quitShortcut() -> Self {
|
||||||
|
appKeyboardShortcut("q".ctrl()) { $0.quit() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the window's default size.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - width: The window's width.
|
||||||
|
/// - height: The window's height.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func defaultSize(width: Int? = nil, height: Int? = nil) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.defaultWidth = width
|
||||||
|
newSelf.defaultHeight = height
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the window's title.
|
||||||
|
/// - Parameter title: The title.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func title(_ title: String?) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.title = title
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set whether the window is resizable.
|
||||||
|
/// - Parameter resizable: The resizability.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func resizable(_ resizable: Bool?) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.resizable = resizable
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set whether the window is deletable.
|
||||||
|
/// - Parameter resizable: The deletability.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func deletable(_ deletable: Bool?) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.deletable = deletable
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the window's width and height.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - width: The window's actual width.
|
||||||
|
/// - height: The window's actual height.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func size(width: Binding<Int>? = nil, height: Binding<Int>? = nil) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.width = width
|
||||||
|
newSelf.height = height
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the window's minimum width and height.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - minWidth: The window's minimum width.
|
||||||
|
/// - minHeight: The window's minimum height.
|
||||||
|
public func minSize(width: Int = -1, height: Int = -1) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.minWidth = width
|
||||||
|
newSelf.minHeight = height
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get and set whether the window is maximized.
|
||||||
|
/// - Parameter maximized: Whether the window is maximized.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func maximized(_ maximized: Binding<Bool>?) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.maximized = maximized
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the window used the development style.
|
||||||
|
/// - Parameter active: Whether the style is active.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func devel(_ active: Bool? = true) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.devel = active
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Run this closure when the window should be closed.
|
||||||
|
/// - Parameter onClose: The closure.
|
||||||
|
/// - Returns: The window.
|
||||||
|
public func onClose(onClose: @escaping () -> CloseConfirmation) -> Self {
|
||||||
|
var newSelf = self
|
||||||
|
newSelf.onClose = onClose
|
||||||
|
return newSelf
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -277,129 +277,6 @@ public struct Window: AdwaitaSceneElement {
|
|||||||
return (width: .init(width), height: .init(height))
|
return (width: .init(width), height: .init(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a keyboard shortcut.
|
|
||||||
/// - Parameters:
|
|
||||||
/// - shortcut: The keyboard shortcut.
|
|
||||||
/// - action: The closure to execute when the keyboard shortcut is pressed.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func keyboardShortcut(_ shortcut: String, action: @escaping (AdwaitaWindow) -> Void) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.shortcuts[shortcut] = action
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add the shortcut "<Ctrl>w" which closes the window.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func closeShortcut() -> Self {
|
|
||||||
keyboardShortcut("w".ctrl()) { $0.close() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add a keyboard shortcut for the whole application.
|
|
||||||
/// - Parameters:
|
|
||||||
/// - shortcut: The keyboard shortcut.
|
|
||||||
/// - action: The closure to execute when the keyboard shortcut is pressed.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func appKeyboardShortcut(_ shortcut: String, action: @escaping (AdwaitaApp) -> Void) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.appShortcuts[shortcut] = action
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add the shortcut "<Ctrl>q" which quits the application.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func quitShortcut() -> Self {
|
|
||||||
appKeyboardShortcut("q".ctrl()) { $0.quit() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the window's default size.
|
|
||||||
/// - Parameters:
|
|
||||||
/// - width: The window's width.
|
|
||||||
/// - height: The window's height.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func defaultSize(width: Int? = nil, height: Int? = nil) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.defaultWidth = width
|
|
||||||
newSelf.defaultHeight = height
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the window's title.
|
|
||||||
/// - Parameter title: The title.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func title(_ title: String?) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.title = title
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set whether the window is resizable.
|
|
||||||
/// - Parameter resizable: The resizability.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func resizable(_ resizable: Bool?) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.resizable = resizable
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set whether the window is deletable.
|
|
||||||
/// - Parameter resizable: The deletability.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func deletable(_ deletable: Bool?) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.deletable = deletable
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the window's width and height.
|
|
||||||
/// - Parameters:
|
|
||||||
/// - width: The window's actual width.
|
|
||||||
/// - height: The window's actual height.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func size(width: Binding<Int>? = nil, height: Binding<Int>? = nil) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.width = width
|
|
||||||
newSelf.height = height
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set the window's minimum width and height.
|
|
||||||
/// - Parameters:
|
|
||||||
/// - minWidth: The window's minimum width.
|
|
||||||
/// - minHeight: The window's minimum height.
|
|
||||||
public func minSize(width: Int = -1, height: Int = -1) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.minWidth = width
|
|
||||||
newSelf.minHeight = height
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get and set whether the window is maximized.
|
|
||||||
/// - Parameter maximized: Whether the window is maximized.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func maximized(_ maximized: Binding<Bool>?) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.maximized = maximized
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether the window used the development style.
|
|
||||||
/// - Parameter active: Whether the style is active.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func devel(_ active: Bool? = true) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.devel = active
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Run this closure when the window should be closed.
|
|
||||||
/// - Parameter onClose: The closure.
|
|
||||||
/// - Returns: The window.
|
|
||||||
public func onClose(onClose: @escaping () -> CloseConfirmation) -> Self {
|
|
||||||
var newSelf = self
|
|
||||||
newSelf.onClose = onClose
|
|
||||||
return newSelf
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// swiftlint:enable discouraged_optional_collection
|
// swiftlint:enable discouraged_optional_collection
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user