Skip to content

Commit

Permalink
remove view tuple extension (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmoulton authored Nov 1, 2024
1 parent 30975f6 commit 450aa8b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
23 changes: 22 additions & 1 deletion src/view_tuple.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
use crate::view::{IntoView, View};
use taffy::FlexDirection;

use crate::{
view::{IntoView, View},
views::{create_stack, Stack},
};

pub trait ViewTuple {
fn into_views(self) -> Vec<Box<dyn View>>;
fn stack(self, direction: FlexDirection) -> Stack;
fn v_stack(self) -> Stack
where
Self: Sized,
{
ViewTuple::stack(self, FlexDirection::Column)
}
fn h_stack(self) -> Stack
where
Self: Sized,
{
ViewTuple::stack(self, FlexDirection::Row)
}
}

// Macro to implement ViewTuple for tuples of Views and Vec<Box<dyn View>>
Expand All @@ -15,6 +33,9 @@ macro_rules! impl_view_tuple {
$($t.into_any(),)+
]
}
fn stack(self, direction: FlexDirection) -> Stack {
create_stack(self.into_views(), Some(direction))
}
}

impl<$($t: IntoView + 'static),+> IntoView for ($($t,)+) {
Expand Down
22 changes: 0 additions & 22 deletions src/views/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,3 @@ impl<V: IntoView + 'static, T: IntoIterator<Item = V> + 'static> StackExt for T
from_iter(self, Some(direction))
}
}
// Necessary to have a separate Ext trait because IntoIterator could be implemented on tuples of specific view types
pub trait TupleStackExt {
fn stack(self, direction: FlexDirection) -> Stack;
fn v_stack(self) -> Stack
where
Self: Sized,
{
TupleStackExt::stack(self, FlexDirection::Column)
}
fn h_stack(self) -> Stack
where
Self: Sized,
{
TupleStackExt::stack(self, FlexDirection::Row)
}
}

impl<T: ViewTuple + 'static> TupleStackExt for T {
fn stack(self, direction: FlexDirection) -> Stack {
create_stack(self.into_views(), Some(direction))
}
}

0 comments on commit 450aa8b

Please sign in to comment.