mirror of
https://github.com/danbulant/cushy
synced 2026-06-19 14:31:04 +00:00
ImageCornerRadius
In the end I think people might be surprised by the default behavior to clip corners, so I've opted to split this behavior into a separate component that defaults to no corner radius.
This commit is contained in:
parent
2ed140a0fe
commit
af208519eb
2 changed files with 25 additions and 6 deletions
|
|
@ -68,7 +68,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `WrapperWidget::activate`'s default implementation now activates the wrapped
|
||||
widget.
|
||||
- `Space` now intercepts mouse events if its color has a non-zero alpha channel.
|
||||
- `Image` now honors `CornerRadius`. Thanks to @danbulant for this change!
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
@ -230,6 +229,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `Scroll::preserve_max_scroll` controls whether the scroll view automatically
|
||||
scrolls when currently scrolled to the maximum and its child grows. The
|
||||
default is `true`, which was the behavior before this flag was added.
|
||||
- `Image` now supports `ImageCornerRadius`. Thanks to @danbulant for helping
|
||||
with this change!
|
||||
|
||||
|
||||
[139]: https://github.com/khonsulabs/cushy/issues/139
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
use figures::units::{Px, UPx};
|
||||
use figures::{FloatConversion, IntoSigned, IntoUnsigned, Point, Rect, ScreenScale, Size, Zero};
|
||||
use kludgine::shapes::Shape;
|
||||
use kludgine::{AnyTexture, CollectedTexture, Color, LazyTexture, SharedTexture, Texture, TextureRegion};
|
||||
use kludgine::shapes::{CornerRadii, 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::styles::Dimension;
|
||||
use crate::value::{IntoValue, Source, Value};
|
||||
use crate::widget::Widget;
|
||||
use crate::ConstraintLimit;
|
||||
|
|
@ -159,7 +161,7 @@ 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 = context.get(&ImageCornerRadius);
|
||||
let radii = radii.map(|r| r.into_px(context.gfx.scale()));
|
||||
|
||||
self.contents.map(|texture| {
|
||||
|
|
@ -167,7 +169,16 @@ impl Widget for Image {
|
|||
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);
|
||||
context.gfx.draw_textured_shape(
|
||||
&Shape::textured_round_rect(
|
||||
rect,
|
||||
radii,
|
||||
Rect::from(texture.size()),
|
||||
Color::WHITE,
|
||||
),
|
||||
texture,
|
||||
opacity,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -254,3 +265,10 @@ pub enum Aspect {
|
|||
/// size it can be to cover the entire surface.
|
||||
Fill,
|
||||
}
|
||||
|
||||
define_components! {
|
||||
Image {
|
||||
/// The corner radius to use to clip when rendering an [`Image`].
|
||||
ImageCornerRadius(CornerRadii<Dimension>, "corner_radius", CornerRadii::ZERO)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue