#[cfg(feature = "embedded-graphics")]
mod as_drawable;
pub mod button;
mod capturing;
mod divider;
mod empty_view;
mod foreach;
mod geometry_reader;
mod hstack;
#[cfg(feature = "embedded-graphics")]
mod image;
#[allow(missing_docs)]
pub mod match_view;
mod modifier;
mod option;
pub mod scroll_view;
pub mod shape;
mod spacer;
mod text;
mod view_that_fits;
mod vstack;
mod zstack;
#[cfg(feature = "embedded-graphics")]
pub use as_drawable::AsDrawable;
pub use button::Button;
pub use capturing::Lens;
pub use divider::Divider;
pub use empty_view::EmptyView;
pub use foreach::ForEach;
pub use geometry_reader::GeometryReader;
pub use hstack::HStack;
#[cfg(feature = "embedded-graphics")]
pub use image::Image;
pub use modifier::aspect_ratio;
pub use modifier::padding;
pub use scroll_view::ScrollView;
pub use spacer::Spacer;
pub(crate) use text::{CharacterWrap, WordWrap};
pub use text::{HorizontalTextAlignment, Text, WrapStrategy};
pub use view_that_fits::{FitAxis, ViewThatFits};
pub use vstack::VStack;
pub use zstack::ZStack;
pub mod prelude {
pub use super::aspect_ratio::{ContentMode, Ratio};
pub use super::modifier::ViewModifier;
#[cfg(feature = "embedded-graphics")]
pub use super::{AsDrawable, Image};
pub use super::{
Button, Divider, EmptyView, ForEach, GeometryReader, HStack, Lens, ScrollView, Spacer,
Text, VStack, View, ViewLayout, ViewThatFits, ZStack,
};
pub use super::{FitAxis, HorizontalTextAlignment, padding::Edges};
pub use crate::animation::Animation;
pub use crate::layout::{Alignment, HorizontalAlignment, VerticalAlignment};
pub use crate::view::shape::*;
}
use crate::transition::Transition;
use crate::{
environment::LayoutEnvironment,
event::{Event, EventContext, EventResult},
layout::ResolvedLayout,
primitives::{Point, ProposedDimensions},
render::Render,
};
pub trait View<Color, Captures: ?Sized>: ViewLayout<Captures, Renderables: Render<Color>> {}
impl<T, Color, Captures: ?Sized> View<Color, Captures> for T where
Self: ViewLayout<Captures, Renderables: Render<Color>>
{
}
pub trait ViewMarker: Sized {
type Renderables: Clone;
type Transition: Transition;
}
pub trait ViewLayout<Captures: ?Sized>: ViewMarker {
type State: 'static;
type Sublayout: Clone + PartialEq + 'static;
fn priority(&self) -> i8 {
0
}
fn is_empty(&self) -> bool {
false
}
fn transition(&self) -> Self::Transition;
fn build_state(&self, captures: &mut Captures) -> Self::State;
fn layout(
&self,
offer: &ProposedDimensions,
env: &impl LayoutEnvironment,
captures: &mut Captures,
state: &mut Self::State,
) -> ResolvedLayout<Self::Sublayout>;
fn render_tree(
&self,
layout: &Self::Sublayout,
origin: Point,
env: &impl LayoutEnvironment,
captures: &mut Captures,
state: &mut Self::State,
) -> Self::Renderables;
fn handle_event(
&self,
_event: &Event,
_context: &EventContext,
_render_tree: &mut Self::Renderables,
_captures: &mut Captures,
_state: &mut Self::State,
) -> EventResult {
EventResult::default()
}
}
impl<T> ViewMarker for &T
where
T: ViewMarker,
{
type Renderables = T::Renderables;
type Transition = T::Transition;
}
impl<T, Captures: ?Sized> ViewLayout<Captures> for &T
where
T: ViewLayout<Captures>,
{
type State = T::State;
type Sublayout = T::Sublayout;
fn transition(&self) -> Self::Transition {
(*self).transition()
}
fn build_state(&self, captures: &mut Captures) -> Self::State {
(*self).build_state(captures)
}
fn layout(
&self,
offer: &ProposedDimensions,
env: &impl LayoutEnvironment,
captures: &mut Captures,
state: &mut Self::State,
) -> ResolvedLayout<Self::Sublayout> {
(*self).layout(offer, env, captures, state)
}
fn render_tree(
&self,
layout: &Self::Sublayout,
origin: Point,
env: &impl LayoutEnvironment,
captures: &mut Captures,
state: &mut Self::State,
) -> Self::Renderables {
(*self).render_tree(layout, origin, env, captures, state)
}
fn priority(&self) -> i8 {
(*self).priority()
}
fn is_empty(&self) -> bool {
(*self).is_empty()
}
fn handle_event(
&self,
event: &Event,
context: &EventContext,
render_tree: &mut Self::Renderables,
captures: &mut Captures,
state: &mut Self::State,
) -> EventResult {
(*self).handle_event(event, context, render_tree, captures, state)
}
}
macro_rules! impl_marker_for_tuple {
($($type:ident),+) => {
impl<$($type),+> ViewMarker for ($($type),+,)
where
$($type: ViewMarker),+
{
type Renderables = ();
type Transition = crate::transition::Opacity;
}
}
}
impl_marker_for_tuple!(T0);
impl_marker_for_tuple!(T0, T1);
impl_marker_for_tuple!(T0, T1, T2);
impl_marker_for_tuple!(T0, T1, T2, T3);
impl_marker_for_tuple!(T0, T1, T2, T3, T4);
impl_marker_for_tuple!(T0, T1, T2, T3, T4, T5);
impl_marker_for_tuple!(T0, T1, T2, T3, T4, T5, T6);
impl_marker_for_tuple!(T0, T1, T2, T3, T4, T5, T6, T7);
impl_marker_for_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8);
impl_marker_for_tuple!(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9);