From 8f1c95ad0e65a3d02f19b1617f0e8a2fbc16b800 Mon Sep 17 00:00:00 2001 From: Jerome Humbert Date: Fri, 17 Oct 2025 21:49:58 +0100 Subject: [PATCH] Fix examples Fix all examples after the Bevy v0.17 upgrade. --- Cargo.toml | 12 +++++++---- examples/ambient_light.rs | 6 +++--- examples/colormaterial_color.rs | 2 +- examples/follow.rs | 6 +++--- examples/menu.rs | 34 +++++++++++++++---------------- examples/sequence.rs | 6 +++--- examples/sprite_color.rs | 2 +- examples/text_color.rs | 10 ++++----- examples/transform_rotation.rs | 6 ++---- examples/transform_translation.rs | 6 ++---- examples/ui_position.rs | 6 ++---- examples/utils/mod.rs | 2 +- run_examples.bat | 16 +++++++-------- run_examples.sh | 16 +++++++-------- src/lens.rs | 20 ++++++++++++++++++ 15 files changed, 83 insertions(+), 67 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8651a92..31e7f83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ required-features = [ "bevy/bevy_pbr", "bevy/hdr", "bevy/tonemapping_luts", + "bevy/bevy_post_process", ] [[example]] @@ -68,23 +69,24 @@ required-features = [ "bevy_text", "bevy/bevy_winit", "bevy/bevy_picking", + "bevy/bevy_ui_render", ] [[example]] name = "colormaterial_color" -required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking"] +required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking", "bevy/bevy_text"] [[example]] name = "sprite_color" -required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking"] +required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking", "bevy/bevy_text"] [[example]] name = "transform_translation" -required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking"] +required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking", "bevy/bevy_text"] [[example]] name = "transform_rotation" -required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking"] +required-features = ["bevy_sprite", "bevy/bevy_winit", "bevy/bevy_picking", "bevy/bevy_text"] [[example]] name = "ui_position" @@ -93,6 +95,7 @@ required-features = [ "bevy_ui", "bevy/bevy_winit", "bevy/bevy_picking", + "bevy/bevy_ui_render", ] [[example]] @@ -102,6 +105,7 @@ required-features = [ "bevy_text", "bevy/bevy_winit", "bevy/bevy_picking", + "bevy/bevy_ui_render", ] [[example]] diff --git a/examples/ambient_light.rs b/examples/ambient_light.rs index 2a3df7b..4d094f6 100644 --- a/examples/ambient_light.rs +++ b/examples/ambient_light.rs @@ -11,7 +11,7 @@ use std::{ time::Duration, }; -use bevy::{color::palettes::css::*, core_pipeline::bloom::Bloom, prelude::*}; +use bevy::{color::palettes::css::*, post_process::bloom::Bloom, prelude::*, render::view::Hdr}; use bevy_tweening::{lens::*, *}; mod utils; @@ -34,7 +34,7 @@ fn main() { .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "AmbientLightLens".to_string(), - resolution: (1200., 600.).into(), + resolution: bevy::window::WindowResolution::new(1200, 600), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), @@ -56,10 +56,10 @@ fn setup( // brightness. commands.spawn(( Camera { - hdr: true, clear_color: Color::BLACK.into(), ..default() }, + Hdr, Bloom { intensity: 0.2, ..default() diff --git a/examples/colormaterial_color.rs b/examples/colormaterial_color.rs index d4f2f62..096387b 100644 --- a/examples/colormaterial_color.rs +++ b/examples/colormaterial_color.rs @@ -10,7 +10,7 @@ fn main() { .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "ColorMaterialColorLens".to_string(), - resolution: (1200., 600.).into(), + resolution: bevy::window::WindowResolution::new(1200, 600), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), diff --git a/examples/follow.rs b/examples/follow.rs index fbcc2d6..5417c12 100644 --- a/examples/follow.rs +++ b/examples/follow.rs @@ -43,7 +43,7 @@ fn main() { .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "Follow".to_string(), - resolution: (1200., 600.).into(), + resolution: bevy::window::WindowResolution::new(1200, 600), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), @@ -112,12 +112,12 @@ fn change_option(keyboard: Res>, mut q_anim: Single<&mut An fn follow( mut commands: Commands, - mut ev: EventReader, + mut message_reader: MessageReader, q_follower: Single<&Transform, With>, q_camera: Single<(&GlobalTransform, &Camera)>, mut q_anim: Single<(Entity, &Anim, &mut TweenAnim)>, ) { - let Some(ev) = ev.read().last() else { + let Some(ev) = message_reader.read().last() else { return; }; let (camera_transform, camera) = *q_camera; diff --git a/examples/menu.rs b/examples/menu.rs index c32e5d4..f90a8f5 100644 --- a/examples/menu.rs +++ b/examples/menu.rs @@ -36,15 +36,13 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "Menu".to_string(), - resolution: (800., 400.).into(), + resolution: bevy::window::WindowResolution::new(800, 400), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), ..default() }), - EguiPlugin { - enable_multipass_for_primary_context: true, - }, + EguiPlugin::default(), WorldInspectorPlugin::new(), TweeningPlugin, )) @@ -55,7 +53,7 @@ fn main() { } fn setup(mut commands: Commands, asset_server: Res) { - commands.spawn(Camera2d::default()); + commands.spawn(Camera2d); let font = asset_server.load("fonts/FiraMono-Regular.ttf"); @@ -91,9 +89,9 @@ fn setup(mut commands: Commands, asset_server: Res) { let tween_scale = Tween::new( EaseFunction::BounceOut, Duration::from_secs(2), - TransformScaleLens { - start: Vec3::splat(0.01), - end: Vec3::ONE, + UiTransformScaleLens { + start: Vec2::splat(0.01), + end: Vec2::ONE, }, ) .with_cycle_completed_event(true); @@ -114,7 +112,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, BackgroundColor(NORMAL_COLOR), - Transform::from_scale(Vec3::splat(0.01)), + UiTransform::from_scale(Vec2::splat(0.01)), label, children![( Text::new(text.to_string()), @@ -124,7 +122,7 @@ fn setup(mut commands: Commands, asset_server: Res) { ..default() }, TextColor(TEXT_COLOR), - TextLayout::new_with_justify(JustifyText::Center), + TextLayout::new_with_justify(Justify::Center), )], )) .id(); @@ -139,7 +137,7 @@ fn setup(mut commands: Commands, asset_server: Res) { .spawn(( InitialAnimMarker, TweenAnim::new(tweenable), - AnimTarget::component::(target), + AnimTarget::component::(target), )) .observe(enable_interaction_after_initial_animation); @@ -149,7 +147,7 @@ fn setup(mut commands: Commands, asset_server: Res) { } fn enable_interaction_after_initial_animation( - trigger: Trigger, + trigger: On, mut commands: Commands, q_names: Query<&Name>, ) { @@ -170,7 +168,7 @@ fn enable_interaction_after_initial_animation( // Spawn an Entity to hold the animation itself. We add the AnimTarget, which // doesn't change, but not yet any TweenAnim since we have no animation to play. let anim_entity = commands - .spawn(AnimTarget::component::(*target_entity)) + .spawn(AnimTarget::component::(*target_entity)) .id(); // Add the HoverAnim component which also acts as a marker @@ -195,7 +193,7 @@ fn interaction( mut commands: Commands, mut interaction_query: Query< ( - &Transform, + &UiTransform, &Interaction, &mut BackgroundColor, &ButtonLabel, @@ -231,9 +229,9 @@ fn interaction( let tween = Tween::new( EaseFunction::QuadraticIn, Duration::from_millis(200), - TransformScaleLens { + UiTransformScaleLens { start: transform.scale, - end: Vec3::splat(1.1), + end: Vec2::splat(1.1), }, ); @@ -247,9 +245,9 @@ fn interaction( let tween = Tween::new( EaseFunction::QuadraticIn, Duration::from_millis(200), - TransformScaleLens { + UiTransformScaleLens { start: transform.scale, - end: Vec3::ONE, + end: Vec2::ONE, }, ); diff --git a/examples/sequence.rs b/examples/sequence.rs index 1472567..813ece2 100644 --- a/examples/sequence.rs +++ b/examples/sequence.rs @@ -10,7 +10,7 @@ fn main() { .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "Sequence".to_string(), - resolution: (600., 600.).into(), + resolution: bevy::window::WindowResolution::new(600, 600), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), @@ -51,7 +51,7 @@ fn setup(mut commands: Commands, asset_server: Res) -> Result<()> { let text_color_red = TextColor(RED.into()); let text_color_blue = TextColor(AQUA.into()); - let justify = JustifyText::Center; + let justify = Justify::Center; // Text with the index of the active tween in the sequence commands @@ -233,7 +233,7 @@ fn update_text( mut q_textspans: Query<&mut TextSpan, With>, q_anim_red: Single, With>, q_anim_blue: Single, With>, - mut q_event_completed: EventReader, + mut q_event_completed: MessageReader, ) { let anim_red = *q_anim_red; let progress_red = if let Some(anim) = anim_red { diff --git a/examples/sprite_color.rs b/examples/sprite_color.rs index 31b682f..c17e49f 100644 --- a/examples/sprite_color.rs +++ b/examples/sprite_color.rs @@ -8,7 +8,7 @@ fn main() { .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "SpriteColorLens".to_string(), - resolution: (1200., 600.).into(), + resolution: bevy::window::WindowResolution::new(1200, 600), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), diff --git a/examples/text_color.rs b/examples/text_color.rs index c99f61a..bb44899 100644 --- a/examples/text_color.rs +++ b/examples/text_color.rs @@ -3,15 +3,15 @@ use bevy_tweening::{lens::*, *}; mod utils; -const WIDTH: f32 = 1200.; -const HEIGHT: f32 = 600.; +const WIDTH: u32 = 1200; +const HEIGHT: u32 = 600; fn main() { App::default() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "TextColorLens".to_string(), - resolution: (WIDTH, HEIGHT).into(), + resolution: bevy::window::WindowResolution::new(WIDTH, HEIGHT), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), @@ -31,8 +31,8 @@ fn setup(mut commands: Commands, asset_server: Res) { let size_x = 140.; let size_y = 40.; - let delta_x = WIDTH / 5.; - let delta_y = HEIGHT / 6.; + let delta_x = WIDTH as f32 / 5.; + let delta_y = HEIGHT as f32 / 6.; let mut x = 20.; let mut y = 20.; diff --git a/examples/transform_rotation.rs b/examples/transform_rotation.rs index 2937320..0349945 100644 --- a/examples/transform_rotation.rs +++ b/examples/transform_rotation.rs @@ -10,15 +10,13 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "TransformRotationLens".to_string(), - resolution: (1400., 600.).into(), + resolution: bevy::window::WindowResolution::new(1400, 600).into(), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), ..default() }), - EguiPlugin { - enable_multipass_for_primary_context: true, - }, + EguiPlugin::default(), ResourceInspectorPlugin::::new(), TweeningPlugin, )) diff --git a/examples/transform_translation.rs b/examples/transform_translation.rs index f06245e..297fcc0 100644 --- a/examples/transform_translation.rs +++ b/examples/transform_translation.rs @@ -10,15 +10,13 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "TransformPositionLens".to_string(), - resolution: (1400., 600.).into(), + resolution: bevy::window::WindowResolution::new(1400, 600).into(), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), ..default() }), - EguiPlugin { - enable_multipass_for_primary_context: true, - }, + EguiPlugin::default(), //DefaultInspectorConfigPlugin, ResourceInspectorPlugin::::new(), TweeningPlugin, diff --git a/examples/ui_position.rs b/examples/ui_position.rs index 3a844b2..f7b4013 100644 --- a/examples/ui_position.rs +++ b/examples/ui_position.rs @@ -10,15 +10,13 @@ fn main() { DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "UiPositionLens".to_string(), - resolution: (1400., 600.).into(), + resolution: bevy::window::WindowResolution::new(1400, 600).into(), present_mode: bevy::window::PresentMode::Fifo, // vsync ..default() }), ..default() }), - EguiPlugin { - enable_multipass_for_primary_context: true, - }, + EguiPlugin::default(), ResourceInspectorPlugin::::new(), TweeningPlugin, )) diff --git a/examples/utils/mod.rs b/examples/utils/mod.rs index 296c772..654a672 100644 --- a/examples/utils/mod.rs +++ b/examples/utils/mod.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; -pub fn close_on_esc(mut ev_app_exit: EventWriter, input: Res>) { +pub fn close_on_esc(mut ev_app_exit: MessageWriter, input: Res>) { if input.just_pressed(KeyCode::Escape) { ev_app_exit.write(AppExit::Success); } diff --git a/run_examples.bat b/run_examples.bat index cefc6fa..6696e0b 100644 --- a/run_examples.bat +++ b/run_examples.bat @@ -1,16 +1,16 @@ @echo on echo Run all examples REM Default -cargo r --example menu --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking" -cargo r --example transform_translation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" -cargo r --example transform_rotation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" +cargo r --example menu --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking bevy/bevy_ui_render" +cargo r --example transform_translation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" +cargo r --example transform_rotation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" cargo r --example sequence --no-default-features --features="bevy_sprite bevy_text bevy/bevy_winit bevy/bevy_picking" -cargo r --example ambient_light --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking bevy/bevy_pbr bevy/hdr bevy/tonemapping_luts" +cargo r --example ambient_light --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking bevy/bevy_pbr bevy/hdr bevy/tonemapping_luts bevy/bevy_post_process" cargo r --example follow --no-default-features --features="bevy_sprite bevy_text bevy/bevy_winit bevy/bevy_picking" REM bevy_sprite -cargo r --example sprite_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" -cargo r --example colormaterial_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" +cargo r --example sprite_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" +cargo r --example colormaterial_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" REM bevy_ui -cargo r --example ui_position --no-default-features --features="bevy_sprite bevy_ui bevy/bevy_winit bevy/bevy_picking" +cargo r --example ui_position --no-default-features --features="bevy_sprite bevy_ui bevy/bevy_winit bevy/bevy_picking bevy/bevy_ui_render" REM bevy_text -cargo r --example text_color --no-default-features --features="bevy_text bevy_ui bevy/bevy_winit bevy/bevy_picking" +cargo r --example text_color --no-default-features --features="bevy_text bevy_ui bevy/bevy_winit bevy/bevy_picking bevy/bevy_ui_render" diff --git a/run_examples.sh b/run_examples.sh index 86d7dc4..aa7addb 100755 --- a/run_examples.sh +++ b/run_examples.sh @@ -1,15 +1,15 @@ echo Run all examples # Default -cargo r --example menu --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking" -cargo r --example transform_translation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" -cargo r --example transform_rotation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" +cargo r --example menu --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking bevy/bevy_ui_render" +cargo r --example transform_translation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" +cargo r --example transform_rotation --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" cargo r --example sequence --no-default-features --features="bevy_sprite bevy_text bevy/bevy_winit bevy/bevy_picking" -cargo r --example ambient_light --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking bevy/bevy_pbr bevy/hdr bevy/tonemapping_luts" +cargo r --example ambient_light --no-default-features --features="bevy_ui bevy_text bevy/bevy_winit bevy/bevy_picking bevy/bevy_pbr bevy/hdr bevy/tonemapping_luts bevy/bevy_post_process" cargo r --example follow --no-default-features --features="bevy_sprite bevy_text bevy/bevy_winit bevy/bevy_picking" # bevy_sprite -cargo r --example sprite_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" -cargo r --example colormaterial_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking" +cargo r --example sprite_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" +cargo r --example colormaterial_color --no-default-features --features="bevy_sprite bevy/bevy_winit bevy/bevy_picking bevy/bevy_text" # bevy_ui -cargo r --example ui_position --no-default-features --features="bevy_sprite bevy_ui bevy/bevy_winit bevy/bevy_picking" +cargo r --example ui_position --no-default-features --features="bevy_sprite bevy_ui bevy/bevy_winit bevy/bevy_picking bevy/bevy_ui_render" # bevy_text -cargo r --example text_color --no-default-features --features="bevy_text bevy_ui bevy/bevy_winit bevy/bevy_picking" +cargo r --example text_color --no-default-features --features="bevy_text bevy_ui bevy/bevy_winit bevy/bevy_picking bevy/bevy_ui_render" diff --git a/src/lens.rs b/src/lens.rs index 3a52f49..e121793 100644 --- a/src/lens.rs +++ b/src/lens.rs @@ -412,6 +412,26 @@ impl Lens for UiPositionLens { } } +/// A lens to manipulate the [`scale`] field of a [`UiTransform`] component. +/// +/// [`scale`]: https://docs.rs/bevy/0.17/bevy/ui/ui_transform/struct.UiTransform.html#structfield.scale +/// [`UiTransform`]: https://docs.rs/bevy/0.17/bevy/ui/ui_transform/struct.UiTransform.html +#[cfg(feature = "bevy_ui")] +#[derive(Debug, Copy, Clone, PartialEq)] +pub struct UiTransformScaleLens { + /// Start value of the scale. + pub start: Vec2, + /// End value of the scale. + pub end: Vec2, +} + +#[cfg(feature = "bevy_ui")] +impl Lens for UiTransformScaleLens { + fn lerp(&mut self, mut target: Mut, ratio: f32) { + target.scale = self.start.lerp(self.end, ratio); + } +} + /// Gamer #[cfg(feature = "bevy_ui")] #[derive(Debug, Copy, Clone, PartialEq)]