Skip to content

Commit

Permalink
feat: add set_handle method
Browse files Browse the repository at this point in the history
  • Loading branch information
edfloreshz committed Nov 25, 2024
1 parent a9c7c3c commit d623bb0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/widget/button/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ pub type Button<'a, Message> = Builder<'a, Message, Image<'a, Handle, Message>>;
/// A button constructed from an image handle, using image button styling.
pub fn image<'a, Message>(handle: impl Into<Handle> + 'a) -> Button<'a, Message> {
Button::new(Image {
image: widget::image(handle).border_radius([9.0; 4]),
image: widget::image::image(handle).border_radius([9.0; 4]),
selected: false,
on_remove: None,
})
}

/// The image variant of a button.
pub struct Image<'a, Handle, Message> {
image: widget::Image<'a, Handle>,
image: widget::image::Image<'a, Handle>,
selected: bool,
on_remove: Option<Message>,
}
Expand Down
19 changes: 19 additions & 0 deletions src/widget/image.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#[doc(inline)]
pub use iced::widget::{image, image::*, Image};

#[cfg(feature = "winit")]
use {
crate::app::Task,
iced_accessibility::Id,
iced_core::widget::operation,
iced_runtime::{task, Action},
};

#[cfg(feature = "winit")]
/// Produces a [`Task`] that sets a new [`Handle`] to the [`Image`] with the given [`Id`].
pub fn set_handle<Message: 'static>(id: Id, handle: impl Into<image::Handle>) -> Task<Message> {
task::effect(Action::widget(operation::image::set_handle(
id,
handle.into(),
)))
}
3 changes: 1 addition & 2 deletions src/widget/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ pub use iced::widget::{container, Container};
#[doc(inline)]
pub use iced::widget::{horizontal_space, vertical_space, Space};

#[doc(inline)]
pub use iced::widget::{image, Image};
pub mod image;

#[doc(inline)]
pub use iced::widget::{lazy, Lazy};
Expand Down

0 comments on commit d623bb0

Please sign in to comment.