This commit is contained in:
JMARyA 2025-01-16 23:21:52 +01:00
parent cd3d4a5a6d
commit 8887eb07c1
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
2 changed files with 149 additions and 165 deletions

View file

@ -55,6 +55,36 @@ impl DivWidget {
self
}
#[must_use]
pub fn push_if<T: UIWidget + 'static, U: Fn() -> T>(
mut self,
condition: bool,
then: U,
) -> Self {
if condition {
self.0.push(Box::new(then()));
}
self
}
#[must_use]
pub fn push_for<
'a,
T: UIWidget + 'static,
X: 'a,
U: Fn(&X) -> T,
I: IntoIterator<Item = &'a X>,
>(
mut self,
iterator: I,
then: U,
) -> Self {
for val in iterator {
self.0.push(Box::new(then(val)));
}
self
}
/// Extract the `<div>`s innerHTML
///
/// This will render `<content>` instead of `<div> <content> </div>`