2025-08-21 00:07:04 +02:00
|
|
|
use crate::core::{self, Element};
|
2024-09-05 14:46:11 +02:00
|
|
|
use crate::lazy::component;
|
2022-11-03 02:46:31 +01:00
|
|
|
|
|
|
|
|
use std::hash::Hash;
|
|
|
|
|
|
2024-09-05 15:08:08 +02:00
|
|
|
#[allow(deprecated)]
|
2025-08-21 00:07:04 +02:00
|
|
|
pub use crate::lazy::{Component, Lazy};
|
2024-09-05 14:46:11 +02:00
|
|
|
|
2023-05-11 15:40:57 +02:00
|
|
|
/// Creates a new [`Lazy`] widget with the given data `Dependency` and a
|
|
|
|
|
/// closure that can turn this data into a widget tree.
|
2024-01-05 13:50:38 +00:00
|
|
|
#[cfg(feature = "lazy")]
|
2024-01-21 17:56:01 +01:00
|
|
|
pub fn lazy<'a, Message, Theme, Renderer, Dependency, View>(
|
2022-11-03 02:46:31 +01:00
|
|
|
dependency: Dependency,
|
2023-01-11 07:45:36 -08:00
|
|
|
view: impl Fn(&Dependency) -> View + 'a,
|
2024-01-21 17:56:01 +01:00
|
|
|
) -> Lazy<'a, Message, Theme, Renderer, Dependency, View>
|
2022-11-03 02:46:31 +01:00
|
|
|
where
|
|
|
|
|
Dependency: Hash + 'a,
|
2024-01-21 17:56:01 +01:00
|
|
|
View: Into<Element<'static, Message, Theme, Renderer>>,
|
2022-11-03 02:46:31 +01:00
|
|
|
{
|
|
|
|
|
Lazy::new(dependency, view)
|
|
|
|
|
}
|
2022-07-27 06:49:20 +02:00
|
|
|
|
|
|
|
|
/// Turns an implementor of [`Component`] into an [`Element`] that can be
|
|
|
|
|
/// embedded in any application.
|
2024-01-05 13:50:38 +00:00
|
|
|
#[cfg(feature = "lazy")]
|
2024-09-05 15:08:08 +02:00
|
|
|
#[deprecated(
|
|
|
|
|
since = "0.13.0",
|
|
|
|
|
note = "components introduce encapsulated state and hamper the use of a single source of truth. \
|
|
|
|
|
Instead, leverage the Elm Architecture directly, or implement a custom widget"
|
|
|
|
|
)]
|
|
|
|
|
#[allow(deprecated)]
|
2024-01-21 17:56:01 +01:00
|
|
|
pub fn component<'a, C, Message, Theme, Renderer>(
|
2022-07-27 06:49:20 +02:00
|
|
|
component: C,
|
2024-01-21 17:56:01 +01:00
|
|
|
) -> Element<'a, Message, Theme, Renderer>
|
2022-07-27 06:49:20 +02:00
|
|
|
where
|
2024-01-21 17:56:01 +01:00
|
|
|
C: Component<Message, Theme, Renderer> + 'a,
|
2022-07-27 06:49:20 +02:00
|
|
|
C::State: 'static,
|
|
|
|
|
Message: 'a,
|
2024-01-21 17:56:01 +01:00
|
|
|
Theme: 'a,
|
2023-03-04 05:37:11 +01:00
|
|
|
Renderer: core::Renderer + 'a,
|
2022-07-27 06:49:20 +02:00
|
|
|
{
|
|
|
|
|
component::view(component)
|
|
|
|
|
}
|