diff --git a/examples/tools/gamepad_viewer.rs b/examples/tools/gamepad_viewer.rs index a191f81f07..f5bef89524 100644 --- a/examples/tools/gamepad_viewer.rs +++ b/examples/tools/gamepad_viewer.rs @@ -88,6 +88,37 @@ impl FromWorld for FontHandle { } } +#[derive(Bundle)] +struct GamepadButtonBundle { + mesh_bundle: MaterialMesh2dBundle, + react_to: ReactTo, +} + +impl GamepadButtonBundle { + pub fn new( + button_type: GamepadButtonType, + mesh: Mesh2dHandle, + material: Handle, + x: f32, + y: f32, + ) -> Self { + Self { + mesh_bundle: MaterialMesh2dBundle { + mesh, + material, + transform: Transform::from_xyz(x, y, 0.), + ..default() + }, + react_to: ReactTo(button_type), + } + } + + pub fn with_rotation(mut self, angle: f32) -> Self { + self.mesh_bundle.transform.rotation = Quat::from_rotation_z(angle); + self + } +} + fn main() { App::new() .add_plugins(DefaultPlugins) @@ -116,65 +147,52 @@ fn setup(mut commands: Commands, meshes: Res, materials: Res, materials: Res