Skip to content
Snippets Groups Projects
Unverified Commit f3d614a5 authored by Jerome Humbert's avatar Jerome Humbert Committed by GitHub
Browse files

Move `TextColorLens` under a new `bevy_text` feat. (#70)

Add a new `bevy_text` feature for more granular control over
`Text`-related lenses, and change the `TextColorLens` to require that
new feature instead of `bevy_ui`, as texts _can_ be used without the
Bevy UI crate.

Fixes #68
parent d295b91c
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,10 @@ jobs: ...@@ -56,6 +56,10 @@ jobs:
run: cargo test --no-default-features --features="bevy_sprite" run: cargo test --no-default-features --features="bevy_sprite"
env: env:
CARGO_INCREMENTAL: 1 CARGO_INCREMENTAL: 1
- name: Build & run tests (text)
run: cargo test --no-default-features --features="bevy_text"
env:
CARGO_INCREMENTAL: 1
- name: Build & run tests (asset) - name: Build & run tests (asset)
run: cargo test --no-default-features --features="bevy_asset" run: cargo test --no-default-features --features="bevy_asset"
env: env:
......
...@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `with_repeat_count()` and `with_repeat_strategy()` builder methods to `Tween<T>`. - Added `with_repeat_count()` and `with_repeat_strategy()` builder methods to `Tween<T>`.
- Added a `speed()` getter on `Animator<T>` and `AssetAnimator<T>`. - Added a `speed()` getter on `Animator<T>` and `AssetAnimator<T>`.
- Added `set_elapsed(Duration)` and `elapsed() -> Duration` to the `Tweenable<T>` trait. Those methods are preferable over `set_progress()` and `progress()` as they avoid the conversion to floating-point values and any rounding errors. - Added `set_elapsed(Duration)` and `elapsed() -> Duration` to the `Tweenable<T>` trait. Those methods are preferable over `set_progress()` and `progress()` as they avoid the conversion to floating-point values and any rounding errors.
- Added a new `bevy_text` feature for `Text`-related built-in lenses.
### Changed ### Changed
...@@ -18,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -18,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Animators now always have a tween (instead of it being optional). This means the default animator implementation was removed. - Animators now always have a tween (instead of it being optional). This means the default animator implementation was removed.
- `Delay::new()` now panics if the `duration` is zero. This prevents creating no-op `Delay` objects, and avoids an internal edge case producing wrong results. - `Delay::new()` now panics if the `duration` is zero. This prevents creating no-op `Delay` objects, and avoids an internal edge case producing wrong results.
- Tweens moving to `TweenState::Completed` are now guaranteed to freeze their state. In particular, this means that their direction will not flip at the end of the last loop if their repeat strategy is `RepeatStrategy::MirroredRepeat`. - Tweens moving to `TweenState::Completed` are now guaranteed to freeze their state. In particular, this means that their direction will not flip at the end of the last loop if their repeat strategy is `RepeatStrategy::MirroredRepeat`.
- Moved the `TextColorLens` lens from the `bevy_ui` feature to the new `bevy_text` one, to allow using it without the Bevy UI crate.
### Removed ### Removed
......
[package] [package]
name = "bevy_tweening" name = "bevy_tweening"
version = "0.5.0" version = "0.5.1"
authors = ["François Mockers <mockersf@gmail.com>", "Jerome Humbert <djeedai@gmail.com>"] authors = ["François Mockers <mockersf@gmail.com>", "Jerome Humbert <djeedai@gmail.com>"]
edition = "2021" edition = "2021"
description = "Tweening animation plugin for the Bevy game engine" description = "Tweening animation plugin for the Bevy game engine"
...@@ -13,13 +13,15 @@ readme = "README.md" ...@@ -13,13 +13,15 @@ readme = "README.md"
exclude = ["examples/*.gif", ".github", "release.md"] exclude = ["examples/*.gif", ".github", "release.md"]
[features] [features]
default = ["bevy_sprite", "bevy_ui", "bevy_asset"] default = ["bevy_sprite", "bevy_ui", "bevy_asset", "bevy_text"]
# Enable support for Asset animation # Enable support for Asset animation
bevy_asset = ["bevy/bevy_asset"] bevy_asset = ["bevy/bevy_asset"]
# Enable built-in lenses for Bevy sprites # Enable built-in lenses for Bevy sprites
bevy_sprite = ["bevy/bevy_sprite", "bevy/bevy_render"] bevy_sprite = ["bevy/bevy_sprite", "bevy/bevy_render"]
# Enable built-in lenses for Bevy UI # Enable built-in lenses for Bevy UI
bevy_ui = ["bevy/bevy_ui", "bevy/bevy_text", "bevy/bevy_render"] bevy_ui = ["bevy/bevy_ui", "bevy/bevy_render"]
# Enable built-in lenses for Bevy Text
bevy_text = ["bevy/bevy_text", "bevy/bevy_render"]
[dependencies] [dependencies]
interpolation = "0.2" interpolation = "0.2"
...@@ -54,7 +56,7 @@ required-features = [ "bevy_ui", "bevy/bevy_winit" ] ...@@ -54,7 +56,7 @@ required-features = [ "bevy_ui", "bevy/bevy_winit" ]
[[example]] [[example]]
name = "text_color" name = "text_color"
required-features = [ "bevy_ui", "bevy/bevy_winit" ] required-features = [ "bevy_text", "bevy/bevy_winit" ]
[[example]] [[example]]
name = "sequence" name = "sequence"
......
...@@ -34,6 +34,7 @@ This crate supports the following features: ...@@ -34,6 +34,7 @@ This crate supports the following features:
| `bevy_asset` | Yes | Enable animating Bevy assets (`Asset`) in addition of components. | | `bevy_asset` | Yes | Enable animating Bevy assets (`Asset`) in addition of components. |
| `bevy_sprite` | Yes | Includes built-in lenses for some `Sprite`-related components. | | `bevy_sprite` | Yes | Includes built-in lenses for some `Sprite`-related components. |
| `bevy_ui` | Yes | Includes built-in lenses for some UI-related components. | | `bevy_ui` | Yes | Includes built-in lenses for some UI-related components. |
| `bevy_text` | Yes | Includes built-in lenses for some `Text`-related components. |
### System setup ### System setup
...@@ -121,7 +122,7 @@ The naming scheme for predefined lenses is `"<TargetName><FieldName>Lens"`, wher ...@@ -121,7 +122,7 @@ The naming scheme for predefined lenses is `"<TargetName><FieldName>Lens"`, wher
| | [`scale`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.scale) | [`TransformScaleLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformScaleLens.html) | | | | [`scale`](https://docs.rs/bevy/0.8.0/bevy/transform/components/struct.Transform.html#structfield.scale) | [`TransformScaleLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TransformScaleLens.html) | |
| [`Sprite`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.Sprite.html) | [`color`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.Sprite.html#structfield.color) | [`SpriteColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.SpriteColorLens.html) | `bevy_sprite` | | [`Sprite`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.Sprite.html) | [`color`](https://docs.rs/bevy/0.8.0/bevy/sprite/struct.Sprite.html#structfield.color) | [`SpriteColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.SpriteColorLens.html) | `bevy_sprite` |
| [`Style`](https://docs.rs/bevy/0.8.0/bevy/ui/struct.Style.html) | [`position`](https://docs.rs/bevy/0.8.0/bevy/ui/struct.Style.html#structfield.position) | [`UiPositionLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.UiPositionLens.html) | `bevy_ui` | | [`Style`](https://docs.rs/bevy/0.8.0/bevy/ui/struct.Style.html) | [`position`](https://docs.rs/bevy/0.8.0/bevy/ui/struct.Style.html#structfield.position) | [`UiPositionLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.UiPositionLens.html) | `bevy_ui` |
| [`Text`](https://docs.rs/bevy/0.8.0/bevy/text/struct.Text.html) | [`TextStyle::color`](https://docs.rs/bevy/0.8.0/bevy/text/struct.TextStyle.html#structfield.color) | [`TextColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TextColorLens.html) | `bevy_ui` | | [`Text`](https://docs.rs/bevy/0.8.0/bevy/text/struct.Text.html) | [`TextStyle::color`](https://docs.rs/bevy/0.8.0/bevy/text/struct.TextStyle.html#structfield.color) | [`TextColorLens`](https://docs.rs/bevy_tweening/latest/bevy_tweening/struct.TextColorLens.html) | `bevy_text` |
¹ Shortest-path interpolation between two rotations, using `Quat::slerp()`. ¹ Shortest-path interpolation between two rotations, using `Quat::slerp()`.
......
...@@ -79,7 +79,7 @@ pub trait Lens<T> { ...@@ -79,7 +79,7 @@ pub trait Lens<T> {
/// ///
/// [`color`]: https://docs.rs/bevy/0.8.0/bevy/text/struct.TextStyle.html#structfield.color /// [`color`]: https://docs.rs/bevy/0.8.0/bevy/text/struct.TextStyle.html#structfield.color
/// [`Text`]: https://docs.rs/bevy/0.8.0/bevy/text/struct.Text.html /// [`Text`]: https://docs.rs/bevy/0.8.0/bevy/text/struct.Text.html
#[cfg(feature = "bevy_ui")] #[cfg(feature = "bevy_text")]
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
pub struct TextColorLens { pub struct TextColorLens {
/// Start color. /// Start color.
...@@ -90,7 +90,7 @@ pub struct TextColorLens { ...@@ -90,7 +90,7 @@ pub struct TextColorLens {
pub section: usize, pub section: usize,
} }
#[cfg(feature = "bevy_ui")] #[cfg(feature = "bevy_text")]
impl Lens<Text> for TextColorLens { impl Lens<Text> for TextColorLens {
fn lerp(&mut self, target: &mut Text, ratio: f32) { fn lerp(&mut self, target: &mut Text, ratio: f32) {
// Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for // Note: Add<f32> for Color affects alpha, but not Mul<f32>. So use Vec4 for
...@@ -377,7 +377,7 @@ mod tests { ...@@ -377,7 +377,7 @@ mod tests {
use super::*; use super::*;
#[cfg(feature = "bevy_ui")] #[cfg(feature = "bevy_text")]
#[test] #[test]
fn text_color() { fn text_color() {
let mut lens = TextColorLens { let mut lens = TextColorLens {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment