Add view modifier detecting clicks on any widget
This commit is contained in:
parent
5a1c325580
commit
1e6143acce
@ -36,6 +36,12 @@ Run a function when the view appears for the first time.
|
||||
- Parameter closure: The function.
|
||||
- Returns: A view.
|
||||
|
||||
### `onClick(handler:)`
|
||||
|
||||
Run a function when the widget gets clicked.
|
||||
- Parameter handler: The function.
|
||||
- Returns: A view.
|
||||
|
||||
### `frame(maxSize:)`
|
||||
|
||||
Set the view's maximal size.
|
||||
|
||||
@ -50,4 +50,11 @@ extension View {
|
||||
inspectOnAppear { _ in closure() }
|
||||
}
|
||||
|
||||
/// Run a function when the widget gets clicked.
|
||||
/// - Parameter handler: The function.
|
||||
/// - Returns: A view.
|
||||
public func onClick(handler: @escaping () -> Void) -> View {
|
||||
inspectOnAppear { _ = $0.onClick(closure: handler) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -33,6 +33,7 @@ struct CarouselDemo: View {
|
||||
.vexpand()
|
||||
.hexpand()
|
||||
.style("card")
|
||||
.onClick { print(element.id) }
|
||||
.padding(20)
|
||||
.frame(minWidth: 300, minHeight: 200)
|
||||
.frame(maxSize: 500)
|
||||
|
||||
@ -50,6 +50,7 @@ This is an overview of the available widgets and other components in _Adwaita_.
|
||||
| `toast(_:signal:button:handler:)` | Show a toast with a button on top of the view whenever the signal gets activated. |
|
||||
| `overlay(_:)` | Overlay a view with another view. |
|
||||
| `insensitive(_:)` | Make a view unable to detect actions. This is especially useful for overlays. |
|
||||
| `onClick(handler:)` | Run a function when the user clicks on the widget. |
|
||||
|
||||
### `Button` Modifiers
|
||||
| Syntax | Description |
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user