Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove view tuple extension #651

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}