Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Improve onClick observer
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Jan 29, 2024
1 parent aef77da commit db8d667
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
19 changes: 9 additions & 10 deletions Sources/Adwaita/Model/User Interface/View/ViewStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ViewStorage {
public class SignalData {

/// The closure.
public var closure: ([UnsafeMutableRawPointer]) -> Void
public var closure: ([Any]) -> Void

/// The closure as a C handler.
var handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void {
Expand All @@ -53,7 +53,7 @@ public class ViewStorage {
/// The closure as a C handler with three parameters.
var threeParamsHandler: @convention(c) (
UnsafeMutableRawPointer,
UnsafeMutableRawPointer,
UnsafeRawPointer?,
UnsafeMutableRawPointer
) -> Void {
{ _, arg1, data in
Expand All @@ -65,8 +65,8 @@ public class ViewStorage {
/// The closure as a C handler with four parameters.
var fourParamsHandler: @convention(c) (
UnsafeMutableRawPointer,
UnsafeMutableRawPointer,
UnsafeMutableRawPointer,
UnsafeRawPointer?,
UnsafeRawPointer?,
UnsafeMutableRawPointer
) -> Void {
{ _, arg1, arg2, data in
Expand All @@ -78,15 +78,14 @@ public class ViewStorage {
/// The closure as a C handler with five parameters.
var fiveParamsHandler: @convention(c) (
UnsafeMutableRawPointer,
UnsafeMutableRawPointer,
UnsafeMutableRawPointer,
UnsafeMutableRawPointer,
UnsafeRawPointer?,
Double,
Double,
UnsafeMutableRawPointer
) -> Void {
{ _, arg1, arg2, arg3, data in
let data = unsafeBitCast(data, to: SignalData.self)
data.closure([arg1, arg2, arg3])
print("Hi")
}
}

Expand All @@ -98,7 +97,7 @@ public class ViewStorage {

/// Initialize the signal data.
/// - Parameter closure: The signal's closure.
public init(closure: @escaping ([UnsafeMutableRawPointer]) -> Void) {
public init(closure: @escaping ([Any]) -> Void) {
self.closure = closure
}

Expand Down Expand Up @@ -151,7 +150,7 @@ public class ViewStorage {
id: String = "",
connectFlags: GConnectFlags = G_CONNECT_AFTER,
argCount: Int = 0,
handler: @escaping ([UnsafeMutableRawPointer]) -> Void
handler: @escaping ([Any]) -> Void
) {
if let data = handlers[name + id] {
data.closure = handler
Expand Down
3 changes: 2 additions & 1 deletion Sources/Adwaita/View/Modifiers/AppearObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extension View {
let controller = ViewStorage(gtk_gesture_click_new())
gtk_widget_add_controller(storage.pointer?.cast(), controller.pointer)
storage.fields["controller"] = controller
controller.connectSignal(name: "stopped", argCount: 0, handler: handler)
let argCount = 3
controller.connectSignal(name: "released", argCount: argCount, handler: handler)
}
}

Expand Down

0 comments on commit db8d667

Please sign in to comment.