diff --git a/core/src/theme.rs b/core/src/theme.rs index 6b2c04da4f..9aacbc920a 100644 --- a/core/src/theme.rs +++ b/core/src/theme.rs @@ -89,6 +89,11 @@ impl Theme { Self::custom_with_fn(name, palette, palette::Extended::generate) } + /// Creates a new custom [`Theme`] from the given [`Palette`] and a custom [`palette::Extended`] palette + pub fn custom_with_extended(name: String, palette: Palette, extended: palette::Extended) -> Self { + Self::Custom(Arc::new(Custom::new_with_extended(name, palette, extended))) + } + /// Creates a new custom [`Theme`] from the given [`Palette`], with /// a custom generator of a [`palette::Extended`]. pub fn custom_with_fn( @@ -226,6 +231,15 @@ impl Custom { Self::with_fn(name, palette, palette::Extended::generate) } + /// Creates a [`Custom`] theme from the given [`Palette`] and a custom [`palette::Extended`] palette + pub fn new_with_extended(name: String, palette: Palette, extended: palette::Extended) -> Self { + Self { + name, + palette, + extended, + } + } + /// Creates a [`Custom`] theme from the given [`Palette`] with /// a custom generator of a [`palette::Extended`]. pub fn with_fn( diff --git a/widget/src/mouse_area.rs b/widget/src/mouse_area.rs index d7235cf602..cee2023a6a 100644 --- a/widget/src/mouse_area.rs +++ b/widget/src/mouse_area.rs @@ -1,6 +1,7 @@ //! A container for capturing mouse events. use iced_renderer::core::Point; +use iced_runtime::core::mouse::ScrollDelta; use crate::core::event::{self, Event}; use crate::core::layout; @@ -28,6 +29,7 @@ pub struct MouseArea< on_right_release: Option, on_middle_press: Option, on_middle_release: Option, + on_scroll: Option Message + 'a>>, on_enter: Option, on_move: Option Message>>, on_exit: Option, @@ -77,6 +79,16 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> { self } + /// The message to emit when scroll wheel is used + #[must_use] + pub fn on_scroll(mut self, build_message: F) -> Self + where + F: Fn(ScrollDelta) -> Message + 'static, + { + self.on_scroll = Some(Box::new(build_message)); + self + } + /// The message to emit when the mouse enters the area. #[must_use] pub fn on_enter(mut self, message: Message) -> Self { @@ -128,6 +140,7 @@ impl<'a, Message, Theme, Renderer> MouseArea<'a, Message, Theme, Renderer> { on_right_release: None, on_middle_press: None, on_middle_release: None, + on_scroll: None, on_enter: None, on_move: None, on_exit: None, @@ -397,5 +410,13 @@ fn update( } } + if let Some(message) = widget.on_scroll.as_ref() { + if let Event::Mouse(mouse::Event::WheelScrolled { delta }) = event { + shell.publish(message(delta)); + + return event::Status::Captured; + } + } + event::Status::Ignored }