forked from aparoksha/adwaita-swift
Improve onClick observer
This commit is contained in:
parent
aef77da78b
commit
db8d667238
@ -40,7 +40,7 @@ public class ViewStorage {
|
|||||||
public class SignalData {
|
public class SignalData {
|
||||||
|
|
||||||
/// The closure.
|
/// The closure.
|
||||||
public var closure: ([UnsafeMutableRawPointer]) -> Void
|
public var closure: ([Any]) -> Void
|
||||||
|
|
||||||
/// The closure as a C handler.
|
/// The closure as a C handler.
|
||||||
var handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void {
|
var handler: @convention(c) (UnsafeMutableRawPointer, UnsafeMutableRawPointer) -> Void {
|
||||||
@ -53,7 +53,7 @@ public class ViewStorage {
|
|||||||
/// The closure as a C handler with three parameters.
|
/// The closure as a C handler with three parameters.
|
||||||
var threeParamsHandler: @convention(c) (
|
var threeParamsHandler: @convention(c) (
|
||||||
UnsafeMutableRawPointer,
|
UnsafeMutableRawPointer,
|
||||||
UnsafeMutableRawPointer,
|
UnsafeRawPointer?,
|
||||||
UnsafeMutableRawPointer
|
UnsafeMutableRawPointer
|
||||||
) -> Void {
|
) -> Void {
|
||||||
{ _, arg1, data in
|
{ _, arg1, data in
|
||||||
@ -65,8 +65,8 @@ public class ViewStorage {
|
|||||||
/// The closure as a C handler with four parameters.
|
/// The closure as a C handler with four parameters.
|
||||||
var fourParamsHandler: @convention(c) (
|
var fourParamsHandler: @convention(c) (
|
||||||
UnsafeMutableRawPointer,
|
UnsafeMutableRawPointer,
|
||||||
UnsafeMutableRawPointer,
|
UnsafeRawPointer?,
|
||||||
UnsafeMutableRawPointer,
|
UnsafeRawPointer?,
|
||||||
UnsafeMutableRawPointer
|
UnsafeMutableRawPointer
|
||||||
) -> Void {
|
) -> Void {
|
||||||
{ _, arg1, arg2, data in
|
{ _, arg1, arg2, data in
|
||||||
@ -78,15 +78,14 @@ public class ViewStorage {
|
|||||||
/// The closure as a C handler with five parameters.
|
/// The closure as a C handler with five parameters.
|
||||||
var fiveParamsHandler: @convention(c) (
|
var fiveParamsHandler: @convention(c) (
|
||||||
UnsafeMutableRawPointer,
|
UnsafeMutableRawPointer,
|
||||||
UnsafeMutableRawPointer,
|
UnsafeRawPointer?,
|
||||||
UnsafeMutableRawPointer,
|
Double,
|
||||||
UnsafeMutableRawPointer,
|
Double,
|
||||||
UnsafeMutableRawPointer
|
UnsafeMutableRawPointer
|
||||||
) -> 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])
|
||||||
print("Hi")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +97,7 @@ public class ViewStorage {
|
|||||||
|
|
||||||
/// Initialize the signal data.
|
/// Initialize the signal data.
|
||||||
/// - Parameter closure: The signal's closure.
|
/// - Parameter closure: The signal's closure.
|
||||||
public init(closure: @escaping ([UnsafeMutableRawPointer]) -> Void) {
|
public init(closure: @escaping ([Any]) -> Void) {
|
||||||
self.closure = closure
|
self.closure = closure
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +150,7 @@ public class ViewStorage {
|
|||||||
id: String = "",
|
id: String = "",
|
||||||
connectFlags: GConnectFlags = G_CONNECT_AFTER,
|
connectFlags: GConnectFlags = G_CONNECT_AFTER,
|
||||||
argCount: Int = 0,
|
argCount: Int = 0,
|
||||||
handler: @escaping ([UnsafeMutableRawPointer]) -> Void
|
handler: @escaping ([Any]) -> Void
|
||||||
) {
|
) {
|
||||||
if let data = handlers[name + id] {
|
if let data = handlers[name + id] {
|
||||||
data.closure = handler
|
data.closure = handler
|
||||||
|
|||||||
@ -59,7 +59,8 @@ extension View {
|
|||||||
let controller = ViewStorage(gtk_gesture_click_new())
|
let controller = ViewStorage(gtk_gesture_click_new())
|
||||||
gtk_widget_add_controller(storage.pointer?.cast(), controller.pointer)
|
gtk_widget_add_controller(storage.pointer?.cast(), controller.pointer)
|
||||||
storage.fields["controller"] = controller
|
storage.fields["controller"] = controller
|
||||||
controller.connectSignal(name: "stopped", argCount: 0, handler: handler)
|
let argCount = 3
|
||||||
|
controller.connectSignal(name: "released", argCount: argCount, handler: handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user