pub struct TilesetBuilder { /* private fields */ }Expand description
Builder for TilesetOptions.
Construct via TilesetOptions::builder.
columns defaults to image_width / tile_width,
so you usually don’t need to set it explicitly. codepage
defaults to Codepage::Cp437.
§Examples
Standard CP437 tileset:
use retroglyph_window::tileset::TilesetOptions;
let png: Vec<u8> = std::fs::read("assets/cp437_16x16.png").unwrap();
let opts = TilesetOptions::builder(png)
.tile_size(16, 16) // codepage defaults to Cp437
.build()
.unwrap();Private-use sprite sheet addressed by index, centred in whatever box a span reserves:
use retroglyph_window::tileset::{Codepage, SpriteAlign, TilesetOptions};
let png: Vec<u8> = std::fs::read("assets/sprites.png").unwrap();
let opts = TilesetOptions::builder(png)
.tile_size(32, 32)
.codepage(Codepage::Identity) // tile 0 = '\0', tile 1 = '\x01', …
.align(SpriteAlign::Center)
.build()
.unwrap();How many cells a sprite occupies is a per-write decision, not a tileset-wide one: declare it
with Surface::put_span at the draw call.
Unicode private-use area sprite sheet:
use retroglyph_window::tileset::TilesetOptions;
let png: Vec<u8> = std::fs::read("assets/monsters.png").unwrap();
let opts = TilesetOptions::builder(png)
.tile_size(16, 16)
.start_codepoint('\u{E000}') // maps to Unicode PUA starting at U+E000
.build()
.unwrap();Implementations§
Source§impl TilesetBuilder
impl TilesetBuilder
Sourcepub const fn tile_size(self, width: u16, height: u16) -> TilesetBuilder
pub const fn tile_size(self, width: u16, height: u16) -> TilesetBuilder
Sets the pixel dimensions of each tile.
Sourcepub const fn columns(self, cols: u16) -> TilesetBuilder
pub const fn columns(self, cols: u16) -> TilesetBuilder
Sets the number of tiles per row in the sprite sheet.
Useful for sheets with padding. If not set, derived from image width.
Sourcepub fn codepage(self, codepage: Codepage) -> TilesetBuilder
pub fn codepage(self, codepage: Codepage) -> TilesetBuilder
Sets the codepoint mapping.
Sourcepub fn start_codepoint(self, start: char) -> TilesetBuilder
pub fn start_codepoint(self, start: char) -> TilesetBuilder
Sets the codepoint of the first tile; subsequent tiles increment by 1.
Shorthand for codepage(Codepage::Unicode { start }).
Sourcepub const fn align(self, align: SpriteAlign) -> TilesetBuilder
pub const fn align(self, align: SpriteAlign) -> TilesetBuilder
Sets where each sprite sits inside the multi-cell box a span reserves for it.
Defaults to SpriteAlign::TopLeft. Has no visible effect on a sprite whose art fills
its box exactly; see SpriteAlign.
Sourcepub const fn color(self, color: SheetColor) -> TilesetBuilder
pub const fn color(self, color: SheetColor) -> TilesetBuilder
Declares what this sheet’s pixels mean, and so whether the cell’s foreground color colors them.
Defaults to SheetColor::Art: composited verbatim. See SheetColor.
Sourcepub const fn mask(self) -> TilesetBuilder
pub const fn mask(self) -> TilesetBuilder
Shorthand for color(SheetColor::Mask): this sheet is white-on-
transparent artwork to be colored by each cell’s foreground.
Sourcepub const fn transparent_color(self, r: u8, g: u8, b: u8) -> TilesetBuilder
pub const fn transparent_color(self, r: u8, g: u8, b: u8) -> TilesetBuilder
Pixels matching (r, g, b) are made fully transparent (alpha = 0).
Use this for spritesheets that use a solid colour background instead of an alpha channel.
Sourcepub fn build(self) -> Result<TilesetOptions, TilesetError>
pub fn build(self) -> Result<TilesetOptions, TilesetError>
Validates and builds TilesetOptions.
§Errors
Returns TilesetError::ZeroTileSize if tile dimensions are 0, or
TilesetError::EmptyCodepage if Custom codepage is empty.
Auto Trait Implementations§
impl Freeze for TilesetBuilder
impl RefUnwindSafe for TilesetBuilder
impl Send for TilesetBuilder
impl Sync for TilesetBuilder
impl Unpin for TilesetBuilder
impl UnsafeUnpin for TilesetBuilder
impl UnwindSafe for TilesetBuilder
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
§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.