summaryrefslogtreecommitdiffstats
path: root/lazy
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-01-12 11:48:49 +0700
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-01-12 11:48:49 +0700
commitf6c436aec1acb674078bf7e878b9e49f28e947a7 (patch)
treedd5fa045c9fd3f8f116f230c3e70dcba2d32d011 /lazy
parent241e123c9b49bb5f8c6bf223eef666c94042dd8f (diff)
downloadiced-f6c436aec1acb674078bf7e878b9e49f28e947a7.tar.gz
iced-f6c436aec1acb674078bf7e878b9e49f28e947a7.tar.bz2
iced-f6c436aec1acb674078bf7e878b9e49f28e947a7.zip
Write docs for `responsive` in `iced_lazy`
Diffstat (limited to 'lazy')
-rw-r--r--lazy/src/responsive.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/lazy/src/responsive.rs b/lazy/src/responsive.rs
index 2afad2e5..da7bb408 100644
--- a/lazy/src/responsive.rs
+++ b/lazy/src/responsive.rs
@@ -1,3 +1,4 @@
+//! Build responsive widgets.
use crate::{Cache, CacheBuilder};
use iced_native::event::{self, Event};
@@ -13,6 +14,7 @@ use std::cell::RefCell;
use std::hash::{Hash, Hasher as _};
use std::ops::Deref;
+/// The state of a [`Responsive`] widget.
#[derive(Debug, Clone, Default)]
pub struct State {
last_size: Option<Size>,
@@ -25,7 +27,7 @@ impl State {
State::default()
}
- pub fn layout(&self, parent: Layout<'_>) -> Layout<'_> {
+ fn layout(&self, parent: Layout<'_>) -> Layout<'_> {
Layout::with_offset(
parent.position() - Point::ORIGIN,
&self.last_layout,
@@ -33,12 +35,22 @@ impl State {
}
}
+/// A widget that is aware of its dimensions.
+///
+/// A [`Responsive`] widget will always try to fill all the available space of
+/// its parent.
#[allow(missing_debug_implementations)]
pub struct Responsive<'a, Message, Renderer>(
RefCell<Internal<'a, Message, Renderer>>,
);
impl<'a, Message, Renderer> Responsive<'a, Message, Renderer> {
+ /// Creates a new [`Responsive`] widget with the given [`State`] and 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 new(
state: &'a mut State,
view: impl FnOnce(Size) -> Element<'a, Message, Renderer> + 'a,