mirror of
https://github.com/danbulant/cushy
synced 2026-05-22 21:59:02 +00:00
Merge pull request #174 from danbulant/image-corner-radii
Make images respect border radii
This commit is contained in:
commit
223989410d
1 changed files with 12 additions and 3 deletions
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue