forked from aparoksha/adwaita-swift
Add freeze modifier
Prevent a view from being updated
This commit is contained in:
parent
5cf2be2f54
commit
6b5e1c1a25
46
Sources/Adwaita/View/Modifiers/Freeze.swift
Normal file
46
Sources/Adwaita/View/Modifiers/Freeze.swift
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
//
|
||||||
|
// Freeze.swift
|
||||||
|
// Adwaita
|
||||||
|
//
|
||||||
|
// Created by david-swift on 13.02.24.
|
||||||
|
//
|
||||||
|
|
||||||
|
/// State whether to update the child views or not.
|
||||||
|
struct Freeze: Widget {
|
||||||
|
|
||||||
|
/// Whether not to update the child view.
|
||||||
|
var freeze: Bool
|
||||||
|
/// The wrapped view.
|
||||||
|
var content: View
|
||||||
|
|
||||||
|
/// Get the content's container.
|
||||||
|
/// - Parameter modifiers: Modify views before being updated.
|
||||||
|
/// - Returns: The content's container.
|
||||||
|
func container(modifiers: [(View) -> View]) -> ViewStorage {
|
||||||
|
let storage = content.storage(modifiers: [])
|
||||||
|
return storage
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the content.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - storage: The content's storage.
|
||||||
|
/// - modifiers: Modify views before being updated.
|
||||||
|
/// - updateProperties: Whether to update properties.
|
||||||
|
func update(_ storage: ViewStorage, modifiers: [(View) -> View], updateProperties: Bool) {
|
||||||
|
if !freeze {
|
||||||
|
content.updateStorage(storage, modifiers: [], updateProperties: updateProperties)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
|
||||||
|
/// Prevent a view from being updated.
|
||||||
|
/// - Parameter freeze: Whether to freeze the view.
|
||||||
|
/// - Returns: A view.
|
||||||
|
public func freeze(_ freeze: Bool = true) -> View {
|
||||||
|
Freeze(freeze: freeze, content: self)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -22,6 +22,7 @@ There are many more widgets available using auto-generation. Learn [how to use t
|
|||||||
|
|
||||||
| Syntax | Description |
|
| Syntax | Description |
|
||||||
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
|
| `freeze(_:)` | Prevent a view from being updated. |
|
||||||
| `inspect(_:)` | Edit the underlying Gtk or Libadwaita widget. |
|
| `inspect(_:)` | Edit the underlying Gtk or Libadwaita widget. |
|
||||||
| `padding(_:_:)` | Add empty space around a view. |
|
| `padding(_:_:)` | Add empty space around a view. |
|
||||||
| `hexpand(_:)` | Enable or disable the horizontal expansion of a view. |
|
| `hexpand(_:)` | Enable or disable the horizontal expansion of a view. |
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user