Added Sprite::sized(custom_size) (#14849)

# Objective
add a quick shorthand for creating a sprite with an custom size. This is
often desired when working with custom units or scaled sprites and
allows for a cleaner syntax in those cases/

## Solution

Implemented a `sized` function on the Sprite struct which creates a
Sprite, sets the custom size and leaves the rest at their default values

---

## Changelog

- Added `Sprite::sized(custom_size: Vec2)`
This commit is contained in:
Kees van Beilen 2024-08-21 14:24:16 +02:00 committed by GitHub
parent 6e2f96f222
commit 7499b74bbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,6 +31,16 @@ pub struct Sprite {
pub anchor: Anchor,
}
impl Sprite {
/// Create a Sprite with a custom size
pub fn sized(custom_size: Vec2) -> Self {
Sprite {
custom_size: Some(custom_size),
..Default::default()
}
}
}
/// Controls how the image is altered when scaled.
#[derive(Component, Debug, Clone, Reflect)]
#[reflect(Component)]