Rename pop widget to sensor 📡

This commit is contained in:
Héctor Ramón Jiménez 2025-08-02 22:57:09 +02:00
parent c46600a69a
commit 57c628839a
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
5 changed files with 31 additions and 28 deletions

View file

@ -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()
}

View file

@ -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()))

View file

@ -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<Element<'a, Message, Theme, Renderer>>,
) -> 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.

View file

@ -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;

View file

@ -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<Element<'a, Message, Theme, Renderer>>,
) -> 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<K>(
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<K>(
self,
key: &'a K,
) -> Pop<'a, &'a K, Message, Theme, Renderer>
) -> Sensor<'a, &'a K, Message, Theme, Renderer>
where
K: ToOwned + PartialEq<K::Owned> + ?Sized,
K::Owned: 'static,
{
Pop {
Sensor {
content: self.content,
key,
on_show: self.on_show,
@ -160,7 +161,7 @@ struct State<Key> {
}
impl<Key, Message, Theme, Renderer> Widget<Message, Theme, Renderer>
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<Pop<'a, Key, Message, Theme, Renderer>>
From<Sensor<'a, Key, Message, Theme, Renderer>>
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)
}
}