Skip to main content

SpriteAlign

Enum SpriteAlign 

Source
#[non_exhaustive]
pub enum SpriteAlign { TopLeft, Top, TopRight, Left, Center, Right, BottomLeft, Bottom, BottomRight, }
Available on crate feature tilesets only.
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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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));
Source

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

Source§

fn clone(&self) -> SpriteAlign

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SpriteAlign

Source§

impl Debug for SpriteAlign

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SpriteAlign

Source§

fn default() -> SpriteAlign

Returns the “default value” for a type. Read more
Source§

impl Eq for SpriteAlign

Source§

impl PartialEq for SpriteAlign

Source§

fn eq(&self, other: &SpriteAlign) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SpriteAlign

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<C> WithAlpha for C
where C: Copy,

Source§

fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>

Wraps self with alpha, storing alpha before the color in memory (see AlphaFirst).
Source§

fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>

Wraps self with alpha, storing alpha after the color in memory (see AlphaLast).
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more