Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Text in SVG `<text>` elements now rendered in PNG sprites (see [#102])
- Support loading SVG files compressed with gzip (`*.svgz`; see [#107])
- Propagate errors in `get_svg_input_paths` (see [#108])
- Use consuming builder pattern for `SpritesheetBuilder` (see [#109])
- Update Oxipng dependency from v9 to v10 (see [#106])
- Update thiserror dependency from v1 to v2 (see [#106])

Expand All @@ -14,6 +15,7 @@ The minimum supported version of Rust is now 1.85.1 (released March 2025).
[#106]: https://github.com/flother/spreet/pull/106
[#107]: https://github.com/flother/spreet/pull/107
[#108]: https://github.com/flother/spreet/pull/108
[#109]: https://github.com/flother/spreet/pull/109

## v0.13.1 (2025-12-24)

Expand Down
12 changes: 5 additions & 7 deletions src/bin/spreet/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ fn main() {
std::process::exit(exitcode::NOINPUT);
}

let mut spritesheet_builder = Spritesheet::build();
spritesheet_builder.sprites(sprites);
spritesheet_builder.spacing(args.spacing);
let mut spritesheet_builder = Spritesheet::build().sprites(sprites).spacing(args.spacing);
if args.unique {
spritesheet_builder.make_unique();
};
spritesheet_builder = spritesheet_builder.make_unique();
}
if args.sdf {
spritesheet_builder.make_sdf();
};
spritesheet_builder = spritesheet_builder.make_sdf();
}

// Generate sprite sheet
let Some(spritesheet) = spritesheet_builder.generate() else {
Expand Down
9 changes: 5 additions & 4 deletions src/sprite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl SpriteDescription {
/// Builder pattern for `Spritesheet`: construct a `Spritesheet` object using calls to a builder
/// helper.
#[derive(Default, Clone)]
#[must_use = "builder does nothing unless you call .generate()"]
pub struct SpritesheetBuilder {
sprites: Option<BTreeMap<String, Sprite>>,
references: Option<MultiMap<String, String>>,
Expand All @@ -328,20 +329,20 @@ impl SpritesheetBuilder {
}
}

pub fn sprites(&mut self, sprites: BTreeMap<String, Sprite>) -> &mut Self {
pub fn sprites(mut self, sprites: BTreeMap<String, Sprite>) -> Self {
self.sprites = Some(sprites);
self
}

/// Set the spacing (in pixels) to add to the right and bottom of each sprite.
pub fn spacing(&mut self, spacing: u8) -> &mut Self {
pub fn spacing(mut self, spacing: u8) -> Self {
self.spacing = spacing;
self
}

// Remove any duplicate sprites from the spritesheet's sprites. This is used to let spritesheets
// include only unique sprites, with multiple references to the same sprite in the index file.
pub fn make_unique(&mut self) -> &mut Self {
pub fn make_unique(mut self) -> Self {
match self.sprites.take() {
Some(sprites) => {
let mut unique_sprites = BTreeMap::new();
Expand Down Expand Up @@ -373,7 +374,7 @@ impl SpritesheetBuilder {
///
/// You have to ensure that the sprites are created as an SDF file beforehand. See
/// [`Sprite::new_sdf`] for further context.
pub fn make_sdf(&mut self) -> &mut Self {
pub fn make_sdf(mut self) -> Self {
self.sdf = true;
self
}
Expand Down