From 0444726a2d9d33436ff692f2b3c5ee065205e60f Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 17 Jan 2025 14:55:55 +0100 Subject: [PATCH] update --- src/ui/primitives/div.rs | 20 +++++++------------- src/ui/primitives/height.rs | 18 +++++++++--------- src/ui/primitives/width.rs | 19 +++++++++++-------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/ui/primitives/div.rs b/src/ui/primitives/div.rs index c4a597d..05e8eb1 100644 --- a/src/ui/primitives/div.rs +++ b/src/ui/primitives/div.rs @@ -67,22 +67,16 @@ impl DivWidget { self } - // todo : Fix weird types #[must_use] - pub fn push_for_each< + pub fn push_for_each(mut self, items: &[X], mut action: F) -> Self + where T: UIWidget + 'static, - X, - U: Fn(&X) -> T, - I: Iterator, - O: Into, - >( - mut self, - iterator: O, - then: U, - ) -> Self { - for val in iterator.into() { - self.0.push(Box::new(then(&val))); + F: FnMut(&X) -> T, + { + for item in items { + self.0.push(Box::new(action(item))); } + self } diff --git a/src/ui/primitives/height.rs b/src/ui/primitives/height.rs index 72bff47..4e04fd5 100644 --- a/src/ui/primitives/height.rs +++ b/src/ui/primitives/height.rs @@ -7,27 +7,27 @@ use super::{ }; #[allow(non_snake_case)] -pub fn Height( - size: Either, +pub fn Height>>( + size: S, inner: T, ) -> HeightWidget { - HeightWidget(Box::new(inner), size, 0) + HeightWidget(Box::new(inner), size.into(), 0) } #[allow(non_snake_case)] -pub fn MinHeight( - size: Either, +pub fn MinHeight>>( + size: S, inner: T, ) -> HeightWidget { - HeightWidget(Box::new(inner), size, 1) + HeightWidget(Box::new(inner), size.into(), 1) } #[allow(non_snake_case)] -pub fn MaxHeight( - size: Either, +pub fn MaxHeight>>( + size: S, inner: T, ) -> HeightWidget { - HeightWidget(Box::new(inner), size, 2) + HeightWidget(Box::new(inner), size.into(), 2) } pub struct HeightWidget(Box, Either, u8); diff --git a/src/ui/primitives/width.rs b/src/ui/primitives/width.rs index b5e662e..f31f0cb 100644 --- a/src/ui/primitives/width.rs +++ b/src/ui/primitives/width.rs @@ -7,24 +7,27 @@ use super::{ }; #[allow(non_snake_case)] -pub fn Width(size: Either, inner: T) -> WidthWidget { - WidthWidget(Box::new(inner), size, 0) +pub fn Width>>( + size: S, + inner: T, +) -> WidthWidget { + WidthWidget(Box::new(inner), size.into(), 0) } #[allow(non_snake_case)] -pub fn MinWidth( - size: Either, +pub fn MinWidth>>( + size: S, inner: T, ) -> WidthWidget { - WidthWidget(Box::new(inner), size, 1) + WidthWidget(Box::new(inner), size.into(), 1) } #[allow(non_snake_case)] -pub fn MaxWidth( - size: Either, +pub fn MaxWidth>>( + size: S, inner: T, ) -> WidthWidget { - WidthWidget(Box::new(inner), size, 2) + WidthWidget(Box::new(inner), size.into(), 2) } pub struct WidthWidget(Box, Either, u8);