Skip to content

Commit

Permalink
Add Image::sense to let an image respond to clicks and drags
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed May 6, 2021
1 parent 03721db commit d862ff6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion egui/src/widgets/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Image {
size: Vec2,
bg_fill: Color32,
tint: Color32,
sense: Sense,
}

impl Image {
Expand All @@ -30,6 +31,7 @@ impl Image {
size: size.into(),
bg_fill: Default::default(),
tint: Color32::WHITE,
sense: Sense::hover(),
}
}

Expand All @@ -50,6 +52,14 @@ impl Image {
self.tint = tint.into();
self
}

/// Make the image respond to clicks and/or drags.
///
/// Consider using [`ImageButton`] instead, for an on-hover effect.
pub fn sense(mut self, sense: Sense) -> Self {
self.sense = sense;
self
}
}

impl Image {
Expand All @@ -65,6 +75,7 @@ impl Image {
size: _,
bg_fill,
tint,
sense: _,
} = self;

if *bg_fill != Default::default() {
Expand All @@ -84,7 +95,7 @@ impl Image {

impl Widget for Image {
fn ui(self, ui: &mut Ui) -> Response {
let (rect, response) = ui.allocate_exact_size(self.size, Sense::hover());
let (rect, response) = ui.allocate_exact_size(self.size, self.sense);
self.paint_at(ui, rect);
response
}
Expand Down

0 comments on commit d862ff6

Please sign in to comment.