-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proportional scaling for the sprite's texture. #17258
Changes from 4 commits
cc47c93
baf755f
296174f
22879d4
2672332
1a8fa2a
dbfa421
6fda406
954fead
bea348f
bf1b769
a876f00
837e0f7
9a2329e
75176c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -162,6 +162,9 @@ pub enum SpriteImageMode { | |||||
/// The sprite will take on the size of the image by default, and will be stretched or shrunk if [`Sprite::custom_size`] is set. | ||||||
#[default] | ||||||
Auto, | ||||||
/// The texture will be scaled to fit the rect bounds defined in [`Sprite::custom_size`]. | ||||||
/// Otherwise no scaling will be applied. | ||||||
ScaleMode(TextureScale), | ||||||
alice-i-cecile marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/// The texture will be cut in 9 slices, keeping the texture in proportions on resize | ||||||
Sliced(TextureSlicer), | ||||||
/// The texture will be repeated if stretched beyond `stretched_value` | ||||||
|
@@ -185,6 +188,49 @@ impl SpriteImageMode { | |||||
SpriteImageMode::Sliced(..) | SpriteImageMode::Tiled { .. } | ||||||
) | ||||||
} | ||||||
|
||||||
/// Returns [`TextureScale`] if scale is presented or [`Option::None`] otherwise | ||||||
#[inline] | ||||||
#[must_use] | ||||||
pub const fn scale(&self) -> Option<TextureScale> { | ||||||
if let SpriteImageMode::ScaleMode(scale) = self { | ||||||
Some(*scale) | ||||||
} else { | ||||||
None | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/// Represents various modes for proportional scaling of a texture | ||||||
alice-i-cecile marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Default, Reflect)] | ||||||
#[reflect(Debug)] | ||||||
pub enum TextureScale { | ||||||
/// Scale the texture uniformly (maintain the texture's aspect ratio) | ||||||
/// so that both dimensions (width and height) of the texture will be equal | ||||||
/// to or larger than the corresponding dimension of the rect. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you mean the |
||||||
/// Fill rect with a centered texture. | ||||||
#[default] | ||||||
FillCenter, | ||||||
/// Scale the texture to fill the rect with a start of the texture, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This isn't really very clear about what the "start" of the texture is. |
||||||
/// maintaining the aspect ratio. | ||||||
FillStart, | ||||||
/// Scale the texture to fill the rect with a end of the texture, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// maintaining the aspect ratio. | ||||||
FillEnd, | ||||||
/// Scaling the texture will maintain the original aspect ratio | ||||||
/// and ensure that the original texture fits entirely inside the rect. | ||||||
/// At least one axis (X or Y) will fit exactly. The result is centered inside the rect. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
FitCenter, | ||||||
/// Scaling the texture will maintain the original aspect ratio | ||||||
/// and ensure that the original texture fits entirely inside rect. | ||||||
/// At least one axis (X or Y) will fit exactly. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// Aligns the result to the left and top edges of rect. | ||||||
FitStart, | ||||||
/// Scaling the texture will maintain the original aspect ratio | ||||||
/// and ensure that the original texture fits entirely inside rect. | ||||||
/// At least one axis (X or Y) will fit exactly. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
/// Aligns the result to the right and bottom edges of rect. | ||||||
FitEnd, | ||||||
} | ||||||
|
||||||
/// How a sprite is positioned relative to its [`Transform`]. | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.