Skip to content

Commit

Permalink
BackgroundColor support (#97)
Browse files Browse the repository at this point in the history
Added background color support, mainly for opacity.

Co-authored-by: Jerome Humbert <djeedai@gmail.com>
  • Loading branch information
Sjael and djeedai authored Oct 28, 2023
1 parent bc12d36 commit 54ea432
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Added built-in support for the `BackgroundColor` bevy component, under the `bevy_ui` feature.

## [0.8.0] - 2023-07-12

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ The naming scheme for predefined lenses is `"<TargetName><FieldName>Lens"`, wher
| | [`scale`](https://docs.rs/bevy/0.11.0/bevy/transform/components/struct.Transform.html#structfield.scale) | [`TransformScaleLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/lens/struct.TransformScaleLens.html) | |
| [`Sprite`](https://docs.rs/bevy/0.11.0/bevy/sprite/struct.Sprite.html) | [`color`](https://docs.rs/bevy/0.11.0/bevy/sprite/struct.Sprite.html#structfield.color) | [`SpriteColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/lens/struct.SpriteColorLens.html) | `bevy_sprite` |
| [`Style`](https://docs.rs/bevy/0.11.0/bevy/ui/struct.Style.html) | [`position`](https://docs.rs/bevy/0.11.0/bevy/ui/struct.Style.html#structfield.position) | [`UiPositionLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/lens/struct.UiPositionLens.html) | `bevy_ui` |
| [`BackgroundColor`](https://docs.rs/bevy/0.11.0/bevy/ui/struct.BackgroundColor.html)| | [`UiBackgroundColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/lens/struct.UiBackgroundColorLens.html) | `bevy_ui` |
| [`Text`](https://docs.rs/bevy/0.11.0/bevy/text/struct.Text.html) | [`TextStyle::color`](https://docs.rs/bevy/0.11.0/bevy/text/struct.TextStyle.html#structfield.color) | [`TextColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/lens/struct.TextColorLens.html) | `bevy_text` |

¹ Shortest-path interpolation between two rotations, using `Quat::slerp()`.
Expand Down
21 changes: 21 additions & 0 deletions src/lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,27 @@ impl Lens<Style> for UiPositionLens {
}
}

/// Gamer
#[cfg(feature = "bevy_ui")]
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct UiBackgroundColorLens {
/// Start position.
pub start: Color,
/// End position.
pub end: Color,
}


#[cfg(feature = "bevy_ui")]
impl Lens<BackgroundColor> for UiBackgroundColorLens {
fn lerp(&mut self, target: &mut BackgroundColor, ratio: f32) {
let start: Vec4 = self.start.into();
let end: Vec4 = self.end.into();
let value = start.lerp(end, ratio);
target.0 = value.into();
}
}

/// A lens to manipulate the [`color`] field of a [`ColorMaterial`] asset.
///
/// [`color`]: https://docs.rs/bevy/0.11.0/bevy/sprite/struct.ColorMaterial.html#structfield.color
Expand Down
5 changes: 5 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ impl Plugin for TweeningPlugin {
Update,
component_animator_system::<Style>.in_set(AnimationSystem::AnimationUpdate),
);
#[cfg(feature = "bevy_ui")]
app.add_systems(
Update,
component_animator_system::<BackgroundColor>.in_set(AnimationSystem::AnimationUpdate),
);

#[cfg(feature = "bevy_sprite")]
app.add_systems(
Expand Down

0 comments on commit 54ea432

Please sign in to comment.