diff --git a/src/widgets/image.rs b/src/widgets/image.rs index 004498a47..3981cf362 100644 --- a/src/widgets/image.rs +++ b/src/widgets/image.rs @@ -1,11 +1,13 @@ //! A widget that displays an image/texture. use figures::units::{Px, UPx}; -use figures::{FloatConversion, IntoSigned, IntoUnsigned, Point, Rect, Size, Zero}; -use kludgine::{AnyTexture, CollectedTexture, LazyTexture, SharedTexture, Texture, TextureRegion}; +use figures::{FloatConversion, IntoSigned, IntoUnsigned, Point, Rect, ScreenScale, Size, Zero}; +use kludgine::shapes::Shape; +use kludgine::{AnyTexture, CollectedTexture, Color, LazyTexture, SharedTexture, Texture, TextureRegion}; use crate::animation::ZeroToOne; use crate::context::{LayoutContext, Trackable}; +use crate::styles::components::CornerRadius; use crate::value::{IntoValue, Source, Value}; use crate::widget::Widget; use crate::ConstraintLimit; @@ -157,9 +159,16 @@ impl Widget for Image { fn redraw(&mut self, context: &mut crate::context::GraphicsContext<'_, '_, '_, '_>) { self.contents.invalidate_when_changed(context); let opacity = self.opacity.get_tracking_redraw(context); + let radii = context.get(&CornerRadius); + let radii = radii.map(|r| r.into_px(context.gfx.scale())); + self.contents.map(|texture| { let rect = self.calculate_image_rect(texture, context.gfx.size(), context); - context.gfx.draw_texture(texture, rect, opacity); + if radii.is_zero() { + context.gfx.draw_texture(texture, rect, opacity); + } else { + context.gfx.draw_textured_shape(&Shape::textured_round_rect(rect, radii, Rect::from(texture.size()), Color::WHITE), texture, opacity); + } }); }