Browse Source

Add Painter::image convenience function

pull/2110/head
Emil Ernerfeldt 2 years ago
parent
commit
dd67f3631f
  1. 10
      crates/egui/src/painter.rs
  2. 6
      crates/epaint/src/shape.rs

10
crates/egui/src/painter.rs

@ -352,6 +352,16 @@ impl Painter {
self.line_segment([tip, tip - tip_length * (rot * dir)], stroke);
self.line_segment([tip, tip - tip_length * (rot.inverse() * dir)], stroke);
}
/// An image at the given position.
///
/// `uv` should normally be `Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0))`
/// unless you want to crop or flip the image.
///
/// `tint` is a color multiplier. Use [`Color32::WHITE`] if you don't want to tint the image.
pub fn image(&self, texture_id: epaint::TextureId, rect: Rect, uv: Rect, tint: Color32) {
self.add(Shape::image(texture_id, rect, uv, tint));
}
}
/// ## Text

6
crates/epaint/src/shape.rs

@ -233,6 +233,12 @@ impl Shape {
Self::Mesh(mesh)
}
/// An image at the given position.
///
/// `uv` should normally be `Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0))`
/// unless you want to crop or flip the image.
///
/// `tint` is a color multiplier. Use [`Color32::WHITE`] if you don't want to tint the image.
pub fn image(texture_id: TextureId, rect: Rect, uv: Rect, tint: Color32) -> Self {
let mut mesh = Mesh::with_texture(texture_id);
mesh.add_rect_with_uv(rect, uv, tint);

Loading…
Cancel
Save