diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index a40df370..14d20103 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -10,7 +10,7 @@ use iced::animation; use iced::time::{Instant, milliseconds}; use iced::widget::{ button, container, float, grid, horizontal_space, image, mouse_area, - opaque, pop, scrollable, stack, + opaque, scrollable, sensor, stack, }; use iced::window; use iced::{ @@ -257,7 +257,7 @@ fn card<'a>( .style(button::text) .into() } else { - pop(card) + sensor(card) .on_show(|_| Message::ImagePoppedIn(metadata.id)) .into() } diff --git a/examples/markdown/src/main.rs b/examples/markdown/src/main.rs index 98d19595..b7195055 100644 --- a/examples/markdown/src/main.rs +++ b/examples/markdown/src/main.rs @@ -6,7 +6,7 @@ use iced::highlighter; use iced::time::{self, Instant, milliseconds}; use iced::widget::{ self, button, center_x, container, horizontal_space, hover, image, - markdown, pop, right, row, scrollable, text_editor, toggler, + markdown, right, row, scrollable, sensor, text_editor, toggler, }; use iced::window; use iced::{ @@ -267,7 +267,7 @@ impl<'a> markdown::Viewer<'a, Message> for CustomViewer<'a> { ) .into() } else { - pop(horizontal_space()) + sensor(horizontal_space()) .key_ref(url.as_str()) .delay(milliseconds(500)) .on_show(|_size| Message::ImageShown(url.clone())) diff --git a/widget/src/helpers.rs b/widget/src/helpers.rs index 232cecd8..6815c3fc 100644 --- a/widget/src/helpers.rs +++ b/widget/src/helpers.rs @@ -25,7 +25,7 @@ use crate::text_input::{self, TextInput}; use crate::toggler::{self, Toggler}; use crate::tooltip::{self, Tooltip}; use crate::vertical_slider::{self, VerticalSlider}; -use crate::{Column, Grid, MouseArea, Pin, Pop, Row, Space, Stack, Themer}; +use crate::{Column, Grid, MouseArea, Pin, Row, Sensor, Space, Stack, Themer}; use std::borrow::Borrow; use std::ops::RangeInclusive; @@ -990,18 +990,20 @@ where }) } -/// Creates a new [`Pop`] widget. +/// Creates a new [`Sensor`] widget. +/// +/// A [`Sensor`] widget can generate messages when its contents are shown, +/// hidden, or resized. /// -/// A [`Pop`] widget can generate messages when it pops in and out of view. /// It can even notify you with anticipation at a given distance! -pub fn pop<'a, Message, Theme, Renderer>( +pub fn sensor<'a, Message, Theme, Renderer>( content: impl Into>, -) -> Pop<'a, (), Message, Theme, Renderer> +) -> Sensor<'a, (), Message, Theme, Renderer> where Renderer: core::Renderer, Message: Clone, { - Pop::new(content) + Sensor::new(content) } /// Creates a new [`Scrollable`] with the provided content. diff --git a/widget/src/lib.rs b/widget/src/lib.rs index 7c144ce2..d08a92f9 100644 --- a/widget/src/lib.rs +++ b/widget/src/lib.rs @@ -26,12 +26,12 @@ pub mod keyed; pub mod overlay; pub mod pane_grid; pub mod pick_list; -pub mod pop; pub mod progress_bar; pub mod radio; pub mod row; pub mod rule; pub mod scrollable; +pub mod sensor; pub mod slider; pub mod table; pub mod text; @@ -74,8 +74,6 @@ pub use pick_list::PickList; #[doc(no_inline)] pub use pin::Pin; #[doc(no_inline)] -pub use pop::Pop; -#[doc(no_inline)] pub use progress_bar::ProgressBar; #[doc(no_inline)] pub use radio::Radio; @@ -86,6 +84,8 @@ pub use rule::Rule; #[doc(no_inline)] pub use scrollable::Scrollable; #[doc(no_inline)] +pub use sensor::Sensor; +#[doc(no_inline)] pub use slider::Slider; #[doc(no_inline)] pub use space::Space; diff --git a/widget/src/pop.rs b/widget/src/sensor.rs similarity index 93% rename from widget/src/pop.rs rename to widget/src/sensor.rs index b580950c..ff5e6fd6 100644 --- a/widget/src/pop.rs +++ b/widget/src/sensor.rs @@ -16,7 +16,7 @@ use crate::core::{ /// /// It can even notify you with anticipation at a given distance! #[allow(missing_debug_implementations)] -pub struct Pop< +pub struct Sensor< 'a, Key, Message, @@ -32,12 +32,12 @@ pub struct Pop< delay: Duration, } -impl<'a, Message, Theme, Renderer> Pop<'a, (), Message, Theme, Renderer> +impl<'a, Message, Theme, Renderer> Sensor<'a, (), Message, Theme, Renderer> where Message: Clone, Renderer: core::Renderer, { - /// Creates a new [`Pop`] widget with the given content. + /// Creates a new [`Sensor`] widget with the given content. pub fn new( content: impl Into>, ) -> Self { @@ -53,7 +53,8 @@ where } } -impl<'a, Key, Message, Theme, Renderer> Pop<'a, Key, Message, Theme, Renderer> +impl<'a, Key, Message, Theme, Renderer> + Sensor<'a, Key, Message, Theme, Renderer> where Message: Clone, Key: self::Key, @@ -84,17 +85,17 @@ where self } - /// Sets the key of the [`Pop`] widget, for continuity. + /// Sets the key of the [`Sensor`] widget, for continuity. /// - /// If the key changes, the [`Pop`] widget will trigger again. + /// If the key changes, the [`Sensor`] widget will trigger again. pub fn key( self, key: K, - ) -> Pop<'a, impl self::Key, Message, Theme, Renderer> + ) -> Sensor<'a, impl self::Key, Message, Theme, Renderer> where K: Clone + PartialEq + 'static, { - Pop { + Sensor { content: self.content, key: OwnedKey(key), on_show: self.on_show, @@ -105,18 +106,18 @@ where } } - /// Sets the key of the [`Pop`] widget, for continuity; using a reference. + /// Sets the key of the [`Sensor`], for continuity; using a reference. /// - /// If the key changes, the [`Pop`] widget will trigger again. + /// If the key changes, the [`Sensor`] will trigger again. pub fn key_ref( self, key: &'a K, - ) -> Pop<'a, &'a K, Message, Theme, Renderer> + ) -> Sensor<'a, &'a K, Message, Theme, Renderer> where K: ToOwned + PartialEq + ?Sized, K::Owned: 'static, { - Pop { + Sensor { content: self.content, key, on_show: self.on_show, @@ -160,7 +161,7 @@ struct State { } impl Widget - for Pop<'_, Key, Message, Theme, Renderer> + for Sensor<'_, Key, Message, Theme, Renderer> where Key: self::Key, Message: Clone, @@ -368,7 +369,7 @@ where } impl<'a, Key, Message, Theme, Renderer> - From> + From> for Element<'a, Message, Theme, Renderer> where Message: Clone + 'a, @@ -376,7 +377,7 @@ where Renderer: core::Renderer + 'a, Theme: 'a, { - fn from(pop: Pop<'a, Key, Message, Theme, Renderer>) -> Self { + fn from(pop: Sensor<'a, Key, Message, Theme, Renderer>) -> Self { Element::new(pop) } }