Add view modifier to set focus only

This commit is contained in:
david-swift 2024-02-14 20:31:40 +01:00
parent 9e05b2692b
commit b13fbcbcf1
3 changed files with 18 additions and 0 deletions

View File

@ -165,6 +165,12 @@ Bind to the view's focus.
- Parameter focus: Whether the view is focused.
- Returns: A view.
### `focus(_:)`
Bind a signal that focuses the view.
- Parameter focus: Whether the view is focused.
- Returns: A view.
### `stopModifiers()`
Remove all of the content modifiers for the wrapped views.

View File

@ -155,4 +155,15 @@ extension View {
}
}
/// Bind a signal that focuses the view.
/// - Parameter focus: Whether the view is focused.
/// - Returns: A view.
public func focus(_ signal: Signal) -> View {
inspect { storage in
if signal.update {
gtk_widget_grab_focus(storage.pointer?.cast())
}
}
}
}

View File

@ -48,6 +48,7 @@ There are many more widgets available using auto-generation. Learn [how to use t
| `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. |
| `focused(_:)` | Set and observe whether a view is focused. |
| `focus(_:)` | Bind a signal that focuses the view. |
| `verticalCenter()` | Wrap a view in a `VStack` and center vertically. |
| `horizontalCenter()` | Wrap a view in an `HStack` and center horizontally. |