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

Commit

Permalink
Add freeze modifier
Browse files Browse the repository at this point in the history
Prevent a view from being updated
  • Loading branch information
david-swift committed Feb 13, 2024
1 parent 5cf2be2 commit 6b5e1c1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Sources/Adwaita/View/Modifiers/Freeze.swift
Original file line number Diff line number Diff line change
@@ -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)
}

}
1 change: 1 addition & 0 deletions user-manual/Information/Widgets.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ There are many more widgets available using auto-generation. Learn [how to use t

| Syntax | Description |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `freeze(_:)` | Prevent a view from being updated. |
| `inspect(_:)` | Edit the underlying Gtk or Libadwaita widget. |
| `padding(_:_:)` | Add empty space around a view. |
| `hexpand(_:)` | Enable or disable the horizontal expansion of a view. |
Expand Down

0 comments on commit 6b5e1c1

Please sign in to comment.