Add homogeneous option to ForEach #74
This commit is contained in:
parent
b364557f2f
commit
cf60b8103f
@ -17,6 +17,8 @@ public struct ForEach<Element>: AdwaitaWidget where Element: Identifiable {
|
|||||||
var content: (Element) -> Body
|
var content: (Element) -> Body
|
||||||
/// Whether the list is horizontal.
|
/// Whether the list is horizontal.
|
||||||
var horizontal: Bool
|
var horizontal: Bool
|
||||||
|
/// Whether the children should all be the same size.
|
||||||
|
var homogeneous: Bool?
|
||||||
|
|
||||||
/// Initialize `ForEach`.
|
/// Initialize `ForEach`.
|
||||||
public init(_ elements: [Element], horizontal: Bool = false, @ViewBuilder content: @escaping (Element) -> Body) {
|
public init(_ elements: [Element], horizontal: Bool = false, @ViewBuilder content: @escaping (Element) -> Body) {
|
||||||
@ -73,10 +75,16 @@ public struct ForEach<Element>: AdwaitaWidget where Element: Identifiable {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
if updateProperties {
|
if updateProperties {
|
||||||
gtk_orientable_set_orientation(
|
if (storage.previousState as? Self)?.horizontal != horizontal {
|
||||||
widget?.opaque(),
|
gtk_orientable_set_orientation(
|
||||||
horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL
|
widget?.opaque(),
|
||||||
)
|
horizontal ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if let homogeneous, (storage.previousState as? Self)?.homogeneous != homogeneous {
|
||||||
|
gtk_box_set_homogeneous(widget?.cast(), homogeneous.cBool)
|
||||||
|
}
|
||||||
|
storage.previousState = self
|
||||||
}
|
}
|
||||||
storage.fields["element"] = elements
|
storage.fields["element"] = elements
|
||||||
storage.content[.mainContent] = contentStorage
|
storage.content[.mainContent] = contentStorage
|
||||||
@ -91,4 +99,11 @@ public struct ForEach<Element>: AdwaitaWidget where Element: Identifiable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the children should all be the same size.
|
||||||
|
/// - Parameter homogeneous: Whether the children should all be the same size.
|
||||||
|
/// - Returns: The for each view.
|
||||||
|
public func homogeneous(_ homogeneous: Bool? = true) -> Self {
|
||||||
|
modify { $0.homogeneous = homogeneous }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user