Skip to content

Commit

Permalink
add custom svg origin. (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruffnext authored Jul 28, 2024
1 parent f2c6421 commit d8f3f44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/common/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fn keyboard_input_system(
Origin::Center => Origin::BottomLeft,
Origin::TopLeft => Origin::Center,
Origin::TopRight => Origin::TopLeft,
Origin::Custom(coord) => Origin::Custom(*coord)
}
}
} else if keyboard_input.just_pressed(KeyCode::KeyF) {
Expand Down
5 changes: 5 additions & 0 deletions src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum Origin {
TopLeft,
/// Top right of the image or viewbox.
TopRight,
/// Custom origin, top left is (0, 0), bottom right is (1, 1)
Custom((f32, f32)),
}

impl Origin {
Expand All @@ -44,6 +46,9 @@ impl Origin {
// Standard SVG origin is top left, so we don't need to do anything
Origin::TopLeft => Vec3::ZERO,
Origin::TopRight => Vec3::new(-scaled_size.x, 0.0, 0.0),
Origin::Custom(coord) => {
Vec3::new(-scaled_size.x * coord.0, scaled_size.y * coord.1, 0.0)
}
}
}
}
Expand Down

0 comments on commit d8f3f44

Please sign in to comment.