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,
|
size: Vec2,
|
||||||
bg_fill: Color32,
|
bg_fill: Color32,
|
||||||
tint: Color32,
|
tint: Color32,
|
||||||
|
sense: Sense,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
|
@ -30,6 +31,7 @@ impl Image {
|
||||||
size: size.into(),
|
size: size.into(),
|
||||||
bg_fill: Default::default(),
|
bg_fill: Default::default(),
|
||||||
tint: Color32::WHITE,
|
tint: Color32::WHITE,
|
||||||
|
sense: Sense::hover(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +52,14 @@ impl Image {
|
||||||
self.tint = tint.into();
|
self.tint = tint.into();
|
||||||
self
|
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 {
|
impl Image {
|
||||||
|
@ -65,6 +75,7 @@ impl Image {
|
||||||
size: _,
|
size: _,
|
||||||
bg_fill,
|
bg_fill,
|
||||||
tint,
|
tint,
|
||||||
|
sense: _,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
if *bg_fill != Default::default() {
|
if *bg_fill != Default::default() {
|
||||||
|
@ -84,7 +95,7 @@ impl Image {
|
||||||
|
|
||||||
impl Widget for Image {
|
impl Widget for Image {
|
||||||
fn ui(self, ui: &mut Ui) -> Response {
|
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);
|
self.paint_at(ui, rect);
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue