summaryrefslogtreecommitdiffstats
path: root/widget/src/lazy/helpers.rs
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2023-07-12 12:23:18 -0700
committerLibravatar Bingus <shankern@protonmail.com>2023-07-12 12:23:18 -0700
commit633f405f3f78bc7f82d2b2061491b0e011137451 (patch)
tree5ebfc1f45d216a5c14a90492563599e6969eab4d /widget/src/lazy/helpers.rs
parent41836dd80d0534608e7aedfbf2319c540a23de1a (diff)
parent21bd51426d900e271206f314e0c915dd41065521 (diff)
downloadiced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.gz
iced-633f405f3f78bc7f82d2b2061491b0e011137451.tar.bz2
iced-633f405f3f78bc7f82d2b2061491b0e011137451.zip
Merge remote-tracking branch 'origin/master' into feat/multi-window-support
# Conflicts: # Cargo.toml # core/src/window/icon.rs # core/src/window/id.rs # core/src/window/position.rs # core/src/window/settings.rs # examples/integration/src/main.rs # examples/integration_opengl/src/main.rs # glutin/src/application.rs # native/src/subscription.rs # native/src/window.rs # runtime/src/window/action.rs # src/lib.rs # src/window.rs # winit/Cargo.toml # winit/src/application.rs # winit/src/icon.rs # winit/src/settings.rs # winit/src/window.rs
Diffstat (limited to 'widget/src/lazy/helpers.rs')
-rw-r--r--widget/src/lazy/helpers.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/widget/src/lazy/helpers.rs b/widget/src/lazy/helpers.rs
new file mode 100644
index 00000000..8ca9cb86
--- /dev/null
+++ b/widget/src/lazy/helpers.rs
@@ -0,0 +1,47 @@
+use crate::core::{self, Element, Size};
+use crate::lazy::component::{self, Component};
+use crate::lazy::{Lazy, Responsive};
+
+use std::hash::Hash;
+
+/// Creates a new [`Lazy`] widget with the given data `Dependency` and a
+/// closure that can turn this data into a widget tree.
+pub fn lazy<'a, Message, Renderer, Dependency, View>(
+ dependency: Dependency,
+ view: impl Fn(&Dependency) -> View + 'a,
+) -> Lazy<'a, Message, Renderer, Dependency, View>
+where
+ Dependency: Hash + 'a,
+ View: Into<Element<'static, Message, Renderer>>,
+{
+ Lazy::new(dependency, view)
+}
+
+/// Turns an implementor of [`Component`] into an [`Element`] that can be
+/// embedded in any application.
+pub fn component<'a, C, Message, Renderer>(
+ component: C,
+) -> Element<'a, Message, Renderer>
+where
+ C: Component<Message, Renderer> + 'a,
+ C::State: 'static,
+ Message: 'a,
+ Renderer: core::Renderer + 'a,
+{
+ component::view(component)
+}
+
+/// Creates a new [`Responsive`] widget with a closure that produces its
+/// contents.
+///
+/// The `view` closure will be provided with the current [`Size`] of
+/// the [`Responsive`] widget and, therefore, can be used to build the
+/// contents of the widget in a responsive way.
+pub fn responsive<'a, Message, Renderer>(
+ f: impl Fn(Size) -> Element<'a, Message, Renderer> + 'a,
+) -> Responsive<'a, Message, Renderer>
+where
+ Renderer: core::Renderer,
+{
+ Responsive::new(f)
+}