Add id modifier #74
This commit is contained in:
parent
92fe4fb256
commit
c29c6e22cb
@ -390,4 +390,11 @@ extension AnyView {
|
|||||||
BreakpointBin(condition: .naturalHeight(padding: padding), matches: matches) { self }
|
BreakpointBin(condition: .naturalHeight(padding: padding), matches: matches) { self }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build the UI from scratch once the identifier changes.
|
||||||
|
/// - Parameter id: The identifier.
|
||||||
|
public func id(_ id: CustomStringConvertible) -> AnyView {
|
||||||
|
ViewStack(id: id) { _ in self }
|
||||||
|
.limitChildren()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,8 @@ public struct ViewStack: AdwaitaWidget {
|
|||||||
var id: CustomStringConvertible
|
var id: CustomStringConvertible
|
||||||
/// Whether the view stack allocates the same height and width for all children.
|
/// Whether the view stack allocates the same height and width for all children.
|
||||||
var homogeneous: Bool?
|
var homogeneous: Bool?
|
||||||
|
/// Whether to limit the stack to one child (always redraw the UI when the id changes).
|
||||||
|
var limitChildren: Bool?
|
||||||
|
|
||||||
/// Initialize the stack.
|
/// Initialize the stack.
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
@ -87,14 +89,30 @@ public struct ViewStack: AdwaitaWidget {
|
|||||||
gtk_stack_set_vhomogeneous(storage.opaquePointer, homogeneous.cBool)
|
gtk_stack_set_vhomogeneous(storage.opaquePointer, homogeneous.cBool)
|
||||||
gtk_stack_set_hhomogeneous(storage.opaquePointer, homogeneous.cBool)
|
gtk_stack_set_hhomogeneous(storage.opaquePointer, homogeneous.cBool)
|
||||||
}
|
}
|
||||||
|
if let limitChildren, limitChildren {
|
||||||
|
for element in storage.content where element.key != id.description {
|
||||||
|
guard let first = element.value.first else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
gtk_stack_remove(storage.opaquePointer, first.opaquePointer?.cast())
|
||||||
|
storage.content.removeValue(forKey: element.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
storage.previousState = self
|
storage.previousState = self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the view stack allocates the same height and width for all children.
|
/// Whether the view stack allocates the same height and width for all children.
|
||||||
/// - Parameter homogeneous: Whether this is enabled.
|
/// - Parameter homogeneous: Whether this is enabled.
|
||||||
/// - Returns: The stack.
|
/// - Returns: The stack.
|
||||||
public func homogeneous(_ homogeneous: Bool? = nil) -> Self {
|
public func homogeneous(_ homogeneous: Bool? = true) -> Self {
|
||||||
modify { $0.homogeneous = homogeneous }
|
modify { $0.homogeneous = homogeneous }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether to limit the stack to one child (always redraw the UI when the id changes).
|
||||||
|
/// - Parameter limit: Whether to limit the stack to one child.
|
||||||
|
/// - Returns: The stack.
|
||||||
|
public func limitChildren(_ limitChildren: Bool? = true) -> Self {
|
||||||
|
modify { $0.limitChildren = limitChildren }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user