Add Image::sense to let an image respond to clicks and drags
This commit is contained in:
parent
03721dbfd8
commit
d862ff66ac
1 changed files with 12 additions and 1 deletions
|
@ -20,6 +20,7 @@ pub struct Image {
|
|||
size: Vec2,
|
||||
bg_fill: Color32,
|
||||
tint: Color32,
|
||||
sense: Sense,
|
||||
}
|
||||
|
||||
impl Image {
|
||||
|
@ -30,6 +31,7 @@ impl Image {
|
|||
size: size.into(),
|
||||
bg_fill: Default::default(),
|
||||
tint: Color32::WHITE,
|
||||
sense: Sense::hover(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -65,6 +75,7 @@ impl Image {
|
|||
size: _,
|
||||
bg_fill,
|
||||
tint,
|
||||
sense: _,
|
||||
} = self;
|
||||
|
||||
if *bg_fill != Default::default() {
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue