Skip to content

Commit

Permalink
add mint functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jabuwu committed May 5, 2024
1 parent 4e5dbfd commit 649b94c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/path_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use crate::{
Bone, PathConstraintData, Slot,
};

#[cfg(feature = "mint")]
use mint::Vector2;

/// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#PathConstraint)
#[derive(Debug)]
pub struct PathConstraint {
Expand Down Expand Up @@ -106,3 +109,22 @@ impl PathConstraint {

c_ptr!(c_path_constraint, spPathConstraint);
}

/// Functions available if using the `mint` feature.
#[cfg(feature = "mint")]
impl PathConstraint {
#[must_use]
pub fn mix(&self) -> Vector2<f32> {
Vector2 {
x: self.mix_x(),
y: self.mix_y(),
}
}

#[must_use]
pub fn set_mix(&mut self, mix: impl Into<Vector2<f32>>) {
let mix: Vector2<f32> = mix.into();
self.set_mix_x(mix.x);
self.set_mix_y(mix.y);
}
}
41 changes: 39 additions & 2 deletions src/transform_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ use crate::{
Bone, TransformConstraintData,
};

#[cfg(feature = "mint")]
use mint::Vector2;

/// [Spine API Reference](https://esotericsoftware.com/spine-api-reference#TransformConstraint)
#[derive(Debug)]
pub struct TransformConstraint {
Expand Down Expand Up @@ -57,15 +60,15 @@ impl TransformConstraint {
/// A percentage (0-1) that controls the mix between the constrained and unconstrained
/// scale X.
mix_scale_x,
set_scale_x,
set_mix_scale_x,
mixScaleX,
f32
);
c_accessor_mut!(
/// A percentage (0-1) that controls the mix between the constrained and unconstrained
/// scale X.
mix_scale_y,
set_scale_y,
set_mix_scale_y,
mixScaleY,
f32
);
Expand Down Expand Up @@ -116,3 +119,37 @@ impl TransformConstraint {

c_ptr!(c_transform_constraint, spTransformConstraint);
}

/// Functions available if using the `mint` feature.
#[cfg(feature = "mint")]
impl TransformConstraint {
#[must_use]
pub fn mix_scale(&self) -> Vector2<f32> {
Vector2 {
x: self.mix_scale_x(),
y: self.mix_scale_y(),
}
}

#[must_use]
pub fn set_mix_scale(&mut self, mix_scale: impl Into<Vector2<f32>>) {
let mix_scale: Vector2<f32> = mix_scale.into();
self.set_mix_scale_x(mix_scale.x);
self.set_mix_scale_y(mix_scale.y);
}

#[must_use]
pub fn mix(&self) -> Vector2<f32> {
Vector2 {
x: self.mix_x(),
y: self.mix_y(),
}
}

#[must_use]
pub fn set_mix(&mut self, mix: impl Into<Vector2<f32>>) {
let mix: Vector2<f32> = mix.into();
self.set_mix_x(mix.x);
self.set_mix_y(mix.y);
}
}

0 comments on commit 649b94c

Please sign in to comment.