#[non_exhaustive]pub enum SpriteAlign {
TopLeft,
Top,
TopRight,
Left,
Center,
Right,
BottomLeft,
Bottom,
BottomRight,
}Expand description
Where a sprite sits inside the multi-cell box a span reserves for it.
Geometry only: alignment moves a sprite’s pixels, it never changes their color. See
TilesetOptions for how a sprite’s color relates to the cell’s style.
Only observable when the reserved box is larger than the sprite’s own pixels, i.e. when
Surface::put_span declares more cells than the
artwork fills. A sprite drawn into a box its art exactly fills (the common case) renders
identically under every variant. Mirrors BearLibTerminal’s tileset align= option.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
TopLeft
Flush with the box’s top-left corner.
Top
Centred horizontally, flush with the top edge.
TopRight
Flush with the top-right corner.
Left
Flush with the left edge, centred vertically.
Center
Centred on both axes.
Right
Flush with the right edge, centred vertically.
BottomLeft
Flush with the bottom-left corner.
Bottom
Centred horizontally, flush with the bottom edge.
BottomRight
Flush with the bottom-right corner.
Implementations§
Source§impl SpriteAlign
impl SpriteAlign
Sourcepub const fn offset(
self,
sprite_w: u32,
sprite_h: u32,
box_w: u32,
box_h: u32,
) -> (i16, i16)
pub const fn offset( self, sprite_w: u32, sprite_h: u32, box_w: u32, box_h: u32, ) -> (i16, i16)
Returns the offset of a sprite_w x sprite_h sprite placed inside a box_w x box_h
box, in unscaled pixels to match Tile::dx.
Centring uses integer division, so an odd leftover pixel lands on the right/bottom side.
Saturates at 0 on either axis where the sprite is at least as large as the box, so an
oversized sprite is never pulled off its own anchor cell.
§Examples
use retroglyph_window::tileset::SpriteAlign;
// 16x16 art in a 32x32 box leaves 16 pixels of slack on each axis.
assert_eq!(SpriteAlign::Center.offset(16, 16, 32, 32), (8, 8));
assert_eq!(SpriteAlign::BottomRight.offset(16, 16, 32, 32), (16, 16));
// Art that fills its box renders identically under every variant.
assert_eq!(SpriteAlign::Center.offset(16, 16, 16, 16), (0, 0));Sourcepub const fn offset_in_span(
self,
sprite_w: u32,
sprite_h: u32,
span_w: u16,
span_h: u16,
glyph_w: u8,
glyph_h: u8,
) -> (i16, i16)
pub const fn offset_in_span( self, sprite_w: u32, sprite_h: u32, span_w: u16, span_h: u16, glyph_w: u8, glyph_h: u8, ) -> (i16, i16)
Returns the offset of a sprite_w x sprite_h sprite inside the box a span_w x
span_h span of glyph_w x glyph_h cells reserves for it, in unscaled pixels.
span_w/span_h come from Tile::span and glyph_w/
glyph_h are the unscaled cell size, so the box is span_w * glyph_w x span_h * glyph_h pixels. A zero cell size is treated as one pixel, leaving the sprite on its
anchor rather than offsetting it by a meaningless amount.
Trait Implementations§
Source§impl Clone for SpriteAlign
impl Clone for SpriteAlign
Source§fn clone(&self) -> SpriteAlign
fn clone(&self) -> SpriteAlign
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SpriteAlign
impl Debug for SpriteAlign
Source§impl Default for SpriteAlign
impl Default for SpriteAlign
Source§fn default() -> SpriteAlign
fn default() -> SpriteAlign
Source§impl PartialEq for SpriteAlign
impl PartialEq for SpriteAlign
Source§fn eq(&self, other: &SpriteAlign) -> bool
fn eq(&self, other: &SpriteAlign) -> bool
self and other values to be equal, and is used by ==.impl Copy for SpriteAlign
impl Eq for SpriteAlign
impl StructuralPartialEq for SpriteAlign
Auto Trait Implementations§
impl Freeze for SpriteAlign
impl RefUnwindSafe for SpriteAlign
impl Send for SpriteAlign
impl Sync for SpriteAlign
impl Unpin for SpriteAlign
impl UnsafeUnpin for SpriteAlign
impl UnwindSafe for SpriteAlign
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).